Skip to content

Commit

Permalink
Add attachment support for chip
Browse files Browse the repository at this point in the history
  • Loading branch information
rowanseymour committed May 29, 2024
1 parent e2060e7 commit 2b4156f
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 13 deletions.
18 changes: 10 additions & 8 deletions handlers/chip/handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -110,10 +110,11 @@ func (h *handler) receive(ctx context.Context, c courier.Channel, w http.Respons
}

type sendMsg struct {
ID courier.MsgID `json:"id"`
Text string `json:"text"`
Origin courier.MsgOrigin `json:"origin"`
UserID courier.UserID `json:"user_id,omitempty"`
ID courier.MsgID `json:"id"`
Text string `json:"text"`
Attachments []string `json:"attachments,omitempty"`
Origin courier.MsgOrigin `json:"origin"`
UserID courier.UserID `json:"user_id,omitempty"`
}

type sendPayload struct {
Expand All @@ -133,10 +134,11 @@ func (h *handler) Send(ctx context.Context, msg courier.MsgOut, res *courier.Sen
ChatID: msg.URN().Path(),
Secret: secret,
Msg: sendMsg{
ID: msg.ID(),
Text: msg.Text(),
Origin: msg.Origin(),
UserID: msg.UserID(),
ID: msg.ID(),
Text: msg.Text(),
Attachments: msg.Attachments(),
Origin: msg.Origin(),
UserID: msg.UserID(),
},
}
req, _ := http.NewRequest("POST", sendURL+"/"+string(msg.Channel().UUID())+"/", bytes.NewReader(jsonx.MustMarshal(payload)))
Expand Down
10 changes: 5 additions & 5 deletions handlers/chip/handler_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -91,18 +91,18 @@ var outgoingCases = []OutgoingTestCase{
},
},
{
Label: "Chat message",
MsgText: "Simple message ☺",
MsgURN: "webchat:65vbbDAQCdPdEWlEhDGy4utO",
MsgUserID: 123,
Label: "Chat message that is an attachment",
MsgAttachments: []string{"image/jpeg:https://example.com/image.jpg"},
MsgURN: "webchat:65vbbDAQCdPdEWlEhDGy4utO",
MsgUserID: 123,
MockResponses: map[string][]*httpx.MockResponse{
"http://textit.com/wc/send/8eb23e93-5ecb-45ba-b726-3b064e0c56ab/": {
httpx.NewMockResponse(200, nil, []byte(`{"status": "queued"}`)),
},
},
ExpectedRequests: []ExpectedRequest{
{
Body: `{"chat_id":"65vbbDAQCdPdEWlEhDGy4utO","secret":"sesame","msg":{"id":10,"text":"Simple message ☺","origin":"flow","user_id":123}}`,
Body: `{"chat_id":"65vbbDAQCdPdEWlEhDGy4utO","secret":"sesame","msg":{"id":10,"text":"","attachments":["image/jpeg:https://example.com/image.jpg"],"origin":"flow","user_id":123}}`,
},
},
},
Expand Down

0 comments on commit 2b4156f

Please sign in to comment.