-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit 0d55610
Showing
13 changed files
with
784 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
# 46elks SMS GitHub Action | ||
|
||
Send an SMS with the [46elks](https://46elks.com/) API from GitHub | ||
Actions. | ||
|
||
|
||
## Inputs | ||
|
||
* `apiUsername` - **Required**: Your 46elks API username, available at | ||
the [46elks dashboard](https://46elks.com/account). | ||
* `apiPassword` - **Required**: Your 46elks API password, also available | ||
from the 46elks dashboard. | ||
* `from` - **Required**: The number or alpha numerical sender ID you | ||
would like to send the SMS from. Defaults to `"ElkAction"`. | ||
* `to` - **Required**: The number you would like to send the SMS to. | ||
Defaults to `+4670000000`, which does not actually send a message and | ||
is free, but will show up in your logs. | ||
* `message` - **Required**: The message to send with the SMS. | ||
|
||
## Outputs | ||
|
||
* `id` - The 46elks SMS ID of the SMS that was created. | ||
|
||
|
||
## Usage | ||
|
||
Store your API credentials in your repository's `Settings` -> `Secrets`, | ||
then you'll be able to use them as below. | ||
|
||
```yaml | ||
- name: Send SMS action step | ||
uses: 46elks/gh-actions-sms | ||
id: sms | ||
with: | ||
apiUsername: ${{ secrets.ELKS_API_USERNAME }} | ||
apiPassword: ${{ secrets.ELKS_API_PASSWORD }} | ||
from: 'ElkAction' | ||
to: '+4670000000' | ||
message: 'An elk says that something happened!' | ||
- name: Get the SMS ID | ||
run: "echo \"SMS ID: ${{ steps.sms.outputs.id }}\"" | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
name: '46elks SMS message' | ||
description: 'Send an SMS with the 46elks API' | ||
inputs: | ||
apiUsername: | ||
description: 'Your 46elks API username.' | ||
required: true | ||
apiPassword: | ||
description: 'Your 46elks API password.' | ||
required: true | ||
to: | ||
description: 'The phone number to send an SMS to' | ||
required: true | ||
default: '+46700000000' | ||
from: | ||
description: 'The phone number or text sender id to send the SMS from' | ||
required: true | ||
default: 'ElkAction' | ||
message: | ||
description: 'The message to send' | ||
required: true | ||
default: 'Elky greetings from GitHub actions!' | ||
outputs: | ||
id: | ||
description: 'The 46elks SMS ID of the created message' | ||
runs: | ||
using: 'node12' | ||
main: 'index.js' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,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) | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Oops, something went wrong.