1
0
mirror of synced 2024-11-22 04:56:06 +03:00

Async status passthrough

This commit is contained in:
kovtun-retailcrm 2020-12-23 10:54:46 +02:00 committed by GitHub
parent cfb601a9b9
commit 14af54f7a1
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 61 additions and 0 deletions

View File

@ -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:

View File

@ -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"`