-
Notifications
You must be signed in to change notification settings - Fork 1
/
index.js
49 lines (40 loc) · 1.43 KB
/
index.js
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
const core = require('@actions/core');
const fetch = require("node-fetch");
async function sendSms() {
// get sms info
const from = core.getInput('fromNumber');
const to = core.getInput('toNumber');
const message = core.getInput('message');
// get Exotel Account credentials
const accountSid = core.getInput('EXOTEL_ACCOUNT_SID') || process.env.EXOTEL_ACCOUNT_SID;
const apiKey = core.getInput('EXOTEL_API_KEY') || process.env.EXOTEL_API_KEY;
const apiToken = core.getInput('EXOTEL_API_TOKEN') || process.env.EXOTEL_API_TOKEN;
core.debug('Sending SMS');
let url = `https://${apiKey}:${apiToken}@api.exotel.com/v1/Accounts/${accountSid}/Sms/send.json`;
const body = `From=${from}&To=${to}&Body=${message}`;
// needs body in url as queryparam too :(
url = url + '?' + body
const options = {
method: 'POST',
body: body
};
const response = await fetch(url, options);
const json = await response.json(response);
if (json["RestException"] != null) {
throw json["RestException"];
};
core.debug('SMS sent!');
const smsMessage = json["SMSMessage"];
core.setOutput('smsMessageSid', smsMessage.Sid);
return smsMessage;
}
async function execute() {
try {
return await sendSms();
} catch ({ Message }) {
core.error('Failed to send message', Message);
core.setFailed(Message);
}
}
module.exports = execute;
execute();