-
Notifications
You must be signed in to change notification settings - Fork 19
/
set_contact_status.go
50 lines (42 loc) · 1.53 KB
/
set_contact_status.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
package actions
import (
"github.com/nyaruka/goflow/flows"
"github.com/nyaruka/goflow/flows/events"
"github.com/nyaruka/goflow/flows/modifiers"
)
func init() {
registerType(TypeSetContactStatus, func() flows.Action { return &SetContactStatusAction{} })
}
// TypeSetContactStatus is the type for the set contact status action
const TypeSetContactStatus string = "set_contact_status"
// SetContactStatusAction can be used to update the status of the contact, e.g. to block or unblock the contact.
// A [event:contact_status_changed] event will be created with the corresponding value.
//
// {
// "uuid": "8eebd020-1af5-431c-b943-aa670fc74da9",
// "type": "set_contact_status",
// "status": "blocked"
// }
//
// @action set_contact_status
type SetContactStatusAction struct {
baseAction
universalAction
Status flows.ContactStatus `json:"status" validate:"contact_status"`
}
// NewSetContactStatus creates a new set status action
func NewSetContactStatus(uuid flows.ActionUUID, status flows.ContactStatus) *SetContactStatusAction {
return &SetContactStatusAction{
baseAction: newBaseAction(TypeSetContactStatus, uuid),
Status: status,
}
}
// Execute runs this action
func (a *SetContactStatusAction) Execute(run flows.FlowRun, step flows.Step, logModifier flows.ModifierCallback, logEvent flows.EventCallback) error {
if run.Contact() == nil {
logEvent(events.NewErrorf("can't execute action in session without a contact"))
return nil
}
a.applyModifier(run, modifiers.NewStatus(a.Status), logModifier, logEvent)
return nil
}