Skip to content

Commit

Permalink
Merge pull request #47 from trololov/feature-ON-98
Browse files Browse the repository at this point in the history
Feature on 98
  • Loading branch information
niekert authored Nov 12, 2019
2 parents ffcc214 + df7d6bf commit 515e09d
Show file tree
Hide file tree
Showing 6 changed files with 397 additions and 3 deletions.
27 changes: 26 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,32 @@ Or in case of an error:
]
}
```

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
-------------

Expand Down
105 changes: 105 additions & 0 deletions lib/messagebird.js
Original file line number Diff line number Diff line change
Expand Up @@ -875,6 +875,111 @@ module.exports = function (accessKey, timeout, features) {

},

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: {

/**
Expand Down
189 changes: 188 additions & 1 deletion lib/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,9 @@ var cache = {
phoneNumber: number
},

transcription: {}
transcription: {},

callflow: {}
};


Expand Down Expand Up @@ -1499,6 +1501,191 @@ queue.push(function () {
});
});

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')
.post('/groups', '{"name":"friends"}')
Expand Down
19 changes: 19 additions & 0 deletions types/callflows.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import { datetime } from './general';
import { languages } from './voice_messages';
import { StepParameter } from './calls';

export interface CallFlow {
/** The unique ID of the call flow. */
id: string;
title: string;
/** Says whether a full call recording is enabled on this call flow, the default value for this attribute is false. */
record: boolean;
/** An array of step objects. The sequence of the array items describe the order of execution, where the first item will be executed first, than the second, etcetera. */
steps: StepParameter[];
/** The default attribute says whether the call flow will be used when no call flow was found for an inbound number. Only one default call flow is allowed. */
default?: boolean;
/** The date-time the call was created, in RFC 3339 format (e.g. 2017-03-06T13:34:14Z). */
createdAt?: datetime;
/** The date-time the call was last updated, in RFC 3339 format (e.g. 2017-03-06T13:34:14Z). */
updatedAt?: datetime;
}
11 changes: 10 additions & 1 deletion types/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@ import { Lookup } from './lookup';
import { Contact, ContactParameter } from './contact';
import { GroupParameter } from './group';
import { Recording } from './recordings';
import { Call, CallParameter } from './calls';
import { Call, CallParameter, CallFlowParameter } from './calls';
import { CallFlow } from './callflows';
import {
ConversationParameter,
SendResponse,
Expand Down Expand Up @@ -42,6 +43,14 @@ export interface MessageBird {
read(id: string, callback: CallbackFn<Message>): void;
create(params: MessageParameters, callback: CallbackFn<Message>): void;
};
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: {
read(id: string, callback: CallbackFn<VoiceMessage>): void;
create(
Expand Down
Loading

0 comments on commit 515e09d

Please sign in to comment.