forked from wso2/choreo-samples
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsample.bal
65 lines (57 loc) · 2.23 KB
/
sample.bal
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
57
58
59
60
61
62
63
64
65
import ballerina/http;
import ballerina/log;
import ballerinax/trigger.github;
import ballerinax/twilio;
// Github configuration parameters
configurable github:ListenerConfig gitHubListenerConfig = ?;
configurable string issueAssigneeGithubUsername = ?;
// Twilio configuration parameters
configurable string TwilioAccountSID = ?;
configurable string TwilioAuthToken = ?;
configurable string fromNumber = ?;
configurable string toNumber = ?;
// Keys related to the issue assigned
final string[] & readonly issueKeys = ["html_url", "title"];
listener http:Listener httpListener = new(8090);
listener github:Listener gitHubListener = new (gitHubListenerConfig, httpListener);
@display { label: "GitHub Issue Assigned to Twilio SMS" }
service github:IssuesService on gitHubListener {
remote function onAssigned(github:IssuesEvent payload) returns error? {
github:Issue issueInfo = payload.issue;
if issueInfo.assignee?.login == issueAssigneeGithubUsername {
string message = "Github new issue assigned! \n";
foreach string issueKey in issueKeys {
if (issueInfo.hasKey(issueKey)) {
message += string `issueKey : ${issueInfo.get(issueKey).toString()}${"\n"}`;
}
}
twilio:Client twilioClient = check new ({
twilioAuth: {
accountSId: TwilioAccountSID,
authToken: TwilioAuthToken
}
});
_ = check twilioClient->sendSms(fromNumber, toNumber, message);
log:printInfo("SMS for new issue assigned sent successfully!");
}
}
remote function onOpened(github:IssuesEvent payload ) returns error? {
return;
}
remote function onClosed(github:IssuesEvent payload ) returns error? {
return;
}
remote function onReopened(github:IssuesEvent payload ) returns error? {
return;
}
remote function onUnassigned(github:IssuesEvent payload ) returns error? {
return;
}
remote function onLabeled(github:IssuesEvent payload ) returns error? {
return;
}
remote function onUnlabeled(github:IssuesEvent payload ) returns error? {
return;
}
}
service /ignore on httpListener {}