Skip to content

Commit

Permalink
Fixes Twilio responses. (#44)
Browse files Browse the repository at this point in the history
Twilio expects an XML response to an incoming webhook, if it gets a content type like application/json it will show errors in the Twilio debugger. This commit ensures that the bot responds with a content type of text/xml and the an empty <Response></Response> element in the body.
  • Loading branch information
philnash authored and stojanovic committed Nov 7, 2016
1 parent 23a47f9 commit ec33d4a
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 5 deletions.
4 changes: 2 additions & 2 deletions lib/twilio/setup.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@ module.exports = function twilioSetup(api, bot, logError, optionalParser, option
};

return Promise.all(arr.map(message => parser(message)).map(twilioHandle))
.then(() => 'ok');
});
.then(() => '<Response></Response>');
}, { success: { contentType: 'text/xml' }});

api.addPostDeployStep('twilio', (options, lambdaDetails, utils) => {
return utils.Promise.resolve().then(() => {
Expand Down
7 changes: 4 additions & 3 deletions spec/twilio/twilio-setup-spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ describe('Twilio setup', () => {
}};
it('wires the POST request for twilio to the message processor', () => {
expect(api.post.calls.count()).toEqual(1);
expect(api.post).toHaveBeenCalledWith('/twilio', jasmine.any(Function));
expect(api.post).toHaveBeenCalledWith('/twilio', jasmine.any(Function), { success: { contentType: 'text/xml' }});
});
describe('processing a single message', () => {
var handler;
Expand All @@ -55,14 +55,15 @@ describe('Twilio setup', () => {
it('does not invoke the bot if the message cannot be parsed', (done) => {
parser.and.returnValue(false);
handler(messageTemplate).then((message) => {
expect(message).toBe('ok');
expect(message).toBe('<Response></Response>');
expect(bot).not.toHaveBeenCalled();
}).then(done, done.fail);
});
it('responds when the bot resolves', (done) => {
parser.and.returnValue({sender: '+333333333', text: 'SMS Twilio'});
botResolve('SMS Twilio');
handler(messageTemplate).then(() => {
handler(messageTemplate).then((message) => {
expect(message).toBe('<Response></Response>');
expect(responder).toHaveBeenCalledWith('randomTwilioAccountSID', 'randomTwilioAuthToken', new Buffer('+4444444444', 'base64').toString('ascii'), '+333333333', 'SMS Twilio');
}).then(done, done.fail);
});
Expand Down

0 comments on commit ec33d4a

Please sign in to comment.