Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
else {
// ----> QUERY : DETECT AN INTENT
let session = config.session || "user.id",
language = config.language || "en",
text = config.text || "payload";
if (config.languageType !== 'str') {
let loc = (config.languageType === 'global') ? node.context().global : data;
language = helper.getByString(loc, language); }
if (config.sessionType !== 'str') {
let loc = (config.sessionType === 'global') ? node.context().global : data;
session = helper.getByString(loc, session); }
if (config.textType !== 'str') {
let loc = (config.textType === 'global') ? node.context().global : data;
text = helper.getByString(loc, text); }
if (version === "v2") { // VERSION 2
try {
config.tokenv2.authenticate((client, token) => {
let key = token.value,
sessionPath = "projects/" + config.tokenv2.cred.project_id + "/agent/sessions/" + session;
let req = {
method: "POST",
uri: "https://dialogflow.googleapis.com/v2beta1/" + sessionPath + ":detectIntent",
headers: {
'Authorization': 'Bearer ' + key,
'Content-Type': 'application/json; charset=utf-8'
},
body: JSON.stringify({
const remove = (node, data, config) => {
let dbKey = (config.keyType === "str") ? config.key : helper.getByString(data, config.key, config.key);
node.server.databaseManager.remove({ id:dbKey}, data, config, function(err, data, result) {
if (err) node.error(err);
node.send(data);
});
}
const input = (node, data, config) => {
let now = new Date();
let pageId = (config.pageIdType === "msg") ? helper.getByString(data, config.pageId) : config.pageId;
let siteId = (config.siteIdType === "msg") ? helper.getByString(data, config.siteId) : config.siteId;
let url = 'http://logv2.xiti.com/hit.xiti' + '?s=' + siteId + '&p=' + pageId
+ '&hl='+now.getHours()+'x'+now.getMinutes()+'x'+now.getSeconds();
request({ 'url': url }, function (err, response, body) {
if (err) node.error(err);
});
node.send(data);
}
const input = (node, data, config) => {
let now = new Date();
let pageId = (config.pageIdType === "msg") ? helper.getByString(data, config.pageId) : config.pageId;
let siteId = (config.siteIdType === "msg") ? helper.getByString(data, config.siteId) : config.siteId;
let url = 'http://logv2.xiti.com/hit.xiti' + '?s=' + siteId + '&p=' + pageId
+ '&hl='+now.getHours()+'x'+now.getMinutes()+'x'+now.getSeconds();
request({ 'url': url }, function (err, response, body) {
if (err) node.error(err);
});
node.send(data);
}
let json = await searchRequest(ibConfig + "/?idata=" + objectId + "&action=click");
data.payload = JSON.parse(json);
return node.send(data);
}
catch(err) { return node.error(err); }
}
else if (action === "rate") {
let rating = config.objectRating,
comment = config.objectComment,
ratingType = config.objectRatingType,
commentType = config.objectCommentType;
if (ratingType !== 'str') {
let loc = (ratingType === 'global') ? node.context().global : data;
rating = helper.getByString(loc, rating);
}
if (commentType !== 'str') {
let loc = (commentType === 'global') ? node.context().global : data;
comment = helper.getByString(loc, comment);
}
if (comment === undefined || typeof comment !== 'string') comment = '';
try {
let json = await searchRequest(ibConfig + "/?action=rating-content&idata=" + rating + comment);
data.payload = JSON.parse(json);
return node.send(data);
}
catch(err) { return node.error(err); }
}
}
const getMessageContext = (message) => {
if (message === undefined) return;
let uuid = helper.getByString(message, _CONTEXT_KEY);
let context = _CONTEXTS.get(uuid);
if (!context) {
context = {};
let convId = helper.getByString(message, 'address.conversation.id');
uuid = convId + '-' + uuidv4();
helper.setByString(message, _CONTEXT_KEY, uuid);
_CONTEXTS.set(uuid, context);
}
return context;
}
const getMessageContext = (message) => {
if (message === undefined) return;
let uuid = helper.getByString(message, _CONTEXT_KEY);
let context = _CONTEXTS.get(uuid);
if (!context) {
context = {};
let convId = helper.getByString(message, 'address.conversation.id');
uuid = convId + '-' + uuidv4();
helper.setByString(message, _CONTEXT_KEY, uuid);
_CONTEXTS.set(uuid, context);
}
return context;
}
const getMessageContext = (message) => {
if (message === undefined) return;
let uuid = helper.getByString(message, _CONTEXT_KEY);
let context = _CONTEXTS.get(uuid);
if (!context) {
context = {};
let convId = helper.getByString(message, 'address.conversation.id');
uuid = convId + '-' + uuidv4();
helper.setByString(message, _CONTEXT_KEY, uuid);
_CONTEXTS.set(uuid, context);
}
return context;
}
const getMessageContext = message => {
if (message === undefined) return;
let uuid = helper.getByString(message, _CONTEXT_KEY);
let context = _CONTEXTS.get(uuid);
if (!context) {
context = {};
let convId = helper.getByString(message, "address.conversation.id");
uuid = convId + "-" + uuidv4();
helper.setByString(message, _CONTEXT_KEY, uuid);
_CONTEXTS.set(uuid, context);
}
return context;
};
const getMessageContext = (message) => {
if (message === undefined) return;
let uuid = helper.getByString(message, _CONTEXT_KEY);
let context = _CONTEXTS.get(uuid);
if (!context) {
context = {};
let convId = helper.getByString(message, 'address.conversation.id');
uuid = convId + '-' + uuidv4();
helper.setByString(message, _CONTEXT_KEY, uuid);
_CONTEXTS.set(uuid, context);
}
return context;
}