Skip to content

Commit c5d6945

Browse files
committed
[Conversation] Added dialog node methods
1 parent d13a618 commit c5d6945

File tree

2 files changed

+289
-0
lines changed

2 files changed

+289
-0
lines changed

conversation/v1.js

Lines changed: 179 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1543,4 +1543,183 @@ ConversationV1.prototype.getLogs = function(params, callback) {
15431543
return requestFactory(parameters, callback);
15441544
};
15451545

1546+
/**
1547+
* Method: createDialogNode
1548+
*
1549+
* Create a new dialog node
1550+
*
1551+
* @param {Object} params
1552+
* @param {String} params.workspace_id
1553+
* @param {String} [params.dialog_node]
1554+
* @param {String} [params.description]
1555+
* @param {Array<Object>} [params.examples]
1556+
* @param {Function} [callback]
1557+
*
1558+
*/
1559+
ConversationV1.prototype.createDialogNode = function(params, callback) {
1560+
params = params || {};
1561+
1562+
const parameters = {
1563+
options: {
1564+
url: '/v1/workspaces/{workspace_id}/dialog_nodes',
1565+
method: 'POST',
1566+
json: true,
1567+
path: pick(params, ['workspace_id']),
1568+
body: pick(params, [
1569+
'dialog_node',
1570+
'description',
1571+
'conditions',
1572+
'parent',
1573+
'previous_sibling',
1574+
'output',
1575+
'context',
1576+
'metadata',
1577+
'next_step',
1578+
'actions',
1579+
'title',
1580+
'type',
1581+
'event_name',
1582+
'variable'
1583+
])
1584+
},
1585+
requiredParams: ['workspace_id', 'dialog_node'],
1586+
defaultOptions: this._options
1587+
};
1588+
return requestFactory(parameters, callback);
1589+
};
1590+
1591+
/**
1592+
* Method: getDialogNodes
1593+
*
1594+
* List the dialog nodes for a workspace.
1595+
*
1596+
* @param {Object} params
1597+
* @param {String} params.workspace_id
1598+
* @param {Boolean} [params.export=false] - if true, the full contents of all of the sub-resources are returned
1599+
* @param {Number} [params.page_limit]
1600+
* @param {Boolean} [params.include_count]
1601+
* @param {String} [params.sort]
1602+
* @param {String} [params.cursor]
1603+
* @param {Function} [callback]
1604+
*
1605+
*/
1606+
ConversationV1.prototype.getDialogNodes = function(params, callback) {
1607+
params = params || {};
1608+
1609+
const parameters = {
1610+
options: {
1611+
url: '/v1/workspaces/{workspace_id}/dialog_nodes',
1612+
method: 'GET',
1613+
json: true,
1614+
path: pick(params, ['workspace_id']),
1615+
qs: pick(params, ['page_limit', 'include_count', 'sort', 'cursor'])
1616+
},
1617+
requiredParams: ['workspace_id'],
1618+
defaultOptions: this._options
1619+
};
1620+
return requestFactory(parameters, callback);
1621+
};
1622+
1623+
/**
1624+
* Method: getDialogNode
1625+
*
1626+
* Get information about an dialog node, optionally including all dialog node content.
1627+
*
1628+
* @param {Object} params
1629+
* @param {String} params.workspace_id
1630+
* @param {String} params.dialog_node
1631+
* @param {Boolean} [params.export=false] - if true, the full contents of all of the sub-resources are returned
1632+
* @param {Function} [callback]
1633+
*
1634+
*/
1635+
ConversationV1.prototype.getDialogNode = function(params, callback) {
1636+
params = params || {};
1637+
1638+
const parameters = {
1639+
options: {
1640+
url: '/v1/workspaces/{workspace_id}/dialog_nodes/{dialog_node}',
1641+
method: 'GET',
1642+
json: true,
1643+
path: pick(params, ['workspace_id', 'dialog_node']),
1644+
qs: pick(params, ['export'])
1645+
},
1646+
requiredParams: ['workspace_id', 'dialog_node'],
1647+
defaultOptions: this._options
1648+
};
1649+
return requestFactory(parameters, callback);
1650+
};
1651+
1652+
/**
1653+
* Method: updateDialogNode
1654+
*
1655+
* Update an existing dialog node with new or modified data. You must provide JSON data defining the content of the updated dialog node.
1656+
*
1657+
* @param {Object} params
1658+
* @param {String} params.workspace_id
1659+
* @param {String} params.old_dialog_node
1660+
* @param {String} params.dialog_node
1661+
* @param {String} params.description
1662+
* @param {Array<Object>} params.examples
1663+
* @param {Function} [callback]
1664+
*
1665+
*/
1666+
ConversationV1.prototype.updateDialogNode = function(params, callback) {
1667+
params = params || {};
1668+
1669+
const parameters = {
1670+
options: {
1671+
url: '/v1/workspaces/{workspace_id}/dialog_nodes/{old_dialog_node}',
1672+
method: 'POST',
1673+
json: true,
1674+
path: pick(params, ['workspace_id', 'old_dialog_node']),
1675+
body: pick(params, [
1676+
'dialog_node',
1677+
'description',
1678+
'conditions',
1679+
'parent',
1680+
'previous_sibling',
1681+
'output',
1682+
'context',
1683+
'metadata',
1684+
'next_step',
1685+
'actions',
1686+
'title',
1687+
'type',
1688+
'event_name',
1689+
'variable'
1690+
])
1691+
},
1692+
requiredParams: ['workspace_id', 'old_dialog_node', 'dialog_node'],
1693+
defaultOptions: this._options
1694+
};
1695+
return requestFactory(parameters, callback);
1696+
};
1697+
1698+
/**
1699+
* Method: deleteDialogNode
1700+
*
1701+
* Delete an dialog node from a workspace
1702+
*
1703+
* @param {Object} params
1704+
* @param {String} params.workspace_id
1705+
* @param {String} params.dialog_node
1706+
* @param {Function} [callback]
1707+
*
1708+
*/
1709+
ConversationV1.prototype.deleteDialogNode = function(params, callback) {
1710+
params = params || {};
1711+
1712+
const parameters = {
1713+
options: {
1714+
url: '/v1/workspaces/{workspace_id}/dialog_nodes/{dialog_node}',
1715+
method: 'DELETE',
1716+
json: true,
1717+
path: pick(params, ['workspace_id', 'dialog_node'])
1718+
},
1719+
requiredParams: ['workspace_id', 'dialog_node'],
1720+
defaultOptions: this._options
1721+
};
1722+
return requestFactory(parameters, callback);
1723+
};
1724+
15461725
module.exports = ConversationV1;

test/integration/test.conversation.js

Lines changed: 110 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,8 @@ const test_value_update = {
9696
};
9797
const test_synonym = 'synonym_1';
9898
const test_synonym_update = 'synonym_2';
99+
const test_dialog_node = 'new_node';
100+
const test_dialog_node_update = 'updated_node';
99101

100102
// changing language is forbidden starting with VERSION_DATE_2017_05_26
101103
const workspace1 = extend(true, {}, workspace, intents, { language: workspace.language });
@@ -983,6 +985,114 @@ describe('conversation_integration', function() {
983985
});
984986
});
985987

988+
describe('createDialogNode()', function() {
989+
it('should create an dialog node', function(done) {
990+
const params = {
991+
workspace_id: workspace1.workspace_id,
992+
dialog_node: test_dialog_node,
993+
conditions: 'true'
994+
};
995+
996+
conversation.createDialogNode(params, function(err, result) {
997+
if (err) {
998+
return done(err);
999+
}
1000+
assert.equal(result.dialog_node, test_dialog_node, 'dialog_node field has unexpected value');
1001+
assert.equal(result.conditions, 'true', 'conditions field has unexpected value');
1002+
assert.equal(result.description, null, 'description field is not null');
1003+
assert.notEqual(result.created, null, 'created field is null');
1004+
done();
1005+
});
1006+
});
1007+
});
1008+
1009+
describe('getDialogNodes()', function() {
1010+
it('should get dialog nodes of the workspace', function(done) {
1011+
const params = {
1012+
workspace_id: workspace1.workspace_id
1013+
};
1014+
1015+
conversation.getDialogNodes(params, function(err, result) {
1016+
if (err) {
1017+
return done(err);
1018+
}
1019+
assert.equal(result.dialog_nodes[0].dialog_node, test_dialog_node);
1020+
done();
1021+
});
1022+
});
1023+
1024+
it('should have pagination information', function(done) {
1025+
const params = {
1026+
workspace_id: workspace1.workspace_id,
1027+
page_limit: 1,
1028+
include_count: true,
1029+
sort: 'dialog_node'
1030+
};
1031+
1032+
conversation.getDialogNodes(params, function(err, result) {
1033+
if (err) {
1034+
return done(err);
1035+
}
1036+
assert.equal(result.hasOwnProperty('pagination'), true);
1037+
done();
1038+
});
1039+
});
1040+
});
1041+
1042+
describe('getDialogNode()', function() {
1043+
it('should get a dialog node of the workspace', function(done) {
1044+
const params = {
1045+
workspace_id: workspace1.workspace_id,
1046+
dialog_node: test_dialog_node
1047+
};
1048+
1049+
conversation.getDialogNode(params, function(err, result) {
1050+
if (err) {
1051+
return done(err);
1052+
}
1053+
assert.equal(result.dialog_node, test_dialog_node);
1054+
assert.equal(result.description, null);
1055+
done();
1056+
});
1057+
});
1058+
});
1059+
1060+
describe('updateDialogNode()', function() {
1061+
it('should update a dialog node of the workspace', function(done) {
1062+
const params = {
1063+
workspace_id: workspace1.workspace_id,
1064+
old_dialog_node: test_dialog_node,
1065+
dialog_node: test_dialog_node_update,
1066+
conditions: 'false'
1067+
};
1068+
1069+
conversation.updateDialogNode(params, function(err, result) {
1070+
if (err) {
1071+
return done(err);
1072+
}
1073+
assert.equal(result.dialog_node, test_dialog_node_update);
1074+
assert.equal(result.conditions, 'false');
1075+
done();
1076+
});
1077+
});
1078+
});
1079+
1080+
describe('deleteDialogNode()', function() {
1081+
it('should delete a dialog node of the workspace', function(done) {
1082+
const params = {
1083+
workspace_id: workspace1.workspace_id,
1084+
dialog_node: test_dialog_node_update
1085+
};
1086+
1087+
conversation.deleteDialogNode(params, function(err, result) {
1088+
if (err) {
1089+
return done(err);
1090+
}
1091+
done();
1092+
});
1093+
});
1094+
});
1095+
9861096
describe('deleteWorkspace()', function() {
9871097
it('should delete the workplace', function(done) {
9881098
const params = {

0 commit comments

Comments
 (0)