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

Send chatbot history on Twilio in just one message #109

Merged
merged 2 commits into from
Jan 25, 2023
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
34 changes: 17 additions & 17 deletions services/tickets/twilioflex/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -284,27 +284,27 @@ func SendHistory(session flows.Session, contactID flows.ContactID, newFlexChanne
return
}
var trace *httpx.Trace
historyMsg := ""
// send history
for _, msg := range msgs {
m := &CreateChatMessageParams{
Body: msg.Text(),
ChannelSid: newFlexChannel.Sid,
DateCreated: msg.CreatedOn().Format(time.RFC3339),
}
if msg.Direction() == "I" {
m.From = fmt.Sprint(contactID)
headerWebhookEnabled := http.Header{"X-Twilio-Webhook-Enabled": []string{"True"}}
_, trace, err = restClient.CreateMessage(m, headerWebhookEnabled)
historyMsg += "👤 (" + msg.CreatedOn().Format("02/01/2006 15:04:05") + "): " + msg.Text() + "\n"
} else {
m.From = "Bot"
_, trace, err = restClient.CreateMessage(m, nil)
}
if trace != nil {
logHTTP(flows.NewHTTPLog(trace, flows.HTTPStatusFromCode, redactor))
}
if err != nil {
logrus.Error(errors.Wrap(err, "error calling Twilio to send message from history"))
return
historyMsg += "🤖 (" + msg.CreatedOn().Format("02/01/2006 15:04:05") + "): " + msg.Text() + "\n"
}
}
m := &CreateChatMessageParams{
Body: historyMsg,
From: "Chatbot History",
ChannelSid: newFlexChannel.Sid,
DateCreated: time.Now().Format(time.RFC3339),
}
_, trace, err = restClient.CreateMessage(m, nil)
if trace != nil {
logHTTP(flows.NewHTTPLog(trace, flows.HTTPStatusFromCode, redactor))
}
if err != nil {
logrus.Error(errors.Wrap(err, "error calling Twilio to send message from history"))
return
}
}
2 changes: 1 addition & 1 deletion services/tickets/twilioflex/service_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -603,5 +603,5 @@ func TestSendHistory(t *testing.T) {
restClient,
nil,
)
assert.Equal(t, 3, len(logger.Logs))
assert.Equal(t, 1, len(logger.Logs))
}
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
POST /api/v2/any_channel/push.json HTTP/1.1
Host: nyaruka.zendesk.com
User-Agent: Go-http-client/1.1
Content-Length: 416
Content-Length: 425
Authorization: Bearer ****************
Content-Type: application/json
Accept-Encoding: gzip

{"instance_push_id":"1234-abcd","request_id":"sesame:1570461700000000000","external_resources":[{"external_id":"ca5607f0-cba8-4c94-9cd5-c4fbc24aa767","message":"It's urgent","thread_id":"59d74b86-3e2f-4a93-aece-b05d2fdcde0c","created_at":"2019-10-07T15:21:39Z","author":{"external_id":"6393abc0-283d-4c9b-a1b3-641a035c34bf","name":"Cathy"},"allow_channelback":true,"file_urls":["https://flows.weni.ai/api/v2/file/0123/attachment1.jpg"]}]}
{"instance_push_id":"1234-abcd","request_id":"sesame:1570461700000000000","external_resources":[{"external_id":"ca5607f0-cba8-4c94-9cd5-c4fbc24aa767","message":"It's urgent","thread_id":"59d74b86-3e2f-4a93-aece-b05d2fdcde0c","created_at":"2019-10-07T15:21:39Z","author":{"external_id":"6393abc0-283d-4c9b-a1b3-641a035c34bf","name":"Cathy"},"allow_channelback":true,"file_urls":["https:///api/v2/file/0123/attachment1.jpg"]}]}