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

Feature/ticketer twilio flex #61

Merged
merged 24 commits into from
Apr 4, 2022
Merged
Changes from 1 commit
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
b7df743
add twilioflex ticketer client base
rasoro Jan 21, 2022
9694ddb
add twilioflex ticketer service base
rasoro Jan 21, 2022
63dc542
Add ticketer twilio flex Open Implementation
rasoro Jan 26, 2022
603d1ff
add twiliflex ticketer Forward implementation
rasoro Jan 27, 2022
0546e7e
add twilioflex ticketer web service for webhook callback events
rasoro Jan 27, 2022
b567a78
add twilio flex ticketer client CompleteTask to close ticket
rasoro Feb 1, 2022
add08bd
add twilio flex service Close method implementation
rasoro Feb 1, 2022
e47f870
add case for twilio channel update event callback to close ticket
rasoro Feb 1, 2022
3b49379
update db dump to add twilio flex dummy ticketer
rasoro Mar 11, 2022
c1a6904
add twilio flex ticketer test constant
rasoro Mar 11, 2022
38a1843
twilioflex client test
rasoro Mar 11, 2022
d04f571
twilioflex ticketer service test
rasoro Mar 11, 2022
6da5613
add twilioflex ticketer testdata
rasoro Mar 11, 2022
6fbb3e8
twilioflex ticketer web test
rasoro Mar 11, 2022
0d62683
refactor twilioflex ticketer web
rasoro Mar 11, 2022
f631afc
support to media message
rasoro Mar 16, 2022
40d90a0
adjust twilio flex ticketer client test
rasoro Mar 17, 2022
3e4dd99
add in ticketer twilioflex the custom fields to flex channel TaskAttr…
rasoro Mar 18, 2022
0fe4d35
twilioflex ticketer history
rasoro Mar 24, 2022
b717727
twilioflex ticketer service_test tweaks
rasoro Mar 24, 2022
a4dd956
fix twilioflex createFlexChannelParams in service
rasoro Mar 25, 2022
da6bde0
fix fetchUrl from twilioflex ticketer client FetchMedia
rasoro Mar 31, 2022
a5b23aa
update twilioflex web_test
rasoro Apr 1, 2022
c40b752
test select contact messages
rasoro Apr 4, 2022
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
25 changes: 11 additions & 14 deletions services/tickets/twilioflex/web.go
Original file line number Diff line number Diff line change
@@ -19,7 +19,7 @@ import (

func init() {
base := "/mr/tickets/types/twilioflex"
web.RegisterRoute(http.MethodPost, base+"/event_callback/{ticketer:[a-f0-9\\-]+}/{ticket:[a-f0-9\\-]+}", handleEventCallback)
web.RegisterJSONRoute(http.MethodPost, base+"/event_callback/{ticketer:[a-f0-9\\-]+}/{ticket:[a-f0-9\\-]+}", web.WithHTTPLogs(handleEventCallback))
}

type eventCallbackRequest struct {
@@ -40,57 +40,54 @@ type eventCallbackRequest struct {
WebhookSid string `json:"webhook_sid,omitempty"`
}

func handleEventCallback(ctx context.Context, rt *runtime.Runtime, r *http.Request, w http.ResponseWriter) error {
func handleEventCallback(ctx context.Context, rt *runtime.Runtime, r *http.Request, l *models.HTTPLogger) (interface{}, int, error) {
ticketerUUID := assets.TicketerUUID(chi.URLParam(r, "ticketer"))
request := &eventCallbackRequest{}
if err := web.DecodeAndValidateForm(request, r); err != nil {
return errors.Wrapf(err, "error decoding form")
return errors.Wrapf(err, "error decoding form"), http.StatusBadRequest, nil
}

ticketer, _, err := tickets.FromTicketerUUID(ctx, rt, ticketerUUID, typeTwilioFlex)
if err != nil {
return errors.Errorf("no such ticketer %s", ticketerUUID)
return errors.Errorf("no such ticketer %s", ticketerUUID), http.StatusNotFound, nil
}

accountSid := request.AccountSid
if accountSid != ticketer.Config(configurationAccountSid) {
return errors.New("Unauthorized")
return map[string]string{"status": "unauthorized"}, http.StatusUnauthorized, nil
}

ticketUUID := uuids.UUID(chi.URLParam(r, "ticket"))

ticket, _, _, err := tickets.FromTicketUUID(ctx, rt, flows.TicketUUID(ticketUUID), typeTwilioFlex)
if err != nil {
return errors.Errorf("no such ticket %s", ticketUUID)
return errors.Errorf("no such ticket %s", ticketUUID), http.StatusNotFound, nil
}

oa, err := models.GetOrgAssets(ctx, rt, ticket.OrgID())
if err != nil {
return err
return err, http.StatusBadRequest, nil
}

switch request.EventType {
case "onMessageSent":
// TODO: Attachments
_, err = tickets.SendReply(ctx, rt, ticket, request.Body, []*tickets.File{})
if err != nil {
return err
return err, http.StatusBadRequest, nil
}
case "onChannelUpdated":
jsonMap := make(map[string]interface{})
err = json.Unmarshal([]byte(request.Attributes), &jsonMap)
if err != nil {
return err
return err, http.StatusBadRequest, nil
}
if jsonMap["status"] == "INACTIVE" {
err = tickets.Close(ctx, rt, oa, ticket, false, nil)
if err != nil {
return err
return err, http.StatusBadRequest, nil
}
}
}
return nil
}

type EventAttributes struct {
return map[string]string{"status": "handled"}, http.StatusOK, nil
}