-
Notifications
You must be signed in to change notification settings - Fork 19
/
set_contact_name.go
54 lines (44 loc) · 1.47 KB
/
set_contact_name.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
51
52
53
54
package actions
import (
"strings"
"github.com/nyaruka/goflow/flows"
"github.com/nyaruka/goflow/flows/modifiers"
)
func init() {
registerType(TypeSetContactName, func() flows.Action { return &SetContactNameAction{} })
}
// TypeSetContactName is the type for the set contact name action
const TypeSetContactName string = "set_contact_name"
// SetContactNameAction can be used to update the name of the contact. The name is a localizable
// template and white space is trimmed from the final value. An empty string clears the name.
// A [event:contact_name_changed] event will be created with the corresponding value.
//
// {
// "uuid": "8eebd020-1af5-431c-b943-aa670fc74da9",
// "type": "set_contact_name",
// "name": "Bob Smith"
// }
//
// @action set_contact_name
type SetContactNameAction struct {
baseAction
universalAction
Name string `json:"name" engine:"evaluated"`
}
// NewSetContactName creates a new set name action
func NewSetContactName(uuid flows.ActionUUID, name string) *SetContactNameAction {
return &SetContactNameAction{
baseAction: newBaseAction(TypeSetContactName, uuid),
Name: name,
}
}
// Execute runs this action
func (a *SetContactNameAction) Execute(run flows.Run, step flows.Step, logModifier flows.ModifierCallback, logEvent flows.EventCallback) error {
name, ok := run.EvaluateTemplate(a.Name, logEvent)
name = strings.TrimSpace(name)
if !ok {
return nil
}
a.applyModifier(run, modifiers.NewName(name), logModifier, logEvent)
return nil
}