-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Feat: Send sms using Twilio - add test for sms - update test phone number * - test * - remove empty line * - move sms-notify-recipient.test to contract
- Loading branch information
1 parent
f0abe69
commit 33f5785
Showing
8 changed files
with
60 additions
and
1 deletion.
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
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
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
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 @@ | ||
const smsStrategy = require('./sms-strategy'); | ||
|
||
module.exports = smsStrategy; |
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,24 @@ | ||
const Twilio = require('twilio'); | ||
const httpError = require('http-errors'); | ||
const smsConfig = require('smart-config').get('sms'); | ||
|
||
module.exports = (config = smsConfig) => { | ||
return { send: sendSms(config) }; | ||
}; | ||
|
||
function sendSms(config) { | ||
const client = new Twilio(config.accountSid, config.authToken); | ||
return async (message, recipientNumber) => { | ||
try { | ||
await client.messages.create({ | ||
body: message, | ||
to: recipientNumber, | ||
from: config.fromNumber | ||
}); | ||
return { status: 'OK' }; | ||
} catch (err) { | ||
throw httpError(err.status, err.message); | ||
} | ||
}; | ||
} | ||
|
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
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 @@ | ||
const smsClient = require('../../../helpers/sms'); | ||
|
||
module.exports = ({ body, recipientNumber }) => { | ||
return smsClient().send(body, recipientNumber); | ||
}; |
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,13 @@ | ||
require('../test-env'); | ||
|
||
const message = { | ||
body: 'testing message :). vanya.', | ||
recipientNumber: '+13346498383' | ||
}; | ||
|
||
describe('Send SMS via TWILIO', () => { | ||
it('should receive status code 201', () => request | ||
.post('/provider/sms/recipient') | ||
.send(message) | ||
.expect(201)); | ||
}); |