Skip to content

Commit

Permalink
Webhook signature jwt (#87)
Browse files Browse the repository at this point in the history
* Add implementation of the webhook signature JWT.
* Update the linter.
* Fix all lint errors and some lint warnings. 
* Add GH Actions.
  • Loading branch information
dysosmus authored Oct 5, 2021
1 parent 5119af8 commit 8b2295b
Show file tree
Hide file tree
Showing 40 changed files with 3,432 additions and 371 deletions.
16 changes: 6 additions & 10 deletions .eslintrc
Original file line number Diff line number Diff line change
@@ -1,20 +1,17 @@
{
"ecmaFeatures": {
"modules": true
},

"extends": "eslint:recommended",
"env": {
"node": true
"node": true,
"es6": true
},

"rules": {
"array-bracket-spacing": [2, "never"],
"brace-style": [2, "1tbs", { "allowSingleLine": true }],
"camelcase": 0,
"comma-spacing": [2, { "before": false, "after": true }],
"comma-style": [2, "last"],
"comma-dangle": [2, "never"],
"complexity": [1, 8],
"complexity": [1, 10],
"computed-property-spacing": [2, "never"],
"consistent-return": 1,
"curly": [2, "all"],
Expand Down Expand Up @@ -96,7 +93,7 @@
"no-undef": 2,
"no-undef-init": 2,
"no-undefined": 2,
"no-underscore-dangle": 2,
"no-underscore-dangle": [2, {"allow": ["_links", "_extend"]}],
"no-unexpected-multiline": 2,
"no-unneeded-ternary": 2,
"no-unreachable": 2,
Expand All @@ -121,15 +118,14 @@
"before": false,
"after": true
}],
"space-after-keywords": [2, "always"],
"keyword-spacing": 2,
"space-before-blocks": [2, "always"],
"space-before-function-paren": [2, {
"anonymous": "always",
"named": "never"
}],
"space-in-parens": [2, "never"],
"space-infix-ops": 2,
"space-return-throw-case": 2,
"space-unary-ops": [2, {
"words": true,
"nonwords": false
Expand Down
36 changes: 36 additions & 0 deletions .github/test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
name: test
on:
push:
branches:
- '*'
- '!master'
workflow_dispatch: {}

jobs:
lint:
runs-on: ubuntu-latest
name: NodeJS ${{ matrix.node }} lint
steps:
- uses: actions/checkout@v2
- name: Setup nodejs
uses: actions/setup-node@v2
with:
node-version: '18'
- run: npm install
- run: npm run dtslint
test:
runs-on: ubuntu-latest
strategy:
matrix:
node: [ '10','11', '12', '13', '14', '15', '16', '17', '18']
name: NodeJS ${{ matrix.node }} test
env:
MB_ACCESSKEY: test_iQpAp0KCs5GCsMpDhIx2leuNB
steps:
- uses: actions/checkout@v2
- name: Setup nodejs
uses: actions/setup-node@v2
with:
node-version: ${{ matrix.node }}
- run: npm install
- run: npm run test
12 changes: 0 additions & 12 deletions .travis.yml

This file was deleted.

2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ Let's go ahead and initialize the library first. Don't forget to replace `<YOUR_
CommonJS require syntax:

```javascript
var messagebird = require('messagebird')('<YOUR_ACCESS_KEY>');
const messagebird = require('messagebird')('<YOUR_ACCESS_KEY>');
```

Typescript with ES6 import (or .mjs with Node >= v13):
Expand Down
2 changes: 1 addition & 1 deletion examples/balance.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@

var messagebird = require('messagebird')('<YOUR_ACCESS_KEY>');
const messagebird = require('messagebird')('<YOUR_ACCESS_KEY>');

messagebird.balance.read(function (err, response) {
if (err) {
Expand Down
28 changes: 14 additions & 14 deletions examples/calls.js
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
var messagebird = require('messagebird')('<YOUR_ACCESS_KEY>');
const messagebird = require('messagebird')('<YOUR_ACCESS_KEY>');

// create a call
var params = {
source: "<SOURCE_PHONE_NUMBER>",
destination: "<DESTINATION_PHONE_NUMBER>",
source: '<SOURCE_PHONE_NUMBER>',
destination: '<DESTINATION_PHONE_NUMBER>',
callFlow: {
title: "Say message",
title: 'Say message',
steps: [
{
action: "say",
action: 'say',
options: {
payload: "This is a journey into sound. Good bye!",
voice: "male",
language: "en-US"
payload: 'This is a journey into sound. Good bye!',
voice: 'male',
language: 'en-US'
}
}
]
Expand All @@ -21,31 +21,31 @@ var params = {

messagebird.calls.create(params, function (err, response) {
if (err) {
return console.log(err);
return console.log(err);
}
console.log(response);
});

// list calls
messagebird.calls.list(function (err, response) {
if (err) {
return console.log(err);
return console.log(err);
}
console.log(response);
});

// read a call
messagebird.calls.read('<CALL_ID>' ,function (err, response) {
messagebird.calls.read('<CALL_ID>', function (err, response) {
if (err) {
return console.log(err);
return console.log(err);
}
console.log(response);
});

// delete a call
messagebird.calls.delete('<CALL_ID>' ,function (err, response) {
messagebird.calls.delete('<CALL_ID>', function (err, response) {
if (err) {
return console.log(err);
return console.log(err);
}
console.log(response);
});
6 changes: 3 additions & 3 deletions examples/conversations.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@

var messagebird = require('messagebird')('<YOUR_ACCESS_KEY>');
const messagebird = require('messagebird')('<YOUR_ACCESS_KEY>');

// start a conversation
messagebird.conversations.start({
'to': '31612345678',
'channelId': '619747f69cf940a98fb443140ce9aed2' ,
'channelId': '619747f69cf940a98fb443140ce9aed2',
'type': 'text',
'content': { 'text': 'Hello!' }
}, function (err, response) {
Expand Down Expand Up @@ -102,7 +102,7 @@ messagebird.conversations.webhooks.read('451e6b72799e4415b2aab425f582f65e', func

// update webhook
messagebird.conversations.webhooks.update('451e6b72799e4415b2aab425f582f65e', {
'status': 'disabled',
'status': 'disabled'
}, function (err, response) {
if (err) {
return console.log(err);
Expand Down
2 changes: 1 addition & 1 deletion examples/hlr_create.js → examples/hlr-create.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@

var messagebird = require('messagebird')('<YOUR_ACCESS_KEY>');
const messagebird = require('messagebird')('<YOUR_ACCESS_KEY>');

messagebird.hlr.create('31612345678', 'YourBrand', function (err, response) {
if (err) {
Expand Down
2 changes: 1 addition & 1 deletion examples/hlr_read.js → examples/hlr-read.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@

var messagebird = require('messagebird')('<YOUR_ACCESS_KEY>');
const messagebird = require('messagebird')('<YOUR_ACCESS_KEY>');

messagebird.hlr.read('<HLR_ID>', function (err, response) {
if (err) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@

var messagebird = require('messagebird')('<YOUR_ACCESS_KEY>');
const messagebird = require('messagebird')('<YOUR_ACCESS_KEY>');

messagebird.lookup.hlr.create('31612345678', function (err, response) {
if (err) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@

var messagebird = require('messagebird')('<YOUR_ACCESS_KEY>');
const messagebird = require('messagebird')('<YOUR_ACCESS_KEY>');

messagebird.lookup.hlr.read('31612345678', function (err, response) {
if (err) {
Expand Down
2 changes: 1 addition & 1 deletion examples/lookup_read.js → examples/lookup-read.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@

var messagebird = require('messagebird')('<YOUR_ACCESS_KEY>');
const messagebird = require('messagebird')('<YOUR_ACCESS_KEY>');

messagebird.lookup.read('31612345678', function (err, response) {
if (err) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@

var messagebird = require('messagebird')('<YOUR_ACCESS_KEY>');
const messagebird = require('messagebird')('<YOUR_ACCESS_KEY>');

var params = {
'originator': 'YourBrand',
Expand Down
16 changes: 16 additions & 0 deletions examples/messages-list.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@

const messagebird = require('messagebird')('<YOUR_ACCESS_KEY>');

messagebird.messages.list(function (err, response) {
if (err) {
return console.log(err);
}
console.log(response);
});

messagebird.messages.list({ status: 'scheduled' }, function (err, response) {
if (err) {
return console.log(err);
}
console.log(response);
});
2 changes: 1 addition & 1 deletion examples/messages_read.js → examples/messages-read.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@

var messagebird = require('messagebird')('<YOUR_ACCESS_KEY>');
const messagebird = require('messagebird')('<YOUR_ACCESS_KEY>');

messagebird.messages.read('<MESSAGE_ID>', function (err, response) {
if (err) {
Expand Down
16 changes: 0 additions & 16 deletions examples/messages_list.js

This file was deleted.

12 changes: 0 additions & 12 deletions examples/node_middleware.js

This file was deleted.

2 changes: 1 addition & 1 deletion examples/recordings.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
var messagebird = require('messagebird')('<YOUR_ACCESS_KEY>');
const messagebird = require('messagebird')('<YOUR_ACCESS_KEY>');

// list recordings
messagebird.recordings.list('<CALL_ID>', '<LEG_ID>', '<LIMIT>', '<OFFSET>', function (err, response) {
Expand Down
2 changes: 1 addition & 1 deletion examples/transcription.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@

var messagebird = require('messagebird')('<YOUR_ACCESS_KEY>');
const messagebird = require('messagebird')('<YOUR_ACCESS_KEY>');

messagebird.transcriptions.create('<CALL_ID>', '<LEG_ID>', '<RECORDING_ID>', '<LANGUAGE>', function (err, data) {
if (err) {
Expand Down
29 changes: 17 additions & 12 deletions examples/verify_create_email.js → examples/verify-create-email.js
Original file line number Diff line number Diff line change
@@ -1,37 +1,42 @@

var messagebird = require('messagebird')('<YOUR_ACCESS_KEY>');
const messagebird = require('messagebird')('<YOUR_ACCESS_KEY>');

var from = "<FROM_EMAIL>";//email from which users will receive the verification token
var to = "<TO_EMAIL>";//email to which the verification code will be sent to
var additionalParams = {
// email from which users will receive the verification token
const from = '<FROM_EMAIL>';

// email to which the verification code will be sent to
const to = '<TO_EMAIL>';
const additionalParams = {
subject: 'Your verification code',
template: 'Your security token: %token',
timeout: 300
}
};

//Creating a token with email
// Creating a token with email
messagebird.verify.createWithEmail(from, to, additionalParams, function (err, response) {
if (err) {
return console.log(err);
}
console.log(response);
});

//Validating a token
var verifyId = '<VERIFY_ID>';
var token = '<TOKEN>';
// Validating a token
const verifyId = '<VERIFY_ID>';
const token = '<TOKEN>';

messagebird.verify.verify(verifyId, token, function (err, response) {
if (err) {
return console.log(err);
}
console.log(response);
});

//Retrieving a email message
var emailMessageId = '<MESSAGE_ID>';
// Retrieving a email message
const emailMessageId = '<MESSAGE_ID>';

messagebird.verify.getVerifyEmailMessage(emailMessageId, function (err, response) {
if (err) {
return console.log(err);
}
console.log(response);
});
});
2 changes: 1 addition & 1 deletion examples/verify_create.js → examples/verify-create.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@

var messagebird = require('messagebird')('<YOUR_ACCESS_KEY>');
const messagebird = require('messagebird')('<YOUR_ACCESS_KEY>');

messagebird.verify.create('31612345678', function (err, response) {
if (err) {
Expand Down
2 changes: 1 addition & 1 deletion examples/verify_delete.js → examples/verify-delete.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@

var messagebird = require('messagebird')('<YOUR_ACCESS_KEY>');
const messagebird = require('messagebird')('<YOUR_ACCESS_KEY>');

messagebird.verify.delete('<VERIFY_ID>', function (err, response) {
if (err) {
Expand Down
2 changes: 1 addition & 1 deletion examples/verify_read.js → examples/verify-read.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@

var messagebird = require('messagebird')('<YOUR_ACCESS_KEY>');
const messagebird = require('messagebird')('<YOUR_ACCESS_KEY>');

messagebird.verify.read('<VERIFY_ID>', function (err, response) {
if (err) {
Expand Down
2 changes: 1 addition & 1 deletion examples/verify_verify.js → examples/verify-verify.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@

var messagebird = require('messagebird')('<YOUR_ACCESS_KEY>');
const messagebird = require('messagebird')('<YOUR_ACCESS_KEY>');

messagebird.verify.verify('<VERIFY_ID>', '<TOKEN>', function (err, response) {
if (err) {
Expand Down
Loading

0 comments on commit 8b2295b

Please sign in to comment.