-
Notifications
You must be signed in to change notification settings - Fork 11
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1 from Nexmo/markl-update-private-sms-tutorial
Markl update private sms tutorial
- Loading branch information
Showing
9 changed files
with
929 additions
and
339 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
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,73 @@ | ||
'use strict' | ||
|
||
const Nexmo = require('nexmo'); | ||
|
||
class SmsProxy { | ||
|
||
constructor() { | ||
this.nexmo = new Nexmo({ | ||
apiKey: process.env.NEXMO_API_KEY, | ||
apiSecret: process.env.NEXMO_API_SECRET | ||
}, { | ||
debug: true | ||
}); | ||
} | ||
|
||
createChat(userANumber, userBNumber) { | ||
this.chat = { | ||
userA: userANumber, | ||
userB: userBNumber | ||
}; | ||
|
||
this.sendSMS(); | ||
} | ||
|
||
sendSMS() { | ||
/* | ||
Send a message from userA to the virtual number | ||
*/ | ||
this.nexmo.message.sendSms(this.chat.userA, | ||
process.env.VIRTUAL_NUMBER, | ||
'Reply to this SMS to talk to UserA'); | ||
|
||
/* | ||
Send a message from userB to the virtual number | ||
*/ | ||
this.nexmo.message.sendSms(this.chat.userB, | ||
process.env.VIRTUAL_NUMBER, | ||
'Reply to this SMS to talk to UserB'); | ||
} | ||
|
||
|
||
getDestinationRealNumber(from) { | ||
let destinationRealNumber = null; | ||
|
||
// Use `from` numbers to work out who is sending to whom | ||
const fromUserA = (from === this.chat.userA); | ||
const fromUserB = (from === this.chat.userB); | ||
|
||
if (fromUserA || fromUserB) { | ||
destinationRealNumber = fromUserA ? this.chat.userB : this.chat.userA; | ||
} | ||
|
||
return destinationRealNumber; | ||
} | ||
|
||
proxySms(from, text) { | ||
// Determine which real number to send the SMS to | ||
const destinationRealNumber = this.getDestinationRealNumber(from); | ||
|
||
if (destinationRealNumber === null) { | ||
console.log(`No chat found for this number`); | ||
return; | ||
} | ||
|
||
// Send the SMS from the virtual number to the real number | ||
this.nexmo.message.sendSms(process.env.VIRTUAL_NUMBER, | ||
destinationRealNumber, | ||
text); | ||
} | ||
|
||
} | ||
|
||
module.exports = SmsProxy; |
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 |
---|---|---|
@@ -1,5 +1,3 @@ | ||
NEXMO_API_KEY= | ||
NEXMO_API_SECRET= | ||
NEXMO_DEBUG=true | ||
PROVISIONED_NUMBERS=[{"country":"2_CHAR_CODE","msisdn":"NUMBER"}] | ||
SMS_WEBHOOK_URL= | ||
VIRTUAL_NUMBER= |
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.