-
Notifications
You must be signed in to change notification settings - Fork 78
/
activity.go
executable file
·56 lines (43 loc) · 1.36 KB
/
activity.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
55
56
package twilio
import (
"github.com/TIBCOSoftware/flogo-lib/core/activity"
"github.com/TIBCOSoftware/flogo-lib/logger"
"github.com/sfreiberg/gotwilio"
)
// log is the default package logger
var log = logger.GetLogger("activity-tibco-twilio")
const (
ivAcctSID = "accountSID"
ivAuthToken = "authToken"
ivFrom = "from"
ivTo = "to"
ivMessage = "message"
)
// TwilioActivity is a Twilio Activity implementation
type TwilioActivity struct {
metadata *activity.Metadata
}
// NewActivity creates a new TwilioActivity
func NewActivity(metadata *activity.Metadata) activity.Activity {
return &TwilioActivity{metadata: metadata}
}
// Metadata implements activity.Activity.Metadata
func (a *TwilioActivity) Metadata() *activity.Metadata {
return a.metadata
}
// Eval implements activity.Activity.Eval
func (a *TwilioActivity) Eval(context activity.Context) (done bool, err error) {
accountSID := context.GetInput(ivAcctSID).(string)
authToken := context.GetInput(ivAuthToken).(string)
from := context.GetInput(ivFrom).(string)
to := context.GetInput(ivTo).(string)
message := context.GetInput(ivMessage).(string)
twilio := gotwilio.NewTwilioClient(accountSID, authToken)
resp, _, err := twilio.SendSMS(from, to, message, "", "")
if err != nil {
log.Error("Error sending SMS:", err)
return false, err
}
log.Debug("Response:", resp)
return true, nil
}