forked from twilio-labs/actions-sms
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.js
More file actions
36 lines (29 loc) · 998 Bytes
/
main.js
File metadata and controls
36 lines (29 loc) · 998 Bytes
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
const core = require('@actions/core');
const twilio = require('twilio');
async function run() {
const fromPhoneNumber = core.getInput('fromPhoneNumber');
const toPhoneNumber = core.getInput('toPhoneNumber');
const message = core.getInput('message');
const accountSid =
core.getInput('TWILIO_ACCOUNT_SID') || process.env.TWILIO_ACCOUNT_SID;
const apiKey = core.getInput('TWILIO_API_KEY') || process.env.TWILIO_API_KEY;
const apiSecret =
core.getInput('TWILIO_API_SECRET') || process.env.TWILIO_API_SECRET;
core.debug('Sending SMS');
const client = twilio(apiKey, apiSecret, { accountSid: accountSid });
const { sid } = await client.messages.create({
from: fromPhoneNumber,
to: toPhoneNumber,
body: message,
});
core.debug('SMS sent!');
core.setOutput('messageSid', sid);
}
function execute() {
run().catch(err => {
core.error('Failed to send message', err.message)
core.setFailed(err.message);
});
}
module.exports = execute;
execute();