-
Notifications
You must be signed in to change notification settings - Fork 1
/
index.js
62 lines (52 loc) · 1.39 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
50
51
52
53
54
55
56
57
58
59
60
61
62
const core = require('@actions/core');
const https = require('https')
const querystring = require('querystring')
function sendSMS(username, password, from, to, message) {
const key = Buffer.from(username + ':' + password).toString('base64')
const postFields = {
from: from,
to: to,
message: message
}
const postData = querystring.stringify(postFields)
const options = {
hostname: 'api.46elks.com',
path: '/a1/SMS',
method: 'POST',
headers: {
'Content-Type': 'application/x-www-form-urlencoded',
'Content-Length': postData.length,
'Authorization': 'Basic ' + key
}
}
const req = https.request(options, (res) => {
let data = ''
res.on('data', (d) => {
data += d
})
res.on('end', () => {
if (res.statusCode == 200) {
let id = JSON.parse(data).id
core.setOutput('id', id)
} else {
core.setFailed(`Status code: ${res.statusCode}`)
}
console.log(data)
})
})
req.on('error', (error) => {
core.setFailed(error)
})
req.write(postData)
req.end()
}
try {
const apiUsername = core.getInput('apiUsername')
const apiPassword = core.getInput('apiPassword')
const to = core.getInput('to')
const from = core.getInput('from')
const message = core.getInput('message')
sendSMS(apiUsername, apiPassword, from, to, message)
} catch (error) {
core.setFailed(error.message)
}