Skip to content

Commit

Permalink
Initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
reinefjord committed Jan 24, 2020
0 parents commit 0d55610
Show file tree
Hide file tree
Showing 13 changed files with 784 additions and 0 deletions.
42 changes: 42 additions & 0 deletions README.md
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 }}\""
```
27 changes: 27 additions & 0 deletions action.yml
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'
62 changes: 62 additions & 0 deletions index.js
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)
}
140 changes: 140 additions & 0 deletions node_modules/@actions/core/README.md

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

16 changes: 16 additions & 0 deletions node_modules/@actions/core/lib/command.d.ts

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

78 changes: 78 additions & 0 deletions node_modules/@actions/core/lib/command.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions node_modules/@actions/core/lib/command.js.map

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit 0d55610

Please sign in to comment.