Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
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
1 parent
44cbba1
commit b49d278
Showing
6 changed files
with
64 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,2 @@ | ||
# The number you want to forward incoming calls to | ||
MY_PHONE_NUMBER=+12223334444 |
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,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`. |
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,5 @@ | ||
exports.handler = function(context, event, callback) { | ||
let twiml = new Twilio.twiml.VoiceResponse() | ||
twiml.dial(context.MY_PHONE_NUMBER); | ||
callback(null, twiml); | ||
}; |
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,3 @@ | ||
{ | ||
"dependencies": {} | ||
} |
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,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); | ||
}); |
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