Skip to content

Commit

Permalink
Merge branch 'main' into bcast_tasks_pt2
Browse files Browse the repository at this point in the history
  • Loading branch information
rowanseymour committed Sep 23, 2024
2 parents 9a82ec5 + 81d44ee commit 5d4d726
Show file tree
Hide file tree
Showing 5 changed files with 37 additions and 14 deletions.
8 changes: 8 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,11 @@
v9.3.29 (2024-09-22)
-------------------------
* Fix trigger_session actions with IVR flows

v9.3.28 (2024-09-20)
-------------------------
* Add more info to error log when writing ivr channel log fails

v9.3.27 (2024-09-20)
-------------------------
* Add .broadcast field to broadcast batch tasks
Expand Down
30 changes: 17 additions & 13 deletions core/handlers/session_triggered_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,16 +23,6 @@ func TestSessionTriggered(t *testing.T) {

defer testsuite.Reset(testsuite.ResetAll)

oa, err := models.GetOrgAssets(ctx, rt, testdata.Org1.ID)
assert.NoError(t, err)

simpleFlow, err := oa.FlowByID(testdata.SingleMessage.ID)
assert.NoError(t, err)

contactRef := &flows.ContactReference{
UUID: testdata.George.UUID,
}

groupRef := &assets.GroupReference{
UUID: testdata.TestersGroup.UUID,
}
Expand All @@ -44,7 +34,7 @@ func TestSessionTriggered(t *testing.T) {
{
Actions: handlers.ContactActionMap{
testdata.Cathy: []flows.Action{
actions.NewStartSession(handlers.NewActionUUID(), simpleFlow.Reference(), []*assets.GroupReference{groupRef}, []*flows.ContactReference{contactRef}, "", nil, nil, true),
actions.NewStartSession(handlers.NewActionUUID(), testdata.SingleMessage.Reference(), []*assets.GroupReference{groupRef}, []*flows.ContactReference{testdata.George.Reference()}, "", nil, nil, true),
},
},
SQLAssertions: []handlers.SQLAssertion{
Expand Down Expand Up @@ -72,12 +62,26 @@ func TestSessionTriggered(t *testing.T) {
assert.True(t, start.CreateContact)
assert.Equal(t, []models.ContactID{testdata.George.ID}, start.ContactIDs)
assert.Equal(t, []models.GroupID{testdata.TestersGroup.ID}, start.GroupIDs)
assert.Equal(t, simpleFlow.ID(), start.FlowID)
assert.JSONEq(t, `{"parent_uuid":"39a9f95e-3641-4d19-95e0-ed866f27c829", "ancestors":1, "ancestors_since_input":1}`, string(start.SessionHistory))
assert.Equal(t, testdata.SingleMessage.ID, start.FlowID)
assert.JSONEq(t, `{"parent_uuid":"36284611-ea19-4f1f-8611-9bc48e206654", "ancestors":1, "ancestors_since_input":1}`, string(start.SessionHistory))
return nil
},
},
},
{
Actions: handlers.ContactActionMap{
testdata.Bob: []flows.Action{
actions.NewStartSession(handlers.NewActionUUID(), testdata.IVRFlow.Reference(), nil, []*flows.ContactReference{testdata.Alexandria.Reference()}, "", nil, nil, true),
},
},
SQLAssertions: []handlers.SQLAssertion{
{ // check that we do have a start in the database because it's an IVR flow
SQL: "select count(*) from flows_flowstart where org_id = 1 AND flow_id = $1",
Args: []any{testdata.IVRFlow.ID},
Count: 1,
},
},
},
}

handlers.RunTestCases(t, ctx, rt, tcs)
Expand Down
7 changes: 7 additions & 0 deletions core/hooks/create_starts.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,13 @@ func (h *createStartsHook) Apply(ctx context.Context, rt *runtime.Runtime, tx *s
WithParentSummary(event.RunSummary).
WithSessionHistory(historyJSON)

// TODO find another way to pass start info to new calls
if flow.FlowType() == models.FlowTypeVoice {
if err := models.InsertFlowStarts(ctx, tx, []*models.FlowStart{start}); err != nil {
return fmt.Errorf("error inserting flow start: %w", err)
}
}

err = tasks.Queue(rc, tasks.BatchQueue, oa.OrgID(), &starts.StartFlowTask{FlowStart: start}, queues.DefaultPriority)
if err != nil {
return fmt.Errorf("error queuing flow start: %w", err)
Expand Down
4 changes: 4 additions & 0 deletions testsuite/testdata/contacts.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,10 @@ type Contact struct {
URNID models.URNID
}

func (c *Contact) Reference() *flows.ContactReference {
return &flows.ContactReference{UUID: c.UUID, Name: ""}
}

func (c *Contact) Load(rt *runtime.Runtime, oa *models.OrgAssets) (*models.Contact, *flows.Contact, []*models.ContactURN) {
ctx := context.Background()

Expand Down
2 changes: 1 addition & 1 deletion web/ivr/ivr.go
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ func newIVRHandler(handler ivrHandlerFn, logType clogs.LogType) web.Handler {
clog.End()

if err := models.InsertChannelLogs(ctx, rt, []*models.ChannelLog{clog}); err != nil {
slog.Error("error writing ivr channel log", "error", err, "http_request", r)
slog.Error("error writing ivr channel log", "error", err, "elapsed", clog.Elapsed, "channel", ch.UUID())
}

return rerr
Expand Down

0 comments on commit 5d4d726

Please sign in to comment.