messagebird
Advanced tools
Comparing version
@@ -18,11 +18,17 @@ /** | ||
* @param {Integer} timeout | ||
* @param {Array} features | ||
* @return {Object} | ||
*/ | ||
module.exports = function (accessKey, timeout) { | ||
module.exports = function (accessKey, timeout, features) { | ||
var config = { | ||
accessKey: accessKey, | ||
timeout: timeout || 5000 | ||
}; | ||
var CONVERSATIONSENDPOINT = 'conversations.messagebird.com'; | ||
if (features && 'indexOf' in features && features.indexOf('ENABLE_CONVERSATIONSAPI_WHATSAPP_SANDBOX') !== -1) { | ||
CONVERSATIONSENDPOINT = "whatsapp-sandbox.messagebird.com"; | ||
} | ||
/** | ||
@@ -472,2 +478,5 @@ * httpRequest does the API call and process the response. | ||
conversations: { | ||
getEndpoint: function() { | ||
return CONVERSATIONSENDPOINT; | ||
}, | ||
@@ -486,3 +495,3 @@ /** | ||
httpRequest({ | ||
hostname: 'conversations.messagebird.com', | ||
hostname: CONVERSATIONSENDPOINT, | ||
method: 'POST', | ||
@@ -506,3 +515,3 @@ path: '/v1/send', | ||
httpRequest({ | ||
hostname: 'conversations.messagebird.com', | ||
hostname: CONVERSATIONSENDPOINT, | ||
method: 'POST', | ||
@@ -537,3 +546,3 @@ path: '/v1/conversations/start', | ||
httpRequest({ | ||
hostname: 'conversations.messagebird.com', | ||
hostname: CONVERSATIONSENDPOINT, | ||
method: 'GET', | ||
@@ -554,3 +563,3 @@ path: '/v1/conversations', | ||
httpRequest({ | ||
hostname: 'conversations.messagebird.com', | ||
hostname: CONVERSATIONSENDPOINT, | ||
method: 'GET', | ||
@@ -571,3 +580,3 @@ path: '/v1/conversations/' + id | ||
httpRequest({ | ||
hostname: 'conversations.messagebird.com', | ||
hostname: CONVERSATIONSENDPOINT, | ||
method: 'PATCH', | ||
@@ -590,3 +599,3 @@ path: '/v1/conversations/' + id, | ||
httpRequest({ | ||
hostname: 'conversations.messagebird.com', | ||
hostname: CONVERSATIONSENDPOINT, | ||
method: 'POST', | ||
@@ -620,3 +629,3 @@ path: '/v1/conversations/' + id + '/messages', | ||
httpRequest({ | ||
hostname: 'conversations.messagebird.com', | ||
hostname: CONVERSATIONSENDPOINT, | ||
method: 'GET', | ||
@@ -637,3 +646,3 @@ path: '/v1/conversations/' + id + '/messages', | ||
httpRequest({ | ||
hostname: 'conversations.messagebird.com', | ||
hostname: CONVERSATIONSENDPOINT, | ||
method: 'GET', | ||
@@ -654,3 +663,3 @@ path: '/v1/messages/' + id | ||
httpRequest({ | ||
hostname: 'conversations.messagebird.com', | ||
hostname: CONVERSATIONSENDPOINT, | ||
method: 'POST', | ||
@@ -671,3 +680,3 @@ path: '/v1/webhooks', | ||
httpRequest({ | ||
hostname: 'conversations.messagebird.com', | ||
hostname: CONVERSATIONSENDPOINT, | ||
method: 'GET', | ||
@@ -688,3 +697,3 @@ path: '/v1/webhooks/' + id, | ||
httpRequest({ | ||
hostname: 'conversations.messagebird.com', | ||
hostname: CONVERSATIONSENDPOINT, | ||
method: 'PATCH', | ||
@@ -717,3 +726,3 @@ path: '/v1/webhooks/' + id, | ||
httpRequest({ | ||
hostname: 'conversations.messagebird.com', | ||
hostname: CONVERSATIONSENDPOINT, | ||
method: 'GET', | ||
@@ -734,3 +743,3 @@ path: '/v1/webhooks', | ||
httpRequest({ | ||
hostname: 'conversations.messagebird.com', | ||
hostname: CONVERSATIONSENDPOINT, | ||
method: 'DELETE', | ||
@@ -737,0 +746,0 @@ path: '/v1/webhooks/' + id, |
var crypto = require('crypto'); | ||
var querystring = require('querystring'); | ||
var sortKeys = require('sort-object'); | ||
var Buffer = require('safe-buffer').Buffer; | ||
@@ -74,4 +73,9 @@ var scmp = require('scmp'); | ||
var normalizedDateTime = query.statusDatetime ? extend(query, { statusDatetime: query.statusDatetime.split(' ').join('+') }) : query; | ||
var sortedQuery = sortKeys(normalizedDateTime); | ||
// The query string needs to be sorted, because we generate a hash from the query | ||
var sortedQuery = {}; | ||
var keys = Object.keys(normalizedDateTime).sort(); | ||
for (var i = 0; i < keys.length; i++) { | ||
sortedQuery[keys[i]] = normalizedDateTime[keys[i]]; | ||
} | ||
return querystring.stringify(sortedQuery); | ||
@@ -78,0 +82,0 @@ } |
@@ -1470,9 +1470,5 @@ var fs = require('fs'); | ||
.get('/groups/group-id') | ||
.query(function (queryString) { | ||
// nock isn't too forgiving when it comes to non-standard queries. The | ||
// closest we can get to properly testing the query is comparing the | ||
// encoded JSON. The query is, in fact, `_method=PUT&ids[]=first-id&ids[]=second-id`. | ||
var expected = '{"_method":"PUT","ids":["first-id","second-id"]}'; | ||
return JSON.stringify(queryString) === expected; | ||
.query({ | ||
'_method': 'PUT', | ||
'ids[]': ["first-id","second-id"] | ||
}) | ||
@@ -1479,0 +1475,0 @@ .reply(204, ''); |
{ | ||
"name": "messagebird", | ||
"version": "2.4.1", | ||
"version": "3.0.0", | ||
"description": "A node.js wrapper for the MessageBird REST API", | ||
@@ -8,3 +8,3 @@ "main": "lib/messagebird.js", | ||
"engines": { | ||
"node": ">=0.8.0" | ||
"node": ">=10.0.0" | ||
}, | ||
@@ -36,9 +36,8 @@ "scripts": { | ||
"safe-buffer": "^5.1.2", | ||
"scmp": "^2.0.0", | ||
"sort-object": "^3.0.2" | ||
"scmp": "^2.0.0" | ||
}, | ||
"devDependencies": { | ||
"dtslint": "^0.4.2", | ||
"nock": "^8.0.0" | ||
"dtslint": "^0.9.3", | ||
"nock": "^11.3.2" | ||
} | ||
} |
@@ -86,2 +86,10 @@ MessageBird REST API for Node.js | ||
Conversations Whatsapp Sandbox | ||
------------- | ||
To use the whatsapp sandbox you need to add `"ENABLE_CONVERSATIONSAPI_WHATSAPP_SANDBOX"` to the list of features you want enabled. Don't forget to replace `<YOUR_ACCESS_KEY>` with your actual access key. | ||
```javascript | ||
var messagebird = require('messagebird')("<YOUR_ACCESS_KEY>", null, ["ENABLE_CONVERSATIONSAPI_WHATSAPP_SANDBOX"]); | ||
``` | ||
Documentation | ||
@@ -88,0 +96,0 @@ ------------- |
@@ -24,2 +24,3 @@ // TypeScript Version: 3.0 | ||
import { MmsObject, MmsParameter } from './mms'; | ||
import { Features } from 'feature'; | ||
@@ -260,4 +261,4 @@ type CallbackFn<T = unknown> = (err: Error | null, res: T | null) => void; | ||
declare function messagebird(accessKey: string, timeout?: number): MessageBird; | ||
declare function messagebird(accessKey: string, timeout?: number, features?: ReadonlyArray<Features>): MessageBird; | ||
export default messagebird; |
Sorry, the diff of this file is not supported yet
130545
0.41%2
-33.33%45
2.27%3928
0.41%104
8.33%- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed