1
0
mirror of synced 2024-11-29 00:25:39 +03:00

POST /api/transport/v1/messages/read_until support

This commit is contained in:
Pavel 2022-11-02 17:22:11 +03:00 committed by GitHub
commit 04ec837f3a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 193 additions and 121 deletions

View File

@ -80,6 +80,7 @@ func (c *MgClient) TransportTemplates() ([]Template, int, error) {
// ActivateTemplate implements template activation // ActivateTemplate implements template activation
// //
// Example: // Example:
//
// var client = v1.New("https://token.url", "cb8ccf05e38a47543ad8477d4999be73bff503ea6") // var client = v1.New("https://token.url", "cb8ccf05e38a47543ad8477d4999be73bff503ea6")
// //
// request := v1.ActivateTemplateRequest{ // request := v1.ActivateTemplateRequest{
@ -124,6 +125,7 @@ func (c *MgClient) ActivateTemplate(channelID uint64, request ActivateTemplateRe
// UpdateTemplate implements template updating // UpdateTemplate implements template updating
// Example: // Example:
//
// var client = New("https://token.url", "cb8ccf05e38a47543ad8477d4999be73bff503ea6") // var client = New("https://token.url", "cb8ccf05e38a47543ad8477d4999be73bff503ea6")
// //
// request := v1.Template{ // request := v1.Template{
@ -547,6 +549,42 @@ func (c *MgClient) AckMessage(request AckMessageRequest) (int, error) {
return status, err return status, err
} }
// ReadUntil will mark all messages from specified timestamp as read.
//
// Example:
//
// var client = v1.New("https://token.url", "cb8ccf05e38a47543ad8477d4999be73bff503ea6")
//
// request := ReadUntilRequest{
// ExternalMessageID: "274628",
// Channel: 10,
// }
//
// resp, status, err := client.ReadUntil(request)
// if err != nil {
// fmt.Printf("%v", err)
// }
// if resp != nil {
// fmt.Printf("Marked these as read: %s", resp.IDs)
// }
func (c *MgClient) ReadUntil(request MarkMessagesReadUntilRequest) (*MarkMessagesReadUntilResponse, int, error) {
outgoing, _ := json.Marshal(&request)
data, status, err := c.PostRequest("/messages/read_until", bytes.NewBuffer(outgoing))
if err != nil {
return nil, status, err
}
if status != http.StatusOK {
return nil, status, NewAPIClientError(data)
}
var resp *MarkMessagesReadUntilResponse
if e := json.Unmarshal(data, &resp); e != nil {
return nil, status, e
}
return resp, status, nil
}
// DeleteMessage implement delete message // DeleteMessage implement delete message
// //
// Example: // Example:

View File

@ -614,6 +614,28 @@ func (t *MGClientTest) Test_UpdateMessages() {
t.Assert().Equal(1, dataU.MessageID) t.Assert().Equal(1, dataU.MessageID)
} }
func (t *MGClientTest) Test_ReadUntil() {
c := t.client()
req := MarkMessagesReadUntilRequest{
CustomerExternalID: "customer",
ChannelID: 1,
Until: time.Unix(0, 0),
}
defer gock.Off()
t.gock().
Post("messages/read_until").
Reply(http.StatusOK).
JSON(MarkMessagesReadUntilResponse{
IDs: []int64{1},
})
resp, st, err := c.ReadUntil(req)
t.Require().NoError(err)
t.Assert().Equal(http.StatusOK, st)
t.Assert().Equal([]int64{1}, resp.IDs)
}
func (t *MGClientTest) Test_MarkMessageReadAndDelete() { func (t *MGClientTest) Test_MarkMessageReadAndDelete() {
c := t.client() c := t.client()

View File

@ -330,6 +330,18 @@ type AckMessageRequest struct {
Error *MessageSentError `json:"error,omitempty"` Error *MessageSentError `json:"error,omitempty"`
} }
// MarkMessagesReadUntilRequest type.
type MarkMessagesReadUntilRequest struct {
CustomerExternalID string `json:"customer_external_id"`
ChannelID uint64 `json:"channel_id"`
Until time.Time `json:"until"`
}
// MarkMessagesReadUntilResponse type.
type MarkMessagesReadUntilResponse struct {
IDs []int64 `json:"ids"`
}
// DeleteData struct. // DeleteData struct.
type DeleteData struct { type DeleteData struct {
Message Message `json:"message"` Message Message `json:"message"`