Skip to content

Commit 7dad003

Browse files
authored
Merge pull request #158 from nyaruka/trigger_param_fix
Fix params on triggers so resolving doesn't blow up when they are empty
2 parents 5558d4f + 5b8e184 commit 7dad003

File tree

3 files changed

+8
-7
lines changed

3 files changed

+8
-7
lines changed

flows/interfaces.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -205,7 +205,7 @@ type Trigger interface {
205205
Environment() utils.Environment
206206
Flow() Flow
207207
Contact() *Contact
208-
Params() *utils.JSONFragment
208+
Params() utils.JSONFragment
209209
TriggeredOn() time.Time
210210
}
211211

flows/triggers/base.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,14 +12,14 @@ type baseTrigger struct {
1212
environment utils.Environment
1313
flow flows.Flow
1414
contact *flows.Contact
15-
params *utils.JSONFragment
15+
params utils.JSONFragment
1616
triggeredOn time.Time
1717
}
1818

1919
func (t *baseTrigger) Environment() utils.Environment { return t.environment }
2020
func (t *baseTrigger) Flow() flows.Flow { return t.flow }
2121
func (t *baseTrigger) Contact() *flows.Contact { return t.contact }
22-
func (t *baseTrigger) Params() *utils.JSONFragment { return t.params }
22+
func (t *baseTrigger) Params() utils.JSONFragment { return t.params }
2323
func (t *baseTrigger) TriggeredOn() time.Time { return t.triggeredOn }
2424

2525
func (t *baseTrigger) Default() interface{} {
@@ -30,7 +30,7 @@ func (t *baseTrigger) Default() interface{} {
3030
func (t *baseTrigger) Resolve(key string) interface{} {
3131
switch key {
3232
case "params":
33-
return *t.params
33+
return t.params
3434
}
3535

3636
return fmt.Errorf("No such field '%s' on trigger", key)

flows/triggers/envelope.go

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -50,8 +50,9 @@ func unmarshalBaseTrigger(session flows.Session, base *baseTrigger, envelope *ba
5050
}
5151
}
5252
if envelope.Params != nil {
53-
params := utils.JSONFragment(envelope.Params)
54-
base.params = &params
53+
base.params = utils.JSONFragment(envelope.Params)
54+
} else {
55+
base.params = utils.EmptyJSONFragment
5556
}
5657

5758
return nil
@@ -75,7 +76,7 @@ func marshalBaseTrigger(t *baseTrigger, envelope *baseTriggerEnvelope) error {
7576
}
7677
}
7778
if t.params != nil {
78-
envelope.Params = json.RawMessage(*t.params)
79+
envelope.Params = json.RawMessage(t.params)
7980
}
8081
return nil
8182
}

0 commit comments

Comments
 (0)