messagebird
Advanced tools
Comparing version 2.2.0 to 2.3.0
@@ -10,2 +10,3 @@ /** | ||
var pkg = require('../package.json'); | ||
var extend = Object.assign ? Object.assign : require('util')._extend; | ||
@@ -28,12 +29,15 @@ /** | ||
/** | ||
* httpRequest does the API call | ||
* and process the response | ||
* httpRequest does the API call and process the response. | ||
* requestParams.hostname is optional and defaults back to | ||
* 'rest.messagebird.com'. | ||
* | ||
* @param {String} method | ||
* @param {String} path | ||
* @param {Object} params | ||
* @param {Object} requestParams | ||
* @param {String} requestParams.hostname | ||
* @param {String} requestParams.path | ||
* @param {String} requestParams.method | ||
* @param {Object} requestParams.params | ||
* @param {Function} callback | ||
* @return {Void} | ||
*/ | ||
function httpRequest(method, path, params, callback) { | ||
function httpRequest(requestParams, callback) { | ||
var options = {}; | ||
@@ -44,5 +48,5 @@ var complete = false; | ||
if (typeof params === 'function') { | ||
callback = params; | ||
params = null; | ||
if (typeof requestParams === 'function') { | ||
callback = requestParams; | ||
requestParams = null; | ||
} | ||
@@ -67,5 +71,5 @@ | ||
options = { | ||
hostname: 'rest.messagebird.com', | ||
path: path, | ||
method: method, | ||
hostname: requestParams.hostname || 'rest.messagebird.com', | ||
path: requestParams.path, | ||
method: requestParams.method, | ||
headers: { | ||
@@ -78,9 +82,12 @@ 'Authorization': 'AccessKey ' + config.accessKey, | ||
if (options.method === 'POST' || options.method === 'PUT' || options.method === 'PATCH') { | ||
body = JSON.stringify(params); | ||
body = JSON.stringify(requestParams.params); | ||
options.headers['Content-Type'] = 'application/json'; | ||
options.headers['Content-Length'] = Buffer.byteLength(body, 'utf8'); | ||
} else { | ||
options.path += params ? '?' + querystring.stringify(params) : ''; | ||
options.path += requestParams.params ? '?' + querystring.stringify(requestParams.params) : ''; | ||
} | ||
// you can override any headers you like | ||
options.headers = extend(options.headers || {}, requestParams.headers || {}) | ||
request = http.request(options); | ||
@@ -171,3 +178,3 @@ | ||
read: function (callback) { | ||
httpRequest('GET', '/balance', callback); | ||
httpRequest({ method: 'GET', path: '/balance' }, callback); | ||
} | ||
@@ -185,7 +192,7 @@ }, | ||
read: function (id, callback) { | ||
httpRequest('GET', '/hlr/' + id, callback); | ||
httpRequest({ method: 'GET', path: '/hlr/' + id }, callback); | ||
}, | ||
/** | ||
* Send HLR network query to a number | ||
* Send HLR network query to a number. Ref parameter is optional. | ||
* | ||
@@ -203,3 +210,3 @@ * @param {Number} msisdn | ||
httpRequest('POST', '/hlr', params, callback || ref); | ||
httpRequest({ method: 'POST', path: '/hlr', params: params }, callback || ref); | ||
} | ||
@@ -218,3 +225,3 @@ }, | ||
read: function (id, callback) { | ||
httpRequest('GET', '/messages/' + id, callback); | ||
httpRequest({ method: 'GET', path: '/messages/' + id}, callback); | ||
}, | ||
@@ -234,6 +241,69 @@ | ||
httpRequest('POST', '/messages', params, callback); | ||
httpRequest({ method: 'POST', path: '/messages', params: params }, callback); | ||
} | ||
}, | ||
mms: { | ||
/** | ||
* Get a mms message | ||
* | ||
* @param {String} id | ||
* @param {Function} callback | ||
* @return {void} | ||
*/ | ||
read: function (id, callback) { | ||
httpRequest({ method: 'GET', path: '/mms/' + id }, callback); | ||
}, | ||
/** | ||
* Send a mms message | ||
* | ||
* @param {Object} params | ||
* @param {Function} callback | ||
* @return {void} | ||
*/ | ||
create: function (params, callback) { | ||
if (params.recipients instanceof Array) { | ||
params.recipients = params.recipients.join(','); | ||
} | ||
httpRequest({ method: 'POST', path: '/mms', params: params }, callback); | ||
}, | ||
/** | ||
* Lists mms messages. Pagination is optional. If a limit is set, an | ||
* offset is also required. | ||
* | ||
* @param {Number} limit | ||
* @param {Number} offset | ||
* @param {Function} callback | ||
* @return void | ||
*/ | ||
list: function (limit, offset, callback) { | ||
var params = null; | ||
if (typeof callback === 'function') { | ||
params = { | ||
limit: limit, | ||
offset: offset | ||
}; | ||
} else { | ||
callback = limit; | ||
} | ||
httpRequest({ method: 'GET', path: '/mms', params: params }, callback); | ||
}, | ||
/** | ||
* Delete a mms message | ||
* | ||
* @param {String} id | ||
* @param {Function} callback | ||
* @return {void} | ||
*/ | ||
delete: function (id, callback) { | ||
httpRequest({ method: 'DELETE', path: '/mms/' + id }, callback); | ||
} | ||
}, | ||
voice_messages: { | ||
@@ -249,3 +319,3 @@ | ||
read: function (id, callback) { | ||
httpRequest('GET', '/voicemessages/' + id, callback); | ||
httpRequest({ method: 'GET', path: '/voicemessages/' + id }, callback); | ||
}, | ||
@@ -276,3 +346,3 @@ | ||
httpRequest('POST', '/voicemessages', params, callback); | ||
httpRequest({ method: 'POST', path: '/voicemessages', params: params }, callback); | ||
} | ||
@@ -291,3 +361,3 @@ }, | ||
read: function (id, callback) { | ||
httpRequest('GET', '/verify/' + id, callback); | ||
httpRequest({ method: 'GET', path: '/verify/' + id }, callback); | ||
}, | ||
@@ -314,3 +384,3 @@ | ||
params.recipient = recipient; | ||
httpRequest('POST', '/verify', params, callback); | ||
httpRequest({ method: 'POST', path: '/verify', params: params }, callback); | ||
}, | ||
@@ -326,3 +396,3 @@ | ||
delete: function (id, callback) { | ||
httpRequest('DELETE', '/verify/' + id, callback); | ||
httpRequest({ method: 'DELETE', path: '/verify/' + id }, callback); | ||
}, | ||
@@ -343,3 +413,3 @@ | ||
httpRequest('GET', '/verify/' + id, params, callback); | ||
httpRequest({ method: 'GET', path: '/verify/' + id, params: params }, callback); | ||
} | ||
@@ -369,3 +439,3 @@ }, | ||
httpRequest('GET', '/lookup/' + phoneNumber, params, callback); | ||
httpRequest({ method: 'GET', path: '/lookup/' + phoneNumber, params: params }, callback); | ||
}, | ||
@@ -395,3 +465,3 @@ | ||
httpRequest('GET', '/lookup/' + phoneNumber + '/hlr', params, callback); | ||
httpRequest({ method: 'GET', path: '/lookup/' + phoneNumber + '/hlr', params: params }, callback); | ||
}, | ||
@@ -413,3 +483,3 @@ | ||
httpRequest('POST', '/lookup/' + phoneNumber + '/hlr', params, callback); | ||
httpRequest({ method: 'POST', path: '/lookup/' + phoneNumber + '/hlr', params: params }, callback); | ||
} | ||
@@ -419,2 +489,260 @@ } | ||
conversations: { | ||
/** | ||
* Sends a new message to a channel-specific user identifier (e.g. phone | ||
* number). If an active conversation already exists for the recipient, | ||
* this conversation will be resumed. If an active conversation does not | ||
* exist, a new one will be created. | ||
* | ||
* @param {Object} params | ||
* @param {Function} callback | ||
* @return void | ||
*/ | ||
send: function (params, callback) { | ||
httpRequest({ | ||
hostname: 'conversations.messagebird.com', | ||
method: 'POST', | ||
path: '/v1/conversations/send', | ||
params: params | ||
}, callback); | ||
}, | ||
/** | ||
* Starts a new conversation from a channel-specific user identifier, | ||
* such as a phone number, and sends a first message. If an active | ||
* conversation already exists for the recipient, this conversation will | ||
* be resumed. | ||
* | ||
* @param {Object} params | ||
* @param {Function} callback | ||
* @return void | ||
*/ | ||
start: function (params, callback) { | ||
httpRequest({ | ||
hostname: 'conversations.messagebird.com', | ||
method: 'POST', | ||
path: '/v1/conversations/start', | ||
params: params | ||
}, callback); | ||
}, | ||
/** | ||
* Retrieves all conversations for this account. By default, | ||
* conversations are sorted by their lastReceivedDatetime field so that | ||
* conversations with new messages appear first. | ||
* | ||
* @param {Number} limit | ||
* @param {Number} offset | ||
* @param {Function} callback | ||
* @return void | ||
*/ | ||
list: function (limit, offset, callback) { | ||
var params = null; | ||
if (typeof callback === 'function') { | ||
params = { | ||
limit: limit, | ||
offset: offset | ||
}; | ||
} else { | ||
callback = limit; | ||
} | ||
httpRequest({ | ||
hostname: 'conversations.messagebird.com', | ||
method: 'GET', | ||
path: '/v1/conversations', | ||
params: params | ||
}, callback); | ||
}, | ||
/** | ||
* Retrieves a single conversation. | ||
* | ||
* @param {String} id | ||
* @param {Function} callback | ||
* @return void | ||
*/ | ||
read: function (id, callback) { | ||
httpRequest({ | ||
hostname: 'conversations.messagebird.com', | ||
method: 'GET', | ||
path: '/v1/conversations/' + id | ||
}, callback); | ||
}, | ||
/** | ||
* Update Conversation Status. | ||
* | ||
* @param {String} id | ||
* @param {String} params | ||
* @param {Function} callback | ||
* @return void | ||
*/ | ||
update: function (id, params, callback) { | ||
httpRequest({ | ||
hostname: 'conversations.messagebird.com', | ||
method: 'PATCH', | ||
path: '/v1/conversations/' + id, | ||
params: params | ||
}, callback); | ||
}, | ||
/** | ||
* Adds a new message to an existing conversation and sends it to the | ||
* contact that you're in conversation with. | ||
* | ||
* @param {String} id | ||
* @param {Object} params | ||
* @param {Function} callback | ||
* @return void | ||
*/ | ||
reply: function (id, params, callback) { | ||
httpRequest({ | ||
hostname: 'conversations.messagebird.com', | ||
method: 'POST', | ||
path: '/v1/conversations/' + id + '/messages', | ||
params: params | ||
}, callback); | ||
}, | ||
/** | ||
* Lists the messages for a contact. | ||
* | ||
* @param {String} contactId | ||
* @param {Number} limit | ||
* @param {Number} offset | ||
* @param {Function} callback | ||
* @return void | ||
*/ | ||
listMessages: function (id, limit, offset, callback) { | ||
var params = null; | ||
if (typeof callback === 'function') { | ||
params = { | ||
limit: limit, | ||
offset: offset | ||
}; | ||
} else { | ||
callback = limit; | ||
} | ||
httpRequest({ | ||
hostname: 'conversations.messagebird.com', | ||
method: 'GET', | ||
path: '/v1/conversations/' + id + '/messages', | ||
params: params | ||
}, callback); | ||
}, | ||
/** | ||
* View a message | ||
* | ||
* @param {String} id | ||
* @param {Function} callback | ||
* @return {void} | ||
*/ | ||
readMessage: function (id, callback) { | ||
httpRequest({ | ||
hostname: 'conversations.messagebird.com', | ||
method: 'GET', | ||
path: '/v1/conversations/messages/' + id | ||
}, callback); | ||
}, | ||
webhooks: { | ||
/** | ||
* Creates a new webhook. | ||
* | ||
* @param {Object} params | ||
* @param {Function} callback | ||
* @return {void} | ||
*/ | ||
create: function (params, callback) { | ||
httpRequest({ | ||
hostname: 'conversations.messagebird.com', | ||
method: 'POST', | ||
path: '/v1/conversations/webhooks', | ||
params: params, | ||
}, callback); | ||
}, | ||
/** | ||
* Retrieves an existing webhook by id. | ||
* | ||
* @param {String} id | ||
* @param {Function} callback | ||
* @return {void} | ||
*/ | ||
read: function (id, callback) { | ||
httpRequest({ | ||
hostname: 'conversations.messagebird.com', | ||
method: 'GET', | ||
path: '/v1/conversations/webhooks/' + id, | ||
}, callback); | ||
}, | ||
/** | ||
* Updates a webhook. | ||
* | ||
* @param {String} id | ||
* @param {Object} params | ||
* @param {Function} callback | ||
* @return {void} | ||
*/ | ||
update: function (id, params, callback) { | ||
httpRequest({ | ||
hostname: 'conversations.messagebird.com', | ||
method: 'PATCH', | ||
path: '/v1/conversations/webhooks/' + id, | ||
params: params | ||
}, callback); | ||
}, | ||
/** | ||
* Retrieves a list of webhooks. | ||
* | ||
* @param {Number} limit | ||
* @param {Number} offset | ||
* @param {Function} callback | ||
* @return void | ||
*/ | ||
list: function (limit, offset, callback) { | ||
var params = null; | ||
if (typeof callback === 'function') { | ||
params = { | ||
limit: limit, | ||
offset: offset | ||
}; | ||
} else { | ||
callback = limit; | ||
} | ||
httpRequest({ | ||
hostname: 'conversations.messagebird.com', | ||
method: 'GET', | ||
path: '/v1/conversations/webhooks', | ||
params: params | ||
}, callback); | ||
}, | ||
/** | ||
* Deletes webhook | ||
* | ||
* @param {String} id | ||
* @param {Function} callback | ||
* @return {void} | ||
*/ | ||
delete: function (id, callback) { | ||
httpRequest({ | ||
hostname: 'conversations.messagebird.com', | ||
method: 'DELETE', | ||
path: '/v1/conversations/webhooks/' + id, | ||
}, callback); | ||
}, | ||
} | ||
}, | ||
contacts: { | ||
@@ -438,3 +766,3 @@ | ||
httpRequest('POST', '/contacts', params, callback); | ||
httpRequest({ method: 'POST', path: '/contacts', params: params }, callback); | ||
}, | ||
@@ -452,3 +780,3 @@ | ||
delete: function (id, callback) { | ||
httpRequest('DELETE', '/contacts/' + id, callback); | ||
httpRequest({ method: 'DELETE', path: '/contacts/' + id }, callback); | ||
}, | ||
@@ -477,3 +805,3 @@ | ||
httpRequest('GET', '/contacts', params, callback); | ||
httpRequest({ method: 'GET', path: '/contacts', params: params }, callback); | ||
}, | ||
@@ -489,3 +817,3 @@ | ||
read: function (id, callback) { | ||
httpRequest('GET', '/contacts/' + id, callback); | ||
httpRequest({ method: 'GET', path: '/contacts/' + id }, callback); | ||
}, | ||
@@ -503,3 +831,3 @@ | ||
update: function (id, params, callback) { | ||
httpRequest('PATCH', '/contacts/' + id, params, callback); | ||
httpRequest({ method: 'PATCH', path: '/contacts/' + id, params: params }, callback); | ||
}, | ||
@@ -528,3 +856,3 @@ | ||
httpRequest('GET', '/contacts/' + contactId + '/groups', params, callback); | ||
httpRequest({ method: 'GET', path: '/contacts/' + contactId + '/groups', params: params }, callback); | ||
}, | ||
@@ -553,3 +881,3 @@ | ||
httpRequest('GET', '/contacts/' + contactId + '/messages', params, callback); | ||
httpRequest({ method: 'GET', path: '/contacts/' + contactId + '/messages', params: params }, callback); | ||
} | ||
@@ -577,3 +905,3 @@ | ||
httpRequest('POST', '/groups', params, callback); | ||
httpRequest({ method: 'POST', path: '/groups', params: params }, callback); | ||
}, | ||
@@ -591,3 +919,3 @@ | ||
delete: function (id, callback) { | ||
httpRequest('DELETE', '/groups/' + id, callback); | ||
httpRequest({ method: 'DELETE', path: '/groups/' + id }, callback); | ||
}, | ||
@@ -616,3 +944,3 @@ | ||
httpRequest('GET', '/groups', params, callback); | ||
httpRequest({ method: 'GET', path: '/groups', params: params }, callback); | ||
}, | ||
@@ -628,3 +956,3 @@ | ||
read: function (id, callback) { | ||
httpRequest('GET', '/groups/' + id, callback); | ||
httpRequest({ method: 'GET', path: '/groups/' + id }, callback); | ||
}, | ||
@@ -649,3 +977,3 @@ | ||
httpRequest('PATCH', '/groups/' + id, params, callback); | ||
httpRequest({ method: 'PATCH', path: '/groups/' + id, params: params }, callback); | ||
}, | ||
@@ -671,3 +999,3 @@ | ||
httpRequest('GET', '/groups/' + groupId + '?' + query, null, callback); | ||
httpRequest({ method: 'GET', path: '/groups/' + groupId + '?' + query, params: null }, callback); | ||
}, | ||
@@ -682,3 +1010,3 @@ | ||
var params = []; | ||
params.push('_method=PUT'); | ||
@@ -688,3 +1016,3 @@ for (var i = 0; i < contactIds.length; i++) { | ||
} | ||
return params.join('&'); | ||
@@ -714,3 +1042,3 @@ }, | ||
httpRequest('GET', '/groups/' + groupId + '/contacts', params, callback); | ||
httpRequest({ method: 'GET', path: '/groups/' + groupId + '/contacts', params: params }, callback); | ||
}, | ||
@@ -727,3 +1055,3 @@ | ||
removeContact: function (groupId, contactId, callback) { | ||
httpRequest('DELETE', '/groups/' + groupId + '/contacts/' + contactId, callback); | ||
httpRequest({ method: 'DELETE', path: '/groups/' + groupId + '/contacts/' + contactId }, callback); | ||
} | ||
@@ -730,0 +1058,0 @@ |
649
lib/test.js
@@ -238,3 +238,2 @@ var fs = require('fs'); | ||
queue.push(function () { | ||
@@ -387,2 +386,650 @@ messagebird.voice_messages.create(cache.voiceMessage, function (err, data) { | ||
var params = { | ||
to: '+31612345678', | ||
from: '619747f69cf940a98fb443140ce9aed2', | ||
type: 'text', | ||
content: { | ||
text: 'Hello!' | ||
}, | ||
reportUrl: 'https://example.com/reports' | ||
}; | ||
nock('https://conversations.messagebird.com') | ||
.post('/v1/conversations/send', params) | ||
.reply(200, { | ||
message: { | ||
id: 'message-id', | ||
status: 'accepted' | ||
} | ||
}); | ||
messagebird.conversations.send(params, function (err, data) { | ||
doTest(err, 'conversations.send', [ | ||
['type', data instanceof Object], | ||
['.message', data.message instanceof Object], | ||
['.message.id', data && data.message.id === 'message-id'] | ||
]); | ||
}); | ||
}); | ||
queue.push(function () { | ||
nock('https://conversations.messagebird.com') | ||
.get('/v1/conversations') | ||
.query({ | ||
offset: 0, | ||
limit: 20 | ||
}) | ||
.reply(200, { | ||
'offset': 0, | ||
'limit': 20, | ||
'count': 2, | ||
'totalCount': 2, | ||
'items': [ | ||
{ | ||
'id': 'fbbdde79129f45e3a179458a91e2ead6', | ||
'contactId': '03dfc27855c3475b953d6200a1b7eaf7', | ||
'contact': { | ||
'id': '03dfc27855c3475b953d6200a1b7eaf7', | ||
'href': 'https://rest.messagebird.com/contacts/03dfc27855c3475b953d6200a1b7eaf7', | ||
'msisdn': 31612345678, | ||
'firstName': 'John', | ||
'lastName': 'Doe', | ||
'customDetails': { | ||
'custom1': null, | ||
'custom2': null, | ||
'custom3': null, | ||
'custom4': null | ||
}, | ||
'createdDatetime': '2018-08-01T09:45:52Z', | ||
'updatedDatetime': '2018-08-28T12:37:35Z' | ||
}, | ||
'channels': [ | ||
{ | ||
'id': '619747f69cf940a98fb443140ce9aed2', | ||
'name': 'My WhatsApp', | ||
'platformId': 'whatsapp', | ||
'status': 'active', | ||
'createdDatetime': '2018-08-28T11:56:57Z', | ||
'updatedDatetime': '2018-08-29T08:16:33Z' | ||
} | ||
], | ||
'status': 'active', | ||
'createdDatetime': '2018-08-29T08:52:54Z', | ||
'updatedDatetime': '2018-08-29T08:52:54Z', | ||
'lastReceivedDatetime': '2018-08-29T08:52:54Z', | ||
'lastUsedChannelId': '619747f69cf940a98fb443140ce9aed2', | ||
'messages': { | ||
'totalCount': 10, | ||
'href': 'https://conversations.messagebird.com/v1/conversations/fbbdde79129f45e3a179458a91e2ead6/messages' | ||
} | ||
}, | ||
{ | ||
'id': '2e15efafec384e1c82e9842075e87beb', | ||
'contactId': 'a621095fa44947a28b441cfdf85cb802', | ||
'contact': { | ||
'id': 'a621095fa44947a28b441cfdf85cb802', | ||
'href': 'https://rest.messagebird.com/1/contacts/a621095fa44947a28b441cfdf85cb802', | ||
'msisdn': 316123456789, | ||
'firstName': 'Jen', | ||
'lastName': 'Smith', | ||
'customDetails': { | ||
'custom1': null, | ||
'custom2': null, | ||
'custom3': null, | ||
'custom4': null | ||
}, | ||
'createdDatetime': '2018-06-03T20:06:03Z', | ||
'updatedDatetime': null | ||
}, | ||
'channels': [ | ||
{ | ||
'id': '853eeb5348e541a595da93b48c61a1ae', | ||
'name': 'SMS', | ||
'platformId': 'sms', | ||
'status': 'active', | ||
'createdDatetime': '2018-08-28T11:56:57Z', | ||
'updatedDatetime': '2018-08-29T08:16:33Z' | ||
}, | ||
{ | ||
'id': '619747f69cf940a98fb443140ce9aed2', | ||
'name': 'My WhatsApp', | ||
'platformId': 'whatsapp', | ||
'status': 'active', | ||
'createdDatetime': '2018-08-28T11:56:57Z', | ||
'updatedDatetime': '2018-08-29T08:16:33Z' | ||
} | ||
], | ||
'status': 'active', | ||
'createdDatetime': '2018-08-13T09:17:22Z', | ||
'updatedDatetime': '2018-08-29T07:35:48Z', | ||
'lastReceivedDatetime': '2018-08-29T07:35:48Z', | ||
'lastUsedChannelId': '853eeb5348e541a595da93b48c61a1ae', | ||
'messages': { | ||
'totalCount': 23, | ||
'href': 'https://conversations.messagebird.com/v1/conversations/2e15efafec384e1c82e9842075e87beb/messages' | ||
} | ||
} | ||
] | ||
}); | ||
messagebird.conversations.list(20, 0, function (err, data) { | ||
doTest(err, 'conversations.list', [ | ||
['.offset', data.offset === 0], | ||
['.limit', data.limit === 20], | ||
['.items[0].id', data.items[0].id === 'fbbdde79129f45e3a179458a91e2ead6'], | ||
['.items[1].contact.id', data.items[1].contact.id === 'a621095fa44947a28b441cfdf85cb802'] | ||
]); | ||
}); | ||
}); | ||
queue.push(function () { | ||
var params = { | ||
to: '+31612345678', | ||
channelId: 'channel-id', | ||
type: 'text', | ||
content: { text: 'Hello!' } | ||
}; | ||
nock('https://conversations.messagebird.com') | ||
.post('/v1/conversations/start', params) | ||
.reply(200, { | ||
id: 'conversation-id', | ||
contactId: 'contact-id', | ||
status: 'active', | ||
channels: [ | ||
{ | ||
id: 'channel-id-1', | ||
name: 'SMS', | ||
platformId: 'sms', | ||
status: 'active', | ||
createdDatetime: '2018-08-28T11:56:57Z', | ||
updatedDatetime: '2018-08-29T08:16:33Z' | ||
}, | ||
{ | ||
id: 'channel-id-2', | ||
name: 'My WhatsApp', | ||
platformId: 'whatsapp', | ||
status: 'active', | ||
createdDatetime: '2018-08-28T11:56:57Z', | ||
updatedDatetime: '2018-08-29T08:16:33Z' | ||
} | ||
] | ||
}); | ||
messagebird.conversations.start(params, function (err, data) { | ||
doTest(err, 'conversations.start', [ | ||
['type', data instanceof Object], | ||
['.id', data && data.id === 'conversation-id'], | ||
['.contactId', data && data.contactId === 'contact-id'], | ||
['channels.length', data && data.channels.length === 2], | ||
['channels[0].id', data && data.channels[0].id === 'channel-id-1'] | ||
]); | ||
}); | ||
}); | ||
queue.push(function () { | ||
nock('https://conversations.messagebird.com') | ||
.get('/v1/conversations/conversation-id') | ||
.reply(200, { | ||
id: 'conversation-id', | ||
contactId: 'contact-id', | ||
status: 'active', | ||
channels: [ | ||
{ | ||
id: 'channel-id-1', | ||
name: 'SMS', | ||
platformId: 'sms', | ||
status: 'active', | ||
createdDatetime: '2018-08-28T11:56:57Z', | ||
updatedDatetime: '2018-08-29T08:16:33Z' | ||
}, | ||
{ | ||
id: 'channel-id-2', | ||
name: 'My WhatsApp', | ||
platformId: 'whatsapp', | ||
status: 'active', | ||
createdDatetime: '2018-08-28T11:56:57Z', | ||
updatedDatetime: '2018-08-29T08:16:33Z' | ||
} | ||
] | ||
}); | ||
messagebird.conversations.read('conversation-id', function (err, data) { | ||
doTest(err, 'conversations.read', [ | ||
['type', data instanceof Object], | ||
['.id', data && data.id === 'conversation-id'], | ||
['.contactId', data && data.contactId === 'contact-id'], | ||
['channels.length', data && data.channels.length === 2], | ||
['channels[0].id', data && data.channels[0].id === 'channel-id-1'] | ||
]); | ||
}); | ||
}); | ||
queue.push(function () { | ||
var params = { | ||
status: 'archived' | ||
}; | ||
nock('https://conversations.messagebird.com') | ||
.patch('/v1/conversations/conversation-id', params) | ||
.reply(200, { | ||
id: 'conversation-id', | ||
contactId: 'contact-id', | ||
status: 'archived' | ||
}); | ||
messagebird.conversations.update('conversation-id', params, function (err, data) { | ||
doTest(err, 'conversations.update', [ | ||
['type', data instanceof Object], | ||
['.id', data && data.id === 'conversation-id'], | ||
['.status', data && data.status === 'archived'], | ||
['.contactId', data && data.contactId === 'contact-id'] | ||
]); | ||
}); | ||
}); | ||
queue.push(function () { | ||
var params = { | ||
type: 'text', | ||
content: { text: 'Hello!' } | ||
}; | ||
nock('https://conversations.messagebird.com') | ||
.post('/v1/conversations/conversation-id/messages', params) | ||
.reply(200, { | ||
id: 'message-id', | ||
conversationId: 'conversation-id', | ||
status: 'pending', | ||
channelId: 'a621095fa44947a28b441cfdf85cb802', | ||
status: 'pending', | ||
type: 'text', | ||
direction: 'sent', | ||
content: { | ||
text: 'This is a test message' | ||
} | ||
}); | ||
messagebird.conversations.reply('conversation-id', params, function (err, data) { | ||
doTest(err, 'conversations.reply', [ | ||
['type', data instanceof Object], | ||
['.id', data && data.id === 'message-id'], | ||
['.conversationId', data && data.conversationId === 'conversation-id'], | ||
['.status', data && data.status === 'pending'] | ||
]); | ||
}); | ||
}); | ||
queue.push(function () { | ||
nock('https://conversations.messagebird.com') | ||
.get('/v1/conversations/2e15efafec384e1c82e9842075e87beb/messages') | ||
.query({ | ||
offset: 0, | ||
limit: 20 | ||
}) | ||
.reply(200, { | ||
'count': 2, | ||
'items': [ | ||
{ | ||
'id': 'eb34fb1fc73f47a58ad644de0e2de254', | ||
'conversationId': '2e15efafec384e1c82e9842075e87beb', | ||
'channelId': '619747f69cf940a98fb443140ce9aed2', | ||
'status': 'received', | ||
'direction': 'received', | ||
'type': 'text', | ||
'content': { | ||
'text': 'This is a test WhatsApp message' | ||
}, | ||
'createdDatetime': '2018-08-29T08:07:15Z', | ||
'updatedDatetime': '2018-08-29T08:07:33Z' | ||
}, | ||
{ | ||
'id': '5f3437fdb8444583aea093a047ac014b', | ||
'conversationId': '2e15efafec384e1c82e9842075e87beb', | ||
'channelId': '853eeb5348e541a595da93b48c61a1ae', | ||
'status': 'delivered', | ||
'direction': 'sent', | ||
'type': 'text', | ||
'content': { | ||
'text': 'This is a test SMS message' | ||
}, | ||
'createdDatetime': '2018-08-28T15:52:41Z', | ||
'updatedDatetime': '2018-08-28T15:52:58Z' | ||
} | ||
], | ||
'limit': 20, | ||
'offset': 0, | ||
'totalCount': 24 | ||
}); | ||
messagebird.conversations.listMessages('2e15efafec384e1c82e9842075e87beb', 20, 0, function (err, data) { | ||
doTest(err, 'conversations.listMessages', [ | ||
['.offset', data.offset === 0], | ||
['.limit', data.limit === 20], | ||
['.items[0].id', data.items[0].id === 'eb34fb1fc73f47a58ad644de0e2de254'], | ||
['.items[1].content.text', data.items[1].content.text === 'This is a test SMS message'] | ||
]); | ||
}); | ||
}); | ||
queue.push(function () { | ||
nock('https://conversations.messagebird.com') | ||
.get('/v1/conversations/messages/message-id') | ||
.reply(200, { | ||
id: 'message-id', | ||
conversationId: 'conversation-id', | ||
channelId: 'channgel-id', | ||
status: 'delivered', | ||
direction: 'sent', | ||
type: 'text' | ||
}); | ||
messagebird.conversations.readMessage('message-id', function (err, data) { | ||
doTest(err, 'conversations.readMessage', [ | ||
['type', data instanceof Object], | ||
['.id', data && data.id === 'message-id'], | ||
['.conversationId', data && data.conversationId === 'conversation-id'], | ||
['.status', data && data.status === 'delivered'] | ||
]); | ||
}); | ||
}); | ||
queue.push(function () { | ||
var params = { | ||
events: ['message.created', 'message.updated'], | ||
channelId: 'channel-id', | ||
url: 'https://example.com/webhook' | ||
}; | ||
nock('https://conversations.messagebird.com') | ||
.post('/v1/conversations/webhooks', params) | ||
.reply(200, { | ||
id: 'webhook-id', | ||
url: 'https://example.com/webhook', | ||
channelId: 'channel-id', | ||
events: [ | ||
'message.created', | ||
'message.updated' | ||
], | ||
status: 'enabled' | ||
}); | ||
messagebird.conversations.webhooks.create(params, function (err, data) { | ||
doTest(err, 'conversations.webhooks.create', [ | ||
['type', data instanceof Object], | ||
['.id', data && data.id === 'webhook-id'], | ||
['.url', data && data.url === 'https://example.com/webhook'], | ||
['.events.length', data && data.events && data.events.length === 2], | ||
['.status', data && data.status === 'enabled'] | ||
]); | ||
}); | ||
}); | ||
queue.push(function () { | ||
nock('https://conversations.messagebird.com') | ||
.get('/v1/conversations/webhooks/webhook-id') | ||
.reply(200, { | ||
id: 'webhook-id', | ||
url: 'https://example.com/webhook', | ||
channelId: 'channel-id', | ||
events: [ | ||
'message.created', | ||
'message.updated' | ||
], | ||
status: 'enabled' | ||
}); | ||
messagebird.conversations.webhooks.read('webhook-id', function (err, data) { | ||
doTest(err, 'conversations.webhooks.read', [ | ||
['type', data instanceof Object], | ||
['.id', data && data.id === 'webhook-id'], | ||
['.channelId', data && data.channelId === 'channel-id'], | ||
['.status', data && data.status === 'enabled'] | ||
]); | ||
}); | ||
}); | ||
queue.push(function () { | ||
var params = { 'status': 'disabled' }; | ||
nock('https://conversations.messagebird.com') | ||
.patch('/v1/conversations/webhooks/webhook-id', params) | ||
.reply(200, { | ||
id: 'webhook-id', | ||
url: 'https://example.com/webhook', | ||
channelId: 'channel-id', | ||
events: [ | ||
'message.created', | ||
'message.updated' | ||
], | ||
status: 'disabled' | ||
}); | ||
messagebird.conversations.webhooks.update('webhook-id', params, function (err, data) { | ||
doTest(err, 'conversations.webhooks.update', [ | ||
['type', data instanceof Object], | ||
['.id', data && data.id === 'webhook-id'], | ||
['.channelId', data && data.channelId === 'channel-id'], | ||
['.status', data && data.status === 'disabled'] | ||
]); | ||
}); | ||
}); | ||
queue.push(function () { | ||
nock('https://conversations.messagebird.com') | ||
.get('/v1/conversations/webhooks') | ||
.query({ | ||
limit: 0, | ||
offset: 30 | ||
}) | ||
.reply(200, { | ||
offset: 0, | ||
limit: 30, | ||
count: 1, | ||
totalCount: 1, | ||
items: [{ | ||
id: 'webhook-id', | ||
url: 'https://example.com/webhook', | ||
channelId: 'channel-id', | ||
events: [ | ||
'message.created', | ||
'message.updated' | ||
], | ||
status: 'enabled' | ||
}] | ||
}); | ||
messagebird.conversations.webhooks.list(0, 30, function (err, data) { | ||
doTest(err, 'conversations.webhooks.list', [ | ||
['type', data instanceof Object], | ||
['.limit', data && data.limit === 30], | ||
['.items[0].id', data && data.items[0].id === 'webhook-id'] | ||
]); | ||
}); | ||
}); | ||
queue.push(function () { | ||
nock('https://conversations.messagebird.com') | ||
.get('/v1/conversations/webhooks') | ||
.reply(200, { | ||
offset: 0, | ||
limit: 20, | ||
count: 1, | ||
totalCount: 1, | ||
items: [{ | ||
id: 'webhook-id', | ||
url: 'https://example.com/webhook', | ||
channelId: 'channel-id', | ||
events: [ | ||
'message.created', | ||
'message.updated' | ||
], | ||
status: 'enabled' | ||
}] | ||
}); | ||
messagebird.conversations.webhooks.list(function (err, data) { | ||
doTest(err, 'conversations.webhooks.list.withoutpagination', [ | ||
['type', data instanceof Object], | ||
['.limit', data && data.limit === 20], | ||
['.items[0].id', data && data.items[0].id === 'webhook-id'] | ||
]); | ||
}); | ||
}); | ||
queue.push(function () { | ||
nock('https://conversations.messagebird.com') | ||
.delete('/v1/conversations/webhooks/webhook-id') | ||
.reply(204, ''); | ||
messagebird.conversations.webhooks.delete('webhook-id', function (err) { | ||
doTest(err, 'conversations.webhooks.delete', []); | ||
}); | ||
}); | ||
queue.push(function () { | ||
var params = { | ||
originator: 'node-js', | ||
recipients: [number], | ||
body: 'Have you seen this logo?', | ||
mediaUrls: ['https://www.messagebird.com/assets/images/og/messagebird.gif'] | ||
}; | ||
nock('https://rest.messagebird.com') | ||
.post('/mms', params) | ||
.reply(200, { id: 'mms-id', body: 'Have you seen this logo?' }); | ||
messagebird.mms.create(params, function (err, data) { | ||
doTest(err, 'mms.create', [ | ||
['type', data instanceof Object], | ||
['.id', data && data.id === 'mms-id'], | ||
['.body', data && data.body === 'Have you seen this logo?'] | ||
]); | ||
}); | ||
}); | ||
queue.push(function () { | ||
nock('https://rest.messagebird.com') | ||
.get('/mms/mms-id') | ||
.reply(200, { | ||
id: 'mms-id', | ||
href: 'https://rest.messagebird.com/mms/efa6405d518d4c0c88cce11f7db775fb', | ||
direction: 'mt', | ||
originator: '+31207009850', | ||
subject: 'Great logo', | ||
body: 'Hi! Please have a look at this very nice logo of this cool company.', | ||
reference: 'the-customers-reference', | ||
mediaUrls: [ | ||
'https://www.messagebird.com/assets/images/og/messagebird.gif' | ||
], | ||
scheduledDatetime: null, | ||
createdDatetime: '2017-09-01T10:00:00+00:00', | ||
recipients: { | ||
totalCount: 1, | ||
totalSentCount: 1, | ||
totalDeliveredCount: 0, | ||
totalDeliveryFailedCount: 0, | ||
items: [ | ||
{ | ||
recipient: 31612345678, | ||
status: 'sent', | ||
statusDatetime: '2017-09-01T10:00:00+00:00' | ||
} | ||
] | ||
} | ||
}); | ||
messagebird.mms.read('mms-id', function (err, data) { | ||
doTest(err, 'mms.read', [ | ||
['type', data instanceof Object], | ||
['.id', data && data.id === 'mms-id'], | ||
['.body', data && data.body === 'Hi! Please have a look at this very nice logo of this cool company.'] | ||
]); | ||
}); | ||
}); | ||
queue.push(function () { | ||
nock('https://rest.messagebird.com') | ||
.get('/mms') | ||
.query({ | ||
limit: 20, | ||
offset: 10 | ||
}) | ||
.reply(200, { | ||
offset: 10, | ||
limit: 20, | ||
count: 1, | ||
totalCount: 1, | ||
links: { | ||
first: 'https://rest.messagebird.com/mms?offset=0', | ||
previous: null, | ||
next: null, | ||
last: 'https://rest.messagebird.com/mmsoffset=0' | ||
}, | ||
items: [ | ||
{ | ||
id: 'mms-id', | ||
href: 'https://rest.messagebird.com/mms/efa6405d518d4c0c88cce11f7db775fb', | ||
direction: 'mt', | ||
originator: '+31207009850', | ||
subject: 'Great logo', | ||
body: 'Hi! Please have a look at this very nice logo of this cool company.', | ||
reference: 'the-customers-reference', | ||
mediaUrls: [ | ||
'https://www.messagebird.com/assets/images/og/messagebird.gif' | ||
], | ||
scheduledDatetime: null, | ||
createdDatetime: '2017-09-01T10:00:00+00:00' | ||
} | ||
] | ||
}); | ||
messagebird.mms.list(20, 10, function (err, data) { | ||
doTest(err, 'mms.list', [ | ||
['type', data instanceof Object], | ||
['.limit', data && data.limit === 20], | ||
['.offset', data && data.offset === 10], | ||
['.items[0].id', data && data.items[0].id === 'mms-id'] | ||
]); | ||
}); | ||
}); | ||
queue.push(function () { | ||
nock('https://rest.messagebird.com') | ||
.get('/mms') | ||
.reply(200, { offset: 0, limit: 20, items: [{ id: 'mms-id' }]}); | ||
messagebird.mms.list(function (err, data) { | ||
doTest(err, 'mms.list.withoutpagination', [ | ||
['type', data instanceof Object], | ||
['.offset', data && data.offset === 0], | ||
['.items[0].id', data && data.items[0].id === 'mms-id'] | ||
]); | ||
}); | ||
}); | ||
queue.push(function () { | ||
nock('https://rest.messagebird.com') | ||
.delete('/mms/mms-id') | ||
.reply(204, { | ||
id: 'mms-id' | ||
}); | ||
messagebird.mms.delete('mms-id', function (err) { | ||
doTest(err, 'mms.delete', []); | ||
}); | ||
}); | ||
queue.push(function () { | ||
nock('https://rest.messagebird.com') | ||
.delete('/mms/mms-id') | ||
.reply(404, { statusCode: 404, errors: [{ code: 20, description: 'message not found', parameter: null }]}); | ||
messagebird.mms.delete('mms-id', function (err) { | ||
expectError(err, 'mms.delete.witherror'); | ||
}); | ||
}); | ||
queue.push(function () { | ||
var params = { | ||
'msisdn': 31612345678, | ||
@@ -389,0 +1036,0 @@ 'firstName': 'Foo', |
{ | ||
"name": "messagebird", | ||
"version": "2.2.0", | ||
"version": "2.3.0", | ||
"description": "A node.js wrapper for the MessageBird REST API", | ||
@@ -5,0 +5,0 @@ "main": "lib/messagebird.js", |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
New author
Supply chain riskA new npm collaborator published a version of the package for the first time. New collaborators are usually benign additions to a project, but do indicate a change to the security surface area of a package.
Found 1 instance in 1 package
81724
2468
1