POST /api/transport/v1/messages/read_until
support
This commit is contained in:
parent
d40fe94ec5
commit
437e3447a6
38
v1/client.go
38
v1/client.go
@ -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:
|
||||||
|
@ -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()
|
||||||
|
|
||||||
|
12
v1/types.go
12
v1/types.go
@ -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"`
|
||||||
|
Loading…
Reference in New Issue
Block a user