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

Receive order on input and trigger #34

Merged
merged 2 commits into from
Jul 22, 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
4 changes: 4 additions & 0 deletions WENI-CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
1.6.5-mailroom-7.1.22
----------
* Add support to receive order on input and tigger and any metadata object in trigger

1.6.4-mailroom-7.1.22
----------
* Update goflow version for v0.1.1-goflow-0.144.3
Expand Down
47 changes: 23 additions & 24 deletions core/tasks/handler/worker.go
Original file line number Diff line number Diff line change
Expand Up @@ -591,6 +591,28 @@ func handleMsgEvent(ctx context.Context, rt *runtime.Runtime, event *MsgEvent) e
msgIn.SetExternalID(string(event.MsgExternalID))
msgIn.SetID(event.MsgID)

if event.Metadata != nil {
var metadata map[string]interface{}
err := json.Unmarshal(event.Metadata, &metadata)
if err != nil {
log.WithError(err).Error("unable to unmarshal metadata from msg event")
}
// if metadata has order key set msg order
mdValue, ok := metadata["order"]
if ok {
var order *types.XObject
asJSON, err := json.Marshal(mdValue)
if err != nil {
log.WithError(err).Error("unable to marshal metadata from msg event")
}
order, err = types.ReadXObject(asJSON)
if err != nil {
log.WithError(err).Error("unable to marshal metadata from msg event")
}
msgIn.SetOrder(order)
}
}

// build our hook to mark a flow message as handled
flowMsgHook := func(ctx context.Context, tx *sqlx.Tx, rp *redis.Pool, oa *models.OrgAssets, sessions []*models.Session) error {
// set our incoming message event on our session
Expand Down Expand Up @@ -629,31 +651,8 @@ func handleMsgEvent(ctx context.Context, rt *runtime.Runtime, event *MsgEvent) e
trigger := triggers.NewBuilder(oa.Env(), flow.FlowReference(), contact).Msg(msgIn).WithMatch(trigger.Match())

if event.Metadata != nil {

var params *types.XObject
metadata := struct {
Headline string `json:"headline,omitempty"`
Body string `json:"body,omitempty"`
SourceType string `json:"source_type,omitempty"`
SourceID string `json:"source_id,omitempty"`
SourceURL string `json:"source_url,omitempty"`
Email string `json:"email,omitempty"`
Image *struct {
ID string `json:"id"`
} `json:"image,omitempty"`
Video *struct {
ID string `json:"id"`
} `json:"video,omitempty"`
}{}
err := json.Unmarshal(event.Metadata, &metadata)
if err != nil {
log.WithError(err).Error("unable to unmarshal metadata from msg event")
}
asJSON, err := json.Marshal(metadata)
if err != nil {
log.WithError(err).Error("unable to marshal metadata from msg event")
}
params, err = types.ReadXObject(asJSON)
params, err = types.ReadXObject(event.Metadata)
if err != nil {
log.WithError(err).Error("unable to marshal metadata from msg event")
}
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -70,4 +70,4 @@ go 1.17

replace github.com/nyaruka/gocommon => github.com/Ilhasoft/gocommon v1.16.2-weni

replace github.com/nyaruka/goflow => github.com/weni-ai/goflow v0.1.1-goflow-0.144.3
replace github.com/nyaruka/goflow => github.com/weni-ai/goflow v0.1.2-goflow-0.144.3
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -204,8 +204,8 @@ github.com/tj/assert v0.0.0-20171129193455-018094318fb0/go.mod h1:mZ9/Rh9oLWpLLD
github.com/tj/go-elastic v0.0.0-20171221160941-36157cbbebc2/go.mod h1:WjeM0Oo1eNAjXGDx2yma7uG2XoyRZTq1uv3M/o7imD0=
github.com/tj/go-kinesis v0.0.0-20171128231115-08b17f58cb1b/go.mod h1:/yhzCV0xPfx6jb1bBgRFjl5lytqVqZXEaeqWP8lTEao=
github.com/tj/go-spin v1.1.0/go.mod h1:Mg1mzmePZm4dva8Qz60H2lHwmJ2loum4VIrLgVnKwh4=
github.com/weni-ai/goflow v0.1.1-goflow-0.144.3 h1:h5JvjuIo7xhAenKl4m+E0OPIhYw0IETBUYqZEgpZlCw=
github.com/weni-ai/goflow v0.1.1-goflow-0.144.3/go.mod h1:o0xaVWP9qNcauBSlcNLa79Fm2oCPV+BDpheFRa/D40c=
github.com/weni-ai/goflow v0.1.2-goflow-0.144.3 h1:vcxe2AQO3MpaDMosP4mzUuQsBwRHd+abpQ68QA5XGT4=
github.com/weni-ai/goflow v0.1.2-goflow-0.144.3/go.mod h1:o0xaVWP9qNcauBSlcNLa79Fm2oCPV+BDpheFRa/D40c=
go.opencensus.io v0.22.5/go.mod h1:5pWMHQbX5EPX2/62yrJeAkowc+lfs/XD7Uxpq3pI6kk=
golang.org/x/crypto v0.0.0-20180904163835-0709b304e793/go.mod h1:6SG95UA2DQfeDnfUPMdvaQW0Q7yPrPDi9nlGo2tz2b4=
golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w=
Expand Down