Skip to content

Commit

Permalink
Merge branch 'master' into no_more_legacy
Browse files Browse the repository at this point in the history
  • Loading branch information
rowanseymour committed Nov 25, 2019
2 parents 42dfedb + dce1a57 commit c822217
Show file tree
Hide file tree
Showing 7 changed files with 86 additions and 43 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
v5.3.6
----------
* Load global assets from database

v5.3.5
----------
* Update to goflow v0.59.0
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ require (
github.com/mattn/go-sqlite3 v1.10.0 // indirect
github.com/nyaruka/ezconf v0.2.1
github.com/nyaruka/gocommon v1.1.1
github.com/nyaruka/goflow v0.59.0
github.com/nyaruka/goflow v0.60.0
github.com/nyaruka/librato v1.0.0
github.com/nyaruka/logrus_sentry v0.8.2-0.20190129182604-c2962b80ba7d
github.com/nyaruka/null v1.2.0
Expand Down
6 changes: 2 additions & 4 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -70,10 +70,8 @@ github.com/nyaruka/ezconf v0.2.1 h1:TDXWoqjqYya1uhou1mAJZg7rgFYL98EB0Tb3+BWtUh0=
github.com/nyaruka/ezconf v0.2.1/go.mod h1:ey182kYkw2MIi4XiWe1FR/mzI33WCmTWuceDYYxgnQw=
github.com/nyaruka/gocommon v1.1.1 h1:RnQ+kMzN1lA+W0NpkBDd0mGU3UqadJygR3SMpITMYTQ=
github.com/nyaruka/gocommon v1.1.1/go.mod h1:QbdU2J9WBsqBmeZRuwndf2f6O7rD7mkC0bGn5UNnwjI=
github.com/nyaruka/goflow v0.58.0 h1:zoy5ZcbTDhhSFC6PiI/G3wp/bGPWqfEH+aCl65tRhqY=
github.com/nyaruka/goflow v0.58.0/go.mod h1:wI+5qZRajxxZvfYXqbmWauTWAJ0GOTTG3TZDkixU/E0=
github.com/nyaruka/goflow v0.59.0 h1:Gf/iV9o3ZE7tHyxyRp8fraLaxcP0mSgsV0MZ0u6gRqM=
github.com/nyaruka/goflow v0.59.0/go.mod h1:wI+5qZRajxxZvfYXqbmWauTWAJ0GOTTG3TZDkixU/E0=
github.com/nyaruka/goflow v0.60.0 h1:GSaRkdlUwVZrBoKJgbe7VsIdoh+ZUIgiv8Hy1ikh/Lo=
github.com/nyaruka/goflow v0.60.0/go.mod h1:wI+5qZRajxxZvfYXqbmWauTWAJ0GOTTG3TZDkixU/E0=
github.com/nyaruka/librato v1.0.0 h1:Vznj9WCeC1yZXbBYyYp40KnbmXLbEkjKmHesV/v2SR0=
github.com/nyaruka/librato v1.0.0/go.mod h1:pkRNLFhFurOz0QqBz6/DuTFhHHxAubWxs4Jx+J7yUgg=
github.com/nyaruka/logrus_sentry v0.8.2-0.20190129182604-c2962b80ba7d h1:hyp9u36KIwbTCo2JAJ+TuJcJBc+UZzEig7RI/S5Dvkc=
Expand Down
16 changes: 8 additions & 8 deletions ivr/nexmo/nexmo_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,40 +61,40 @@ func TestResponseForSprint(t *testing.T) {
Expected string
}{
{
[]flows.Event{events.NewIVRCreated(flows.NewMsgOut(urn, channelRef, "hello world", nil, nil, nil))},
[]flows.Event{events.NewIVRCreated(flows.NewMsgOut(urn, channelRef, "hello world", nil, nil, nil, flows.NilMsgTopic))},
nil,
`[{"action":"talk","text":"hello world"}]`,
},
{
[]flows.Event{events.NewIVRCreated(flows.NewMsgOut(urn, channelRef, "hello world", []utils.Attachment{utils.Attachment("audio:/recordings/foo.wav")}, nil, nil))},
[]flows.Event{events.NewIVRCreated(flows.NewMsgOut(urn, channelRef, "hello world", []utils.Attachment{utils.Attachment("audio:/recordings/foo.wav")}, nil, nil, flows.NilMsgTopic))},
nil,
`[{"action":"stream","streamUrl":["/recordings/foo.wav"]}]`,
},
{
[]flows.Event{events.NewIVRCreated(flows.NewMsgOut(urn, channelRef, "hello world", []utils.Attachment{utils.Attachment("audio:https://temba.io/recordings/foo.wav")}, nil, nil))},
[]flows.Event{events.NewIVRCreated(flows.NewMsgOut(urn, channelRef, "hello world", []utils.Attachment{utils.Attachment("audio:https://temba.io/recordings/foo.wav")}, nil, nil, flows.NilMsgTopic))},
nil,
`[{"action":"stream","streamUrl":["https://temba.io/recordings/foo.wav"]}]`,
},
{
[]flows.Event{
events.NewIVRCreated(flows.NewMsgOut(urn, channelRef, "hello world", nil, nil, nil)),
events.NewIVRCreated(flows.NewMsgOut(urn, channelRef, "goodbye", nil, nil, nil)),
events.NewIVRCreated(flows.NewMsgOut(urn, channelRef, "hello world", nil, nil, nil, flows.NilMsgTopic)),
events.NewIVRCreated(flows.NewMsgOut(urn, channelRef, "goodbye", nil, nil, nil, flows.NilMsgTopic)),
},
nil,
`[{"action":"talk","text":"hello world"},{"action":"talk","text":"goodbye"}]`,
},
{
[]flows.Event{events.NewIVRCreated(flows.NewMsgOut(urn, channelRef, "enter a number", nil, nil, nil))},
[]flows.Event{events.NewIVRCreated(flows.NewMsgOut(urn, channelRef, "enter a number", nil, nil, nil, flows.NilMsgTopic))},
waits.NewActivatedMsgWait(nil, hints.NewFixedDigitsHint(1)),
`[{"action":"talk","text":"enter a number","bargeIn":true},{"action":"input","maxDigits":1,"submitOnHash":true,"timeOut":30,"eventUrl":["http://temba.io/resume?session=1\u0026wait_type=gather\u0026sig=OjsMUDhaBTUVLq1e6I4cM0SKYpk%3D"],"eventMethod":"POST"}]`,
},
{
[]flows.Event{events.NewIVRCreated(flows.NewMsgOut(urn, channelRef, "enter a number, then press #", nil, nil, nil))},
[]flows.Event{events.NewIVRCreated(flows.NewMsgOut(urn, channelRef, "enter a number, then press #", nil, nil, nil, flows.NilMsgTopic))},
waits.NewActivatedMsgWait(nil, hints.NewTerminatedDigitsHint("#")),
`[{"action":"talk","text":"enter a number, then press #","bargeIn":true},{"action":"input","maxDigits":20,"submitOnHash":true,"timeOut":30,"eventUrl":["http://temba.io/resume?session=1\u0026wait_type=gather\u0026sig=OjsMUDhaBTUVLq1e6I4cM0SKYpk%3D"],"eventMethod":"POST"}]`,
},
{
[]flows.Event{events.NewIVRCreated(flows.NewMsgOut(urn, channelRef, "say something", nil, nil, nil))},
[]flows.Event{events.NewIVRCreated(flows.NewMsgOut(urn, channelRef, "say something", nil, nil, nil, flows.NilMsgTopic))},
waits.NewActivatedMsgWait(nil, hints.NewAudioHint()),
`[{"action":"talk","text":"say something"},{"action":"record","endOnKey":"#","timeOut":600,"endOnSilence":5,"eventUrl":["http://temba.io/resume?session=1\u0026wait_type=recording_url\u0026recording_uuid=f3ede2d6-becc-4ea3-ae5e-88526a9f4a57\u0026sig=Am9z7fXyU3SPCZagkSpddZSi6xY%3D"],"eventMethod":"POST"},{"action":"input","submitOnHash":true,"timeOut":1,"eventUrl":["http://temba.io/resume?session=1\u0026wait_type=record\u0026recording_uuid=f3ede2d6-becc-4ea3-ae5e-88526a9f4a57\u0026sig=fX1RhjcJNN4xYaiojVYakaz5F%2Fk%3D"],"eventMethod":"POST"}]`,
},
Expand Down
16 changes: 8 additions & 8 deletions ivr/twiml/twiml_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,40 +36,40 @@ func TestResponseForSprint(t *testing.T) {
Expected string
}{
{
[]flows.Event{events.NewIVRCreated(flows.NewMsgOut(urn, channelRef, "hello world", nil, nil, nil))},
[]flows.Event{events.NewIVRCreated(flows.NewMsgOut(urn, channelRef, "hello world", nil, nil, nil, flows.NilMsgTopic))},
nil,
`<Response><Say>hello world</Say><Hangup></Hangup></Response>`,
},
{
[]flows.Event{events.NewIVRCreated(flows.NewMsgOut(urn, channelRef, "hello world", []utils.Attachment{utils.Attachment("audio:/recordings/foo.wav")}, nil, nil))},
[]flows.Event{events.NewIVRCreated(flows.NewMsgOut(urn, channelRef, "hello world", []utils.Attachment{utils.Attachment("audio:/recordings/foo.wav")}, nil, nil, flows.NilMsgTopic))},
nil,
`<Response><Play>https://mailroom.io/recordings/foo.wav</Play><Hangup></Hangup></Response>`,
},
{
[]flows.Event{events.NewIVRCreated(flows.NewMsgOut(urn, channelRef, "hello world", []utils.Attachment{utils.Attachment("audio:https://temba.io/recordings/foo.wav")}, nil, nil))},
[]flows.Event{events.NewIVRCreated(flows.NewMsgOut(urn, channelRef, "hello world", []utils.Attachment{utils.Attachment("audio:https://temba.io/recordings/foo.wav")}, nil, nil, flows.NilMsgTopic))},
nil,
`<Response><Play>https://temba.io/recordings/foo.wav</Play><Hangup></Hangup></Response>`,
},
{
[]flows.Event{
events.NewIVRCreated(flows.NewMsgOut(urn, channelRef, "hello world", nil, nil, nil)),
events.NewIVRCreated(flows.NewMsgOut(urn, channelRef, "goodbye", nil, nil, nil)),
events.NewIVRCreated(flows.NewMsgOut(urn, channelRef, "hello world", nil, nil, nil, flows.NilMsgTopic)),
events.NewIVRCreated(flows.NewMsgOut(urn, channelRef, "goodbye", nil, nil, nil, flows.NilMsgTopic)),
},
nil,
`<Response><Say>hello world</Say><Say>goodbye</Say><Hangup></Hangup></Response>`,
},
{
[]flows.Event{events.NewIVRCreated(flows.NewMsgOut(urn, channelRef, "enter a number", nil, nil, nil))},
[]flows.Event{events.NewIVRCreated(flows.NewMsgOut(urn, channelRef, "enter a number", nil, nil, nil, flows.NilMsgTopic))},
waits.NewActivatedMsgWait(nil, hints.NewFixedDigitsHint(1)),
`<Response><Gather numDigits="1" timeout="30" action="http://temba.io/resume?session=1&amp;wait_type=gather"><Say>enter a number</Say></Gather><Redirect>http://temba.io/resume?session=1&amp;wait_type=gather&amp;timeout=true</Redirect></Response>`,
},
{
[]flows.Event{events.NewIVRCreated(flows.NewMsgOut(urn, channelRef, "enter a number, then press #", nil, nil, nil))},
[]flows.Event{events.NewIVRCreated(flows.NewMsgOut(urn, channelRef, "enter a number, then press #", nil, nil, nil, flows.NilMsgTopic))},
waits.NewActivatedMsgWait(nil, hints.NewTerminatedDigitsHint("#")),
`<Response><Gather finishOnKey="#" timeout="30" action="http://temba.io/resume?session=1&amp;wait_type=gather"><Say>enter a number, then press #</Say></Gather><Redirect>http://temba.io/resume?session=1&amp;wait_type=gather&amp;timeout=true</Redirect></Response>`,
},
{
[]flows.Event{events.NewIVRCreated(flows.NewMsgOut(urn, channelRef, "say something", nil, nil, nil))},
[]flows.Event{events.NewIVRCreated(flows.NewMsgOut(urn, channelRef, "say something", nil, nil, nil, flows.NilMsgTopic))},
waits.NewActivatedMsgWait(nil, hints.NewAudioHint()),
`<Response><Say>say something</Say><Record action="http://temba.io/resume?session=1&amp;wait_type=record" maxLength="600"></Record><Redirect>http://temba.io/resume?session=1&amp;wait_type=record&amp;empty=true</Redirect></Response>`,
},
Expand Down
7 changes: 5 additions & 2 deletions models/msgs.go
Original file line number Diff line number Diff line change
Expand Up @@ -320,14 +320,17 @@ func NewOutgoingMsg(orgID OrgID, channel *Channel, contactID ContactID, out *flo
}

// populate metadata if we have any
if len(out.QuickReplies()) > 0 || out.Templating() != nil {
if len(out.QuickReplies()) > 0 || out.Templating() != nil || out.Topic() != flows.NilMsgTopic {
metadata := make(map[string]interface{})
if len(out.QuickReplies()) > 0 {
metadata["quick_replies"] = out.QuickReplies()
}
if out.Templating() != nil {
metadata["templating"] = out.Templating()
}
if out.Topic() != flows.NilMsgTopic {
metadata["topic"] = string(out.Topic())
}
m.Metadata = null.NewMap(metadata)
}

Expand Down Expand Up @@ -873,7 +876,7 @@ func CreateBroadcastMessages(ctx context.Context, db Queryer, rp *redis.Pool, or
}

// create our outgoing message
out := flows.NewMsgOut(urn, channel.ChannelReference(), text, t.Attachments, t.QuickReplies, nil)
out := flows.NewMsgOut(urn, channel.ChannelReference(), text, t.Attachments, t.QuickReplies, nil, flows.NilMsgTopic)
msg, err := NewOutgoingMsg(org.OrgID(), channel, c.ID(), out, time.Now())
msg.SetBroadcastID(bcast.BroadcastID())
if err != nil {
Expand Down
78 changes: 58 additions & 20 deletions models/msgs_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,24 +26,62 @@ func TestMsgs(t *testing.T) {
chanUUID := channels[0].UUID()

tcs := []struct {
ChannelUUID assets.ChannelUUID
Channel *Channel
Text string
ContactID ContactID
URN urns.URN
ContactURNID URNID
Attachments []utils.Attachment
QuickReplies []string
Metadata map[string]interface{}
MsgCount int
HasErr bool
ChannelUUID assets.ChannelUUID
Channel *Channel
Text string
ContactID ContactID
URN urns.URN
ContactURNID URNID
Attachments []utils.Attachment
QuickReplies []string
Topic flows.MsgTopic
ExpectedMetadata map[string]interface{}
ExpectedMsgCount int
HasErr bool
}{
{chanUUID, channel, "missing urn id", CathyID, urns.URN("tel:+250700000001"), URNID(0),
nil, nil, map[string]interface{}{}, 1, true},
{chanUUID, channel, "test outgoing", CathyID, urns.URN(fmt.Sprintf("tel:+250700000001?id=%d", CathyURNID)), CathyURNID,
nil, []string{"yes", "no"}, map[string]interface{}{"quick_replies": []string{"yes", "no"}}, 1, false},
{chanUUID, channel, "test outgoing", CathyID, urns.URN(fmt.Sprintf("tel:+250700000001?id=%d", CathyURNID)), CathyURNID,
[]utils.Attachment{utils.Attachment("image/jpeg:https://dl-foo.com/image.jpg")}, nil, map[string]interface{}{}, 2, false},
{
chanUUID, channel,
"missing urn id",
CathyID,
urns.URN("tel:+250700000001"),
URNID(0),
nil,
nil,
flows.NilMsgTopic,
map[string]interface{}{},
1,
true,
},
{
chanUUID,
channel,
"test outgoing",
CathyID,
urns.URN(fmt.Sprintf("tel:+250700000001?id=%d", CathyURNID)),
CathyURNID,
nil,
[]string{"yes", "no"},
flows.MsgTopicPurchase,
map[string]interface{}{
"quick_replies": []string{"yes", "no"},
"topic": "purchase",
},
1,
false,
},
{
chanUUID,
channel,
"test outgoing",
CathyID,
urns.URN(fmt.Sprintf("tel:+250700000001?id=%d", CathyURNID)),
CathyURNID,
[]utils.Attachment{utils.Attachment("image/jpeg:https://dl-foo.com/image.jpg")},
nil,
flows.NilMsgTopic,
map[string]interface{}{},
2,
false},
}

now := time.Now()
Expand All @@ -53,7 +91,7 @@ func TestMsgs(t *testing.T) {
tx, err := db.BeginTxx(ctx, nil)
assert.NoError(t, err)

flowMsg := flows.NewMsgOut(tc.URN, assets.NewChannelReference(tc.ChannelUUID, "Test Channel"), tc.Text, tc.Attachments, tc.QuickReplies, nil)
flowMsg := flows.NewMsgOut(tc.URN, assets.NewChannelReference(tc.ChannelUUID, "Test Channel"), tc.Text, tc.Attachments, tc.QuickReplies, nil, tc.Topic)
msg, err := NewOutgoingMsg(orgID, tc.Channel, tc.ContactID, flowMsg, now)

if err == nil {
Expand All @@ -71,8 +109,8 @@ func TestMsgs(t *testing.T) {
} else {
assert.Nil(t, msg.ContactURNID())
}
assert.Equal(t, tc.Metadata, msg.Metadata())
assert.Equal(t, tc.MsgCount, msg.MsgCount())
assert.Equal(t, tc.ExpectedMetadata, msg.Metadata())
assert.Equal(t, tc.ExpectedMsgCount, msg.MsgCount())
assert.Equal(t, now, msg.CreatedOn())
assert.True(t, msg.ID() > 0)
assert.True(t, msg.QueuedOn().After(now))
Expand Down

0 comments on commit c822217

Please sign in to comment.