From 29f143faada3c117f5e8cfff2f87291c50b57c17 Mon Sep 17 00:00:00 2001 From: Sulaiman Sanusi Date: Fri, 26 Jul 2019 05:05:55 +0100 Subject: [PATCH] added request Query with token --- js/Dialogflow_V2.js | 33 +++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) diff --git a/js/Dialogflow_V2.js b/js/Dialogflow_V2.js index a04f0a6..adba7ef 100644 --- a/js/Dialogflow_V2.js +++ b/js/Dialogflow_V2.js @@ -134,7 +134,40 @@ export class Dialogflow_V2 { }) .catch(onError); }; + + requestQueryWithAuth = async (query, token, onResult, onError) => { + const data = { + "queryParams": { + "contexts": this.mergeContexts(this.contexts, this.permanentContexts), + "sessionEntityTypes": [] + }, + "queryInput": { + "text": { + "text": query, + "languageCode": this.languageTag, + }, + }, + token + } + + this.contexts = null; + this.entities = null; + + fetch(DEFAULT_BASE_URL + this.projectId + "/agent/sessions/" + this.sessionId + ":detectIntent", { + method: "POST", + headers: { + 'Content-Type': 'application/json; charset=utf-8', + 'Authorization': 'Bearer ' + this.accessToken, + 'charset': "utf-8" + }, + body: JSON.stringify(data) + }) + .then(function (response) { + var json = response.json().then(onResult) + }) + .catch(onError); + }; mergeContexts(context1, context2) { if (!context1) {