Skip to content

Commit e26eeb2

Browse files
committed
### 0.8.29
- added createIntent() - added getIntents()
1 parent 46bed84 commit e26eeb2

File tree

4 files changed

+155
-4
lines changed

4 files changed

+155
-4
lines changed

tiledesk-client/CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,10 @@
22

33
This library is on npm: https://www.npmjs.com/package/@tiledesk/tiledesk-client
44

5+
### 0.8.29
6+
- added createIntent()
7+
- added getIntents()
8+
59
### 0.8.24
610
- bug fix
711

tiledesk-client/index.js

Lines changed: 104 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1383,6 +1383,107 @@ class TiledeskClient {
13831383
);
13841384
}
13851385

1386+
// *******************************************************
1387+
// *********************** Intents ***********************
1388+
// *******************************************************
1389+
1390+
/**
1391+
* Create an Intent (aka Faq).<br>
1392+
* <a href='https://developer.tiledesk.com/apis/rest-api/chat-bots/faq#create-a-new-faq' target='_blank'>REST API</a>
1393+
* @param {string} botId - The botId. Mandatory
1394+
* @param {string} intent_display_name - Intent Display Name
1395+
* @param {string} question - The question
1396+
* @param {string} answer - The answer
1397+
* @param {string} language - The bot language
1398+
* @param {boolean} webhook_enabled - Is fulfillment enabled for this intent?
1399+
* @param {resultCallback} callback - The callback that handles the response.
1400+
*/
1401+
createIntent(botId, intentDisplayName, question, answer, language, webhook_enabled, callback) {
1402+
console.log("createIntent 1")
1403+
const URL = `${this.APIURL}/${this.projectId}/faq`
1404+
const HTTPREQUEST = {
1405+
url: URL,
1406+
headers: {
1407+
'Content-Type' : 'application/json',
1408+
'Authorization': this.jwt_token
1409+
},
1410+
json: {
1411+
id_faq_kb: botId,
1412+
intent_display_name: intentDisplayName,
1413+
question: question,
1414+
answer: answer,
1415+
language: language,
1416+
webhook_enabled: webhook_enabled
1417+
},
1418+
method: 'POST'
1419+
};
1420+
console.log("createIntent 2")
1421+
TiledeskClient.myrequest(
1422+
HTTPREQUEST,
1423+
function(err, resbody) {
1424+
if (err) {
1425+
if (callback) {
1426+
console.log("createIntent 3")
1427+
callback(err);
1428+
}
1429+
}
1430+
else {
1431+
console.log("createIntent 5")
1432+
if (callback) {
1433+
console.log("createIntent 4")
1434+
callback(null, resbody);
1435+
}
1436+
}
1437+
}, this.log
1438+
);
1439+
}
1440+
1441+
/**
1442+
* Get bot intents, filtered by parameters<br>
1443+
* <a href='https://developer.tiledesk.com/apis/rest-api/chat-bots/faq#get-all-faqs-of-a-bot' target='_blank'>REST API</a>
1444+
* @param {string} id_faq_kb - The bot's id. Mandatory.
1445+
* @param {string} intent_display_name - Filter by Intent Display Name. Optional
1446+
* @param {number} page - page number for pagination. Optional
1447+
* @param {number} limit - results per page. Optional
1448+
* @param {string} text - executes a full text search on this parameter. Optional
1449+
* @param {resultCallback} callback - The callback that handles the response.
1450+
*/
1451+
getIntents(id_faq_kb, intent_display_name, page, limit, text, callback) {
1452+
const URL = `${this.APIURL}/${this.projectId}/faq`
1453+
const params = {
1454+
id_faq_kb: id_faq_kb,
1455+
intent_display_name: intent_display_name,
1456+
page: page,
1457+
limit: limit,
1458+
text: text
1459+
};
1460+
console.log("querying params:", params);
1461+
const HTTPREQUEST = {
1462+
url: URL,
1463+
headers: {
1464+
'Content-Type' : 'application/json',
1465+
'Authorization': this.jwt_token
1466+
},
1467+
params: params,
1468+
method: 'GET'
1469+
};
1470+
TiledeskClient.myrequest(
1471+
HTTPREQUEST,
1472+
function(err, resbody) {
1473+
if (err) {
1474+
if (callback) {
1475+
callback(err);
1476+
}
1477+
}
1478+
else {
1479+
if (callback) {
1480+
callback(null, resbody);
1481+
}
1482+
}
1483+
}, true
1484+
);
1485+
}
1486+
13861487
// ***********************************************************
13871488
// *********************** DEPARTMENTS ***********************
13881489
// ***********************************************************
@@ -1668,7 +1769,7 @@ class TiledeskClient {
16681769
}
16691770

16701771
/**
1671-
* Returns the current opening status based on Opening Hours.
1772+
* Returns the current opening status based on Opening Hours (aka Operating hours).
16721773
*
16731774
* @param {resultCallback} callback - The callback that handles the response.<br>
16741775
* <a href='https://developer.tiledesk.com/apis/rest-api/projects#return-if-the-project-is-open-regarding-operating-hours' target='_blank'>REST API</a>
@@ -2247,14 +2348,14 @@ class TiledeskClient {
22472348
url: options.url,
22482349
method: options.method,
22492350
data: options.json,
2351+
params: options.params,
22502352
headers: options.headers
22512353
})
22522354
.then(function (res) {
22532355
if (log) {
22542356
console.log("Response for url:", options.url);
22552357
console.log("Response headers:\n", res.headers);
2256-
console.log("******** Response for url:", res);
2257-
console.log("Response body:\n", res.data);
2358+
//console.log("******** Response for url:", res);
22582359
}
22592360
if (res && res.status == 200 && res.data) {
22602361
if (callback) {

tiledesk-client/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@tiledesk/tiledesk-client",
3-
"version": "0.8.28",
3+
"version": "0.8.29",
44
"description": "Javascript (nodeJS) SDK for Tiledesk REST APIs",
55
"main": "index.js",
66
"scripts": {

tiledesk-client/test/test.js

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -865,6 +865,52 @@ describe('TiledeskClient', function() {
865865
});
866866
});
867867

868+
// *********** INTENTS **********
869+
870+
describe('TiledeskClient', function() {
871+
describe('create a Faq, query the faq by intent display name', function() {
872+
it('1. create a bot, 2. create a faq, 3. query the faq by intent display name, 4. delete created bot', (done) => {
873+
const bot_name = "my bot " + uuidv4();
874+
const tdclient = new TiledeskClient(
875+
{
876+
APIKEY: APIKEY,
877+
APIURL: API_ENDPOINT,
878+
projectId: PROJECT_ID,
879+
token: USER_TOKEN,
880+
log: LOG_STATUS
881+
})
882+
tdclient.createBot(bot_name, false, null, (err, thebot) => {
883+
console.log("bot created:", thebot);
884+
assert(thebot);
885+
assert(thebot.type === 'internal');
886+
assert(thebot.name === bot_name);
887+
assert(thebot._id !== null);
888+
const intent_display_name = "mytestintent"
889+
tdclient.createIntent(thebot._id, intent_display_name, "My question", "My answer", "en", false, (err, thefaq) => {
890+
console.log("intent created", thefaq);
891+
assert(thefaq);
892+
tdclient.getIntents(thebot._id, intent_display_name, 0, 0, null, (err, faqs) => {
893+
console.log("the faqs", faqs.length)
894+
assert(faqs.length == 1);
895+
assert(faqs[0]);
896+
assert(faqs[0].intent_display_name === intent_display_name);
897+
tdclient.getIntents(thebot._id, "unknown", 0, 0, null, (err, faqs) => {
898+
console.log("the faqs", faqs.length)
899+
assert(faqs.length == 0);
900+
tdclient.deleteBot(thebot._id, (err, result) => {
901+
assert(!err);
902+
assert(result);
903+
done();
904+
});
905+
});
906+
});
907+
908+
});
909+
});
910+
});
911+
});
912+
});
913+
868914
// *********** ORCHESTERATION ***********
869915

870916
describe('TiledeskClient', function() {

0 commit comments

Comments
 (0)