messagebird
Advanced tools
Comparing version 3.2.0 to 3.3.0
@@ -878,2 +878,107 @@ /** | ||
callflows: { | ||
/** | ||
* Lists existing call flows. | ||
* @param {Number} page | ||
* @param {Number} perpage | ||
* @param {Function} callback | ||
* @return void | ||
*/ | ||
list: function (page, perpage, callback) { | ||
var params = null; | ||
if (typeof callback === 'function') { | ||
params = { | ||
page: page, | ||
perPage: perpage | ||
}; | ||
} else { | ||
callback = page; | ||
} | ||
httpRequest({ | ||
hostname: VOICE_ENDPOINT, | ||
method: 'GET', | ||
path: '/call-flows', | ||
params: params}, | ||
callback); | ||
}, | ||
/** | ||
* Creates a new call flow, params are mandatory. | ||
* | ||
* @param {Object} params | ||
* @param {Function} callback | ||
* @return void | ||
*/ | ||
create: function (params, callback) { | ||
httpRequest( | ||
{ | ||
hostname: VOICE_ENDPOINT, | ||
method: 'POST', | ||
path: '/call-flows', | ||
params: params}, | ||
callback); | ||
}, | ||
/** | ||
* Get a call flow | ||
* | ||
* @param {String} flowId | ||
* @param {Function} callback | ||
* @return {void} | ||
*/ | ||
read: function (flowId, callback) { | ||
httpRequest( | ||
{ | ||
hostname: VOICE_ENDPOINT, | ||
method: 'GET', | ||
path: '/call-flows/'+flowId, | ||
}, | ||
callback | ||
); | ||
}, | ||
/** | ||
* Deletes an existing call flow. The callback is invoked with an error if | ||
* applicable, but the data will never contain anything meaningful as the | ||
* API returns an empty response for successful deletes. | ||
* | ||
* @param {String} flowId | ||
* @param {Function} callback | ||
* @return void | ||
*/ | ||
delete: function (flowId, callback) { | ||
httpRequest( | ||
{ | ||
hostname: VOICE_ENDPOINT, | ||
method: 'DELETE', | ||
path: '/call-flows/'+flowId | ||
}, | ||
callback, | ||
); | ||
}, | ||
/** | ||
* Updates an existing call flow. Params are required. | ||
* | ||
* @param {String} flowId | ||
* @param {Object} params | ||
* @param {Function} callback | ||
* @return void | ||
*/ | ||
update: function (flowId, params, callback) { | ||
httpRequest( | ||
{ | ||
hostname: VOICE_ENDPOINT, | ||
method: 'PUT', | ||
path: '/call-flows/'+flowId, | ||
params: params | ||
}, | ||
callback | ||
); | ||
} | ||
}, | ||
groups: { | ||
@@ -880,0 +985,0 @@ |
189
lib/test.js
@@ -52,3 +52,5 @@ var fs = require('fs'); | ||
transcription: {} | ||
transcription: {}, | ||
callflow: {} | ||
}; | ||
@@ -1503,3 +1505,188 @@ | ||
CALLFLOW_EXAMPLE={ | ||
data: [ | ||
{ | ||
id: "id#1", | ||
title: "title #1", | ||
steps: [ | ||
{ | ||
id: "step #1", | ||
action: "action", | ||
options: { | ||
destination: "dest $1" | ||
} | ||
} | ||
], | ||
record: false, | ||
default: false, | ||
createdAt: "2019-11-04T15:38:01Z", | ||
updatedAt: "2019-11-04T15:38:01Z", | ||
_links: { | ||
self: "/call-flows/id#1" | ||
} | ||
}, | ||
{ | ||
id: "id#2", | ||
title: "title #2", | ||
steps: [ | ||
{ | ||
id: "step #1", | ||
action: "action", | ||
options: { | ||
destination: "dest $2" | ||
} | ||
} | ||
], | ||
record: false, | ||
default: false, | ||
createdAt: "2019-11-04T15:38:01Z", | ||
updatedAt: "2019-11-04T15:38:01Z", | ||
_links: { | ||
self: "/call-flows/id#2" | ||
} | ||
}, | ||
{ | ||
id: "id#3", | ||
title: "title #3", | ||
steps: [ | ||
{ | ||
id: "step #1", | ||
action: "action", | ||
options: { | ||
destination: "dest $3" | ||
} | ||
} | ||
], | ||
record: false, | ||
default: false, | ||
createdAt: "2019-11-04T15:38:01Z", | ||
updatedAt: "2019-11-04T15:38:01Z", | ||
_links: { | ||
self: "/call-flows/id#3" | ||
} | ||
} | ||
], | ||
pagination: { | ||
totalCount: 3, | ||
pageCount: 1, | ||
currentPage: 1, | ||
perPage: 10 | ||
} | ||
} | ||
CALLFLOW_EXAMPLE_PAGE={ | ||
data: [ | ||
{ | ||
id: 'id#1', | ||
title: 'title #1', | ||
steps: [ | ||
{ | ||
id: 'step #1', | ||
action: 'action', | ||
options: { | ||
destination: 'dest $1' | ||
} | ||
} | ||
], | ||
record: false, | ||
default: false, | ||
createdAt: '2019-11-04T15:38:01Z', | ||
updatedAt: '2019-11-04T15:38:01Z', | ||
_links: { | ||
self: '/call-flows/id#1' | ||
} | ||
} | ||
], | ||
pagination: { | ||
totalCount: 1, | ||
pageCount: 1, | ||
currentPage: 1, | ||
perPage: 10 | ||
} | ||
} | ||
queue.push(function () { | ||
nock(VOICE_ENDPOINT) | ||
.get('/call-flows') | ||
.reply(200,{}); | ||
messagebird.callflows.list(function (err, data) { | ||
doTest(err, 'callflows.list.empty', []); | ||
}) | ||
}) | ||
queue.push(function () { | ||
nock(VOICE_ENDPOINT) | ||
.get('/call-flows') | ||
.reply(200,CALLFLOW_EXAMPLE); | ||
messagebird.callflows.list(function (err, response) { | ||
doTest(err, 'callflows.list.default', [ | ||
['.response.data[0].id', response.data[0].id === 'id#1'], | ||
['.response.data[0].id', response.data[0].title === 'title #1'], | ||
['length of array response == 3', response.data.length === 3], | ||
['totalCount == 3', response.pagination.totalCount === 3] | ||
]); | ||
}) | ||
}) | ||
queue.push(function () { | ||
nock(VOICE_ENDPOINT) | ||
.get('/call-flows?page=1&perPage=1') | ||
.reply(200,CALLFLOW_EXAMPLE_PAGE); | ||
messagebird.callflows.list(1, 1, function (err, response) { | ||
doTest(err, 'callflows.list.paged', [ | ||
['.response.data[0].id', response.data[0].id === 'id#1'], | ||
['.response.data[0].id', response.data[0].title === 'title #1'], | ||
['length of array response == 1', response.data.length === 1], | ||
['totalCount == 1', response.pagination.totalCount === 1] | ||
]); | ||
}) | ||
}) | ||
queue.push(function () { | ||
nock(VOICE_ENDPOINT) | ||
.get('/call-flows/id#1') | ||
.reply(200,CALLFLOW_EXAMPLE_PAGE); | ||
messagebird.callflows.read("id#1", function (err, response) { | ||
doTest(err, 'callflows.read', [ | ||
['.response.data[0].id', response.data[0].id === 'id#1'], | ||
['.response.data[0].id', response.data[0].title === 'title #1'], | ||
['length of array response == 1', response.data.length === 1] | ||
]); | ||
}) | ||
}) | ||
queue.push(function () { | ||
nock(VOICE_ENDPOINT) | ||
.delete('/call-flows/id#1') | ||
.reply(204, ''); | ||
messagebird.callflows.delete('id#1', function (err) { | ||
doTest(err, 'callflows.delete', []); | ||
}); | ||
}); | ||
queue.push(function () { | ||
nock(VOICE_ENDPOINT) | ||
.post('/call-flows') | ||
.reply(200, CALLFLOW_EXAMPLE_PAGE); | ||
messagebird.callflows.create(CALLFLOW_EXAMPLE_PAGE.data[0], function (err, response) { | ||
doTest(err, 'callflows.create', [ | ||
['.response.data[0].id', response.data[0].id === 'id#1'], | ||
['.response.data[0].id', response.data[0].title === 'title #1'] | ||
]); | ||
}); | ||
}); | ||
queue.push(function () { | ||
nock(VOICE_ENDPOINT) | ||
.put('/call-flows/id#1') | ||
.reply(204, ''); | ||
messagebird.callflows.update('id#1', {title: 'title_new'}, function (err, response) { | ||
doTest(err, 'callflows.update', []); | ||
}); | ||
}); | ||
queue.push(function () { | ||
nock('https://rest.messagebird.com') | ||
@@ -1506,0 +1693,0 @@ .post('/groups', '{"name":"friends"}') |
{ | ||
"name": "messagebird", | ||
"version": "3.2.0", | ||
"version": "3.3.0", | ||
"description": "A node.js wrapper for the MessageBird REST API", | ||
@@ -5,0 +5,0 @@ "main": "lib/messagebird.js", |
@@ -64,3 +64,28 @@ MessageBird REST API for Node.js | ||
``` | ||
Notes | ||
------------- | ||
Messaging and Voice API use different pagination semantics: | ||
**Messaging API** uses limit and offset params for list methods (where applicable) | ||
````javascript | ||
// list conversations | ||
//In this case 20 is limit and 0 is offset | ||
messagebird.conversations.list(20, 0, function (err, response) { | ||
if (err) { | ||
return console.log(err); | ||
} | ||
console.log(response); | ||
}); | ||
```` | ||
**Voice API** uses page and perPage params for list methods (where applicable) | ||
````javascript | ||
// list Call Flows | ||
// In this case 1 is page, 2 is items per page | ||
messagebird.callflows.list(1, 2, function (err, response) { | ||
if (err) { | ||
return console.log(err); | ||
} | ||
console.log(response); | ||
}); | ||
```` | ||
Verifying Signatures | ||
@@ -67,0 +92,0 @@ ------------- |
@@ -17,3 +17,4 @@ // TypeScript Version: 3.0 | ||
import { Recording } from './recordings'; | ||
import { Call, CallParameter } from './calls'; | ||
import { Call, CallParameter, CallFlowParameter } from './calls'; | ||
import { CallFlow } from './callflows'; | ||
import { | ||
@@ -46,2 +47,10 @@ ConversationParameter, | ||
}; | ||
callflows: { | ||
read(id: string, callback: CallbackFn<CallFlow>): void; | ||
list(page: number, perPage: number, callback: CallbackFn<CallFlow[]>): void; | ||
list(callback: CallbackFn<CallFlow[]>): void; | ||
delete(id: string, callback: CallbackFn): void; | ||
update(id: string, params: CallFlowParameter, callback: CallbackFn): void; | ||
create(params: CallFlowParameter, callback: CallbackFn<CallFlow>): void; | ||
}; | ||
voice_messages: { | ||
@@ -48,0 +57,0 @@ read(id: string, callback: CallbackFn<VoiceMessage>): void; |
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
168480
56
5121
129