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

Wenichats integration tweaks #113

Merged
merged 2 commits into from
Jan 31, 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
2 changes: 1 addition & 1 deletion services/tickets/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@ func FetchFileWithMaxSize(url string, headers map[string]string, maxBodyBytes in
if err != nil {
return nil, err
}
if trace.Response.StatusCode/10 != 2 {
if trace.Response.StatusCode/100 != 2 {
return nil, errors.New("fetch returned no-200 response")
}

Expand Down
8 changes: 8 additions & 0 deletions services/tickets/wenichats/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import (

"github.com/nyaruka/gocommon/httpx"
"github.com/nyaruka/gocommon/jsonx"
"github.com/nyaruka/goflow/assets"
"github.com/pkg/errors"
)

Expand Down Expand Up @@ -153,6 +154,8 @@ type RoomRequest struct {
CreatedOn *time.Time `json:"created_on,omitempty"`
CustomFields map[string]interface{} `json:"custom_fields,omitempty"`
CallbackURL string `json:"callback_url,omitempty"`
FlowUUID assets.FlowUUID `json:"flow_uuid,omitempty"`
Groups []Group `json:"groups,omitempty"`
}

type Contact struct {
Expand Down Expand Up @@ -242,3 +245,8 @@ type Queue struct {
UUID string `json:"uuid"`
Name string `json:"name"`
}

type Group struct {
UUID string `json:"uuid"`
Name string `json:"name"`
}
8 changes: 8 additions & 0 deletions services/tickets/wenichats/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -89,11 +89,19 @@ func (s *service) Open(session flows.Session, topic *flows.Topic, body string, a
roomData.UserEmail = assignee.Email()
}

var groups []Group
for _, group := range contact.Groups().All() {
g := Group{UUID: string(group.UUID()), Name: group.Name()}
groups = append(groups, g)
}

roomData.Contact.ExternalID = string(contact.UUID())
roomData.Contact.Name = contact.Name()
roomData.SectorUUID = s.sectorUUID
roomData.QueueUUID = string(topic.UUID())
roomData.Contact.URN = session.Contact().PreferredURN().URN().String()
roomData.FlowUUID = session.Runs()[0].Flow().UUID()
roomData.Groups = groups

extra := &struct {
CustomFields map[string]interface{} `json:"custom_fields,omitempty"`
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
POST /v1/external/rooms/ HTTP/1.1
Host: chats-engine.dev.cloud.weni.ai
User-Agent: Go-http-client/1.1
Content-Length: 393
Content-Length: 583
Authorization: Bearer ****************
Content-Type: application/json
Accept-Encoding: gzip

{"queue_uuid":"ffc903f7-8cbb-443f-9627-87106842d1aa","sector_uuid":"1a4bae05-993c-4f3b-91b5-80f4e09951f2","contact":{"external_id":"5d76d86b-3bb9-4d5a-b822-c9d86f5d8e4f","name":"Ryan Lewis","urn":"tel:+12024561111?channel=57f1078f-88aa-46f4-a59a-948a5739c03d"},"custom_fields":{"activation_****************":"AACC55","age":"23","country":"brazil","gender":"Male","join_date":"2017-12-02","mood":"angry"}}
{"queue_uuid":"ffc903f7-8cbb-443f-9627-87106842d1aa","sector_uuid":"1a4bae05-993c-4f3b-91b5-80f4e09951f2","contact":{"external_id":"5d76d86b-3bb9-4d5a-b822-c9d86f5d8e4f","name":"Ryan Lewis","urn":"tel:+12024561111?channel=57f1078f-88aa-46f4-a59a-948a5739c03d"},"custom_fields":{"activation_****************":"AACC55","age":"23","country":"brazil","gender":"Male","join_date":"2017-12-02","mood":"angry"},"flow_uuid":"50c3706e-fedb-42c0-8eab-dda3335714b7","groups":[{"uuid":"b7cf0d83-f1c9-411c-96fd-c511a4cfa86d","name":"Testers"},{"uuid":"4f1f98fc-27a7-4a69-bbdb-24744ba739a9","name":"Males"}]}