diff --git a/v1/client.go b/v1/client.go index a40e831..5d8b945 100644 --- a/v1/client.go +++ b/v1/client.go @@ -499,6 +499,37 @@ func (c *MgClient) MarkMessageRead(request MarkMessageReadRequest) (MarkMessageR return resp, status, err } +// AckMessage implements ack of message +// +// Example: +// +// var client = v1.New("https://token.url", "cb8ccf05e38a47543ad8477d4999be73bff503ea6") +// +// request := AckMessageRequest{ +// ExternalMessageID: "274628", +// Channel: 10, +// } +// +// status, err := client.AckMessage(request) +// +// if err != nil { +// fmt.Printf("%v", err) +// } +func (c *MgClient) AckMessage(request AckMessageRequest) (int, error) { + outgoing, _ := json.Marshal(&request) + + data, status, err := c.PostRequest("/messages/ack", bytes.NewBuffer(outgoing)) + if err != nil { + return status, err + } + + if status != http.StatusOK { + return status, c.Error(data) + } + + return status, err +} + // DeleteMessage implement delete message // // Example: diff --git a/v1/types.go b/v1/types.go index b0e9b6a..1c227fc 100644 --- a/v1/types.go +++ b/v1/types.go @@ -65,6 +65,15 @@ const ( OriginatorChannel ) +type ErrorType string +const ( + GeneralError ErrorType = "general" + CustomerNotExistsError = "customer_not_exists" + ReplyTimedOutError = "reply_timed_out" + SpamSuspicionError = "spam_suspicion" + AccessRestrictedError = "access_restricted" +) + // MgClient type type MgClient struct { URL string `json:"url"` @@ -303,6 +312,13 @@ type MarkMessageReadRequestMessage struct { ExternalID string `json:"external_id"` } +// AckMessageRequest type +type AckMessageRequest struct { + ExternalMessageID string `json:"external_message_id"` + Channel uint64 `json:"channel"` + Error *MessageSentError `json:"error,omitempty"` +} + // DeleteData struct type DeleteData struct { Message Message `json:"message"` @@ -322,6 +338,20 @@ type WebhookRequest struct { Data WebhookData `json:"data"` } +// WebhookMessageSentResponse type +// Consider using this structure while processing webhook request +type WebhookMessageSentResponse struct { + ExternalMessageID string `json:"external_message_id"` + Error *MessageSentError `json:"error,omitempty"` + Async bool `json:"async"` +} + +// MessageSentError type +type MessageSentError struct { + Code ErrorType `json:"code"` + Message string `json:"message"` +} + // WebhookData request data type WebhookData struct { ExternalUserID string `json:"external_user_id"`