diff --git a/common/models/subscription.js b/common/models/subscription.js index 3d6f519..2687b02 100644 --- a/common/models/subscription.js +++ b/common/models/subscription.js @@ -773,19 +773,22 @@ module.exports = function (Subscription) { Reference: '5eb9e53ac8de837a99fd214a', OutgoingMessageID: '789091964', MessageNumber: '59255257', - hash: '1111' + notifyBCSwiftKey: '1111' } */ let smsConfig = Subscription.app.get('sms') - if (smsConfig.swift && smsConfig.swift.notifyBCSwiftKey) { - if ( - smsConfig.swift.notifyBCSwiftKey !== - options.httpContext.req.body.notifyBCSwiftKey - ) { - let error = new Error('Forbidden') - error.status = 403 - throw error - } + if (!smsConfig || !smsConfig.swift || !smsConfig.swift.notifyBCSwiftKey) { + let error = new Error('Forbidden') + error.status = 403 + throw error + } + if ( + smsConfig.swift.notifyBCSwiftKey !== + options.httpContext.req.body.notifyBCSwiftKey + ) { + let error = new Error('Forbidden') + error.status = 403 + throw error } let whereClause = { state: 'confirmed', diff --git a/docs/_docs/config-sms.md b/docs/_docs/config-sms.md index 7a34118..8355a9e 100644 --- a/docs/_docs/config-sms.md +++ b/docs/_docs/config-sms.md @@ -4,12 +4,12 @@ title: SMS permalink: /docs/config-sms/ --- -*NotifyBC* depends on underlying SMS service providers to deliver SMS messages. The supported service providers are +_NotifyBC_ depends on underlying SMS service providers to deliver SMS messages. The supported service providers are - * [Twilio](https://twilio.com/) (default) - * [Swift](https://www.swiftsmsgateway.com) +- [Twilio](https://twilio.com/) (default) +- [Swift](https://www.swiftsmsgateway.com) -Only one service provider can be chosen per installation. To change service provider, add following *smsServiceProvider* config object to file */server/config.local.js* +Only one service provider can be chosen per installation. To change service provider, add following _smsServiceProvider_ config object to file _/server/config.local.js_ ```js module.exports = { @@ -17,10 +17,12 @@ module.exports = { smsServiceProvider: 'swift' } ``` + The rest configs are service provider specific. You should have an account with the chosen service provider before proceeding. ## Twilio -Add *sms.twilio* config object to file */server/config.local.js* + +Add _sms.twilio_ config object to file _/server/config.local.js_ ```js module.exports = { @@ -28,24 +30,56 @@ module.exports = { twilio: { accountSid: '', authToken: '', - fromNumber: '' - } - } + fromNumber: '', + }, + }, } ``` -Obtain *\*, *\* and *\* from your Twilio account. + +Obtain _\_, _\_ and _\_ from your Twilio account. ## Swift -Add *sms.swift* config object to file */server/config.local.js* + +Add _sms.swift_ config object to file _/server/config.local.js_ ```js module.exports = { sms: { swift: { - accountKey: '' - } - } + accountKey: '', + }, + }, } ``` -Obtain *\* from your Swift account. +Obtain _\_ from your Swift account. + +### Unsubscription by replying a keyword + +With Swift short code, sms user can unsubscribe by replying to a sms message with a keyword. The keyword must be pre-registered with Swift. + +To enable this feature, + +1. Generate a random string, hereafter referred to as *\* +2. Add it to _sms.swift.notifyBCSwiftKey_ in file _/server/config.local.js_ + + ```js + module.exports = { + sms: { + swift: { + ... + notifyBCSwiftKey: '', + }, + }, + } + ``` +3. Go to Swift web admin console, click *Number Management* tab +4. Click *Launch* button next to *Manage Short Code Keywords* +5. Click *Features* button next to the registered keyword(s). A keyword may have multiple entries. In such case do this for each entry. +6. Click *Redirect To Webpage* tab in the popup window +7. Enter following information in the tab + * set *URL* to *\/api/subscriptions/swift*, where *\* is NotifyBC HTTP host name and should be the same as [HTTP Host](../config-httpHost/) config + * set *Method* to *POST* + * set *Custom Parameter 1 Name* to *notifyBCSwiftKey* + * set *Custom Parameter 1 Value* to *\* +8. Click *Save Changes* button and then *Done* \ No newline at end of file