Skip to content

Commit

Permalink
Merge pull request #402 from alviriseup/main
Browse files Browse the repository at this point in the history
Added Session Status to FCM handler
  • Loading branch information
rowanseymour authored Jan 18, 2022
2 parents 966c851 + 93f74a0 commit 0fda71b
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 10 deletions.
12 changes: 7 additions & 5 deletions handlers/firebase/firebase.go
Original file line number Diff line number Diff line change
Expand Up @@ -117,11 +117,12 @@ func (h *handler) registerContact(ctx context.Context, channel courier.Channel,

type mtPayload struct {
Data struct {
Type string `json:"type"`
Title string `json:"title"`
Message string `json:"message"`
MessageID int64 `json:"message_id"`
QuickReplies []string `json:"quick_replies,omitempty"`
Type string `json:"type"`
Title string `json:"title"`
Message string `json:"message"`
MessageID int64 `json:"message_id"`
SessionStatus string `json:"session_status"`
QuickReplies []string `json:"quick_replies,omitempty"`
} `json:"data"`
Notification *mtNotification `json:"notification,omitempty"`
ContentAvailable bool `json:"content_available"`
Expand Down Expand Up @@ -162,6 +163,7 @@ func (h *handler) SendMsg(ctx context.Context, msg courier.Msg) (courier.MsgStat
payload.Data.Title = title
payload.Data.Message = part
payload.Data.MessageID = int64(msg.ID())
payload.Data.SessionStatus = msg.SessionStatus()

// include any quick replies on the last piece we send
if i == len(msgParts)-1 {
Expand Down
10 changes: 5 additions & 5 deletions handlers/firebase/firebase_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ var notificationSendTestCases = []ChannelSendTestCase{
Status: "W", ExternalID: "123456",
ResponseBody: `{"success":1, "multicast_id": 123456}`, ResponseStatus: 200,
Headers: map[string]string{"Authorization": "key=FCMKey"},
RequestBody: `{"data":{"type":"rapidpro","title":"FCMTitle","message":"Simple Message","message_id":10},"notification":{"title":"FCMTitle","body":"Simple Message"},"content_available":true,"to":"auth1","priority":"high"}`,
RequestBody: `{"data":{"type":"rapidpro","title":"FCMTitle","message":"Simple Message","message_id":10,"session_status":""},"notification":{"title":"FCMTitle","body":"Simple Message"},"content_available":true,"to":"auth1","priority":"high"}`,
SendPrep: setSendURL},
}

Expand All @@ -87,22 +87,22 @@ var sendTestCases = []ChannelSendTestCase{
Status: "W", ExternalID: "123456",
ResponseBody: `{"success":1, "multicast_id": 123456}`, ResponseStatus: 200,
Headers: map[string]string{"Authorization": "key=FCMKey"},
RequestBody: `{"data":{"type":"rapidpro","title":"FCMTitle","message":"Simple Message","message_id":10},"content_available":false,"to":"auth1","priority":"high"}`,
RequestBody: `{"data":{"type":"rapidpro","title":"FCMTitle","message":"Simple Message","message_id":10,"session_status":""},"content_available":false,"to":"auth1","priority":"high"}`,
SendPrep: setSendURL},
{Label: "Long Message",
Text: longMsg,
URN: "fcm:250788123123", URNAuth: "auth1",
URN: "fcm:250788123123", URNAuth: "auth1",
Status: "W", ExternalID: "123456",
ResponseBody: `{"success":1, "multicast_id": 123456}`, ResponseStatus: 200,
Headers: map[string]string{"Authorization": "key=FCMKey"},
RequestBody: `{"data":{"type":"rapidpro","title":"FCMTitle","message":"ate ac.","message_id":10},"content_available":false,"to":"auth1","priority":"high"}`,
RequestBody: `{"data":{"type":"rapidpro","title":"FCMTitle","message":"ate ac.","message_id":10,"session_status":""},"content_available":false,"to":"auth1","priority":"high"}`,
SendPrep: setSendURL},
{Label: "Quick Reply",
Text: "Simple Message", URN: "fcm:250788123123", URNAuth: "auth1", QuickReplies: []string{"yes", "no"}, Attachments: []string{"image/jpeg:https://foo.bar"},
Status: "W", ExternalID: "123456",
ResponseBody: `{"success":1, "multicast_id": 123456}`, ResponseStatus: 200,
Headers: map[string]string{"Authorization": "key=FCMKey"},
RequestBody: `{"data":{"type":"rapidpro","title":"FCMTitle","message":"Simple Message\nhttps://foo.bar","message_id":10,"quick_replies":["yes","no"]},"content_available":false,"to":"auth1","priority":"high"}`,
RequestBody: `{"data":{"type":"rapidpro","title":"FCMTitle","message":"Simple Message\nhttps://foo.bar","message_id":10,"session_status":"","quick_replies":["yes","no"]},"content_available":false,"to":"auth1","priority":"high"}`,
SendPrep: setSendURL},
{Label: "Error",
Text: "Error", URN: "fcm:250788123123", URNAuth: "auth1",
Expand Down

0 comments on commit 0fda71b

Please sign in to comment.