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

twilioflex open ticket can set preferred flexflow from body flws_flow… #88

Merged
merged 1 commit into from
Nov 4, 2022
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
14 changes: 14 additions & 0 deletions services/tickets/twilioflex/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package twilioflex

import (
"context"
"encoding/json"
"fmt"
"net/http"
"net/url"
Expand Down Expand Up @@ -118,6 +119,19 @@ func (s *service) Open(session flows.Session, topic *flows.Topic, body string, a

flexChannelParams.TaskAttributes = body

bodyStruct := struct {
FlexFlowSid *string `json:"flex_flow_sid,omitempty"`
}{}

err = json.Unmarshal([]byte(body), &bodyStruct)
if err != nil {
return nil, errors.Wrap(err, "failed to unmarshal body")
}

if bodyStruct.FlexFlowSid != nil {
flexChannelParams.FlexFlowSid = *bodyStruct.FlexFlowSid
}

newFlexChannel, trace, err := s.restClient.CreateFlexChannel(flexChannelParams)
if trace != nil {
logHTTP(flows.NewHTTPLog(trace, flows.HTTPStatusFromCode, s.redactor))
Expand Down
5 changes: 3 additions & 2 deletions services/tickets/twilioflex/service_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -348,6 +348,7 @@ func TestOpenAndForward(t *testing.T) {
assert.EqualError(t, err, "missing auth_token or account_sid or chat_service_sid or workspace_sid in twilio flex config")

mockDB, mock, err := sqlmock.New()
assert.NoError(t, err)
defer mockDB.Close()
sqlxDB := sqlx.NewDb(mockDB, "sqlmock")

Expand Down Expand Up @@ -387,12 +388,12 @@ func TestOpenAndForward(t *testing.T) {
defaultTopic := oa.SessionAssets().Topics().FindByName("General")

logger := &flows.HTTPLogger{}
ticket, err := svc.Open(session, defaultTopic, `{"extra_field":"foo","custom_fields":{"bar_field":"bar"}}`, nil, logger.Log)
ticket, err := svc.Open(session, defaultTopic, `{"flex_flow_sid":"FO123456abcdefg789ijklm","extra_field":"foo","custom_fields":{"bar_field":"bar"}}`, nil, logger.Log)

assert.NoError(t, err)
assert.Equal(t, flows.TicketUUID("e7187099-7d38-4f60-955c-325957214c42"), ticket.UUID())
assert.Equal(t, "General", ticket.Topic().Name())
assert.Equal(t, `{"extra_field":"foo","custom_fields":{"bar_field":"bar"}}`, ticket.Body())
assert.Equal(t, `{"flex_flow_sid":"FO123456abcdefg789ijklm","extra_field":"foo","custom_fields":{"bar_field":"bar"}}`, ticket.Body())
assert.Equal(t, "CH6442c09c93ba4d13966fa42e9b78f620", ticket.ExternalID())
assert.Equal(t, 7, len(logger.Logs))
test.AssertSnapshot(t, "open_ticket", logger.Logs[0].Request)
Expand Down