Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactor response field to external ID #87

Merged
merged 1 commit into from
Dec 17, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 1 addition & 34 deletions handlers/instagram/instagram.go
Original file line number Diff line number Diff line change
Expand Up @@ -71,23 +71,6 @@ type igUser struct {
ID string `json:"id"`
}

// {
// "object":"instagram",
// "entry":[{
// "id":"180005062406476",
// "time":1514924367082,
// "messaging":[{
// "sender": {"id":"1630934236957797"},
// "recipient":{"id":"180005062406476"},
// "timestamp":1514924366807,
// "message":{
// "mid":"mid.$cAAD5QiNHkz1m6cyj11guxokwkhi2",
// "text":"65863634"
// }
// }]
// }]
// }

type moPayload struct {
Object string `json:"object"`
Entry []struct {
Expand Down Expand Up @@ -298,22 +281,6 @@ func (h *handler) receiveEvent(ctx context.Context, channel courier.Channel, w h
return events, courier.WriteDataResponse(ctx, w, http.StatusOK, "Events Handled", data)
}

// {
// "messaging_type": "<MESSAGING_TYPE>"
// "recipient":{
// "id":"<PSID>"
// },
// "message":{
// "text":"hello, world!"
// "attachment":{
// "type":"image",
// "payload":{
// "url":"http://www.messenger-rocks.com/image.jpg",
// "is_reusable":true
// }
// }
// }
// }
type mtPayload struct {
MessagingType string `json:"messaging_type"`
Tag string `json:"tag,omitempty"`
Expand Down Expand Up @@ -351,7 +318,7 @@ func (h *handler) SendMsg(ctx context.Context, msg courier.Msg) (courier.MsgStat
payload := mtPayload{}

// set our message type
if msg.ResponseToID() != courier.NilMsgID {
if msg.ResponseToExternalID() != "" {
payload.MessagingType = "RESPONSE"
} else if topic != "" {
payload.MessagingType = "MESSAGE_TAG"
Expand Down
2 changes: 1 addition & 1 deletion handlers/instagram/instagram_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -369,7 +369,7 @@ var defaultSendTestCases = []ChannelSendTestCase{

{Label: "Plain Response",
Text: "Simple Message", URN: "instagram:12345",
Status: "W", ExternalID: "mid.133", ResponseToID: 23526,
Status: "W", ExternalID: "mid.133", ResponseToExternalID: "23526",
ResponseBody: `{"message_id": "mid.133"}`, ResponseStatus: 200,
RequestBody: `{"messaging_type":"RESPONSE","recipient":{"id":"12345"},"message":{"text":"Simple Message"}}`,
SendPrep: setSendURL},
Expand Down