Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
feat(template): add new forward-call template (#24)
* feat(template): add new play template (#22)

* feat(template): add new forward-call template

* Reorder templates

* Fix test for forward-call
  • Loading branch information
stefanjudis authored and dkundel committed Jul 29, 2019
1 parent 44cbba1 commit b49d278
Show file tree
Hide file tree
Showing 6 changed files with 64 additions and 0 deletions.
2 changes: 2 additions & 0 deletions forward-call/.env
@@ -0,0 +1,2 @@
# The number you want to forward incoming calls to
MY_PHONE_NUMBER=+12223334444
15 changes: 15 additions & 0 deletions forward-call/README.md
@@ -0,0 +1,15 @@
# Forward Call

This Function in `forward-call.js` will return the TwiML required to forward an incoming call to a number that is set in the environment variables.

### Environment variables

This Function expects one environment variable to be set.

| Variable | Meaning |
| :---------------- | :------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| `MY_PHONE_NUMBER` | The number you want to forward incoming messages to [in E.164 format](https://support.twilio.com/hc/en-us/articles/223183008-Formatting-International-Phone-Numbers) |

### Parameters

This Function expects the incoming request to be a messaging webhook. The parameters that will be used are `From` and `Body`.
5 changes: 5 additions & 0 deletions forward-call/functions/forward-call.js
@@ -0,0 +1,5 @@
exports.handler = function(context, event, callback) {
let twiml = new Twilio.twiml.VoiceResponse()
twiml.dial(context.MY_PHONE_NUMBER);
callback(null, twiml);
};
3 changes: 3 additions & 0 deletions forward-call/package.json
@@ -0,0 +1,3 @@
{
"dependencies": {}
}
34 changes: 34 additions & 0 deletions forward-call/test/forward-call.test.js
@@ -0,0 +1,34 @@
const helpers = require('../../test/test-helper');
const forwardCall = require('../functions/forward-call').handler;
const Twilio = require('twilio');

const context = {
MY_PHONE_NUMBER: 'TwilioNumber'
};
const event = {};

beforeAll(() => {
helpers.setup(context);
});

afterAll(() => {
helpers.teardown();
});

test('returns a VoiceResponse', done => {
const callback = (err, result) => {
expect(result).toBeInstanceOf(Twilio.twiml.VoiceResponse);
done();
};

forwardCall(context, event, callback);
});

test('forwards the call to the number from the context', done => {
const callback = (err, result) => {
expect(result.toString()).toMatch('<Dial>' + context.MY_PHONE_NUMBER + '</Dial>');
done();
};

forwardCall(context, event, callback);
});
5 changes: 5 additions & 0 deletions templates.json
Expand Up @@ -15,6 +15,11 @@
"name": "Never gonna give you up",
"description": "Never gonna let you down. Plays a song to a phone call"
},
{
"id": "forward-call",
"name": "Forward Call",
"description": "Forwards an incoming call to another number"
},
{
"id": "forward-message",
"name": "Forward Message",
Expand Down

0 comments on commit b49d278

Please sign in to comment.