Reputation: 89
I'm brand new to using dialogflow. I've created a basic chatbot to test getting the response i've created through the api. I have my POST working but the GET is not getting the data I want and gives me a 401 and stops working.
I'm not sure if my code is in the right direction. Researching hasn't been too helpful.
The idea is a user enters the website -- I've created -- and can interact with the chatbot. It's very very basic. I have set up my entities and intents which the agent has been trained and works when I do the demo. I just want to be able to do the same with my website.
I'm using firebase to store users response and agent response.
var config = {
apiKey: "AIzaSyChQLuBa0Owj-Zbnpk8_uMcIYAmFz4dFj8",
authDomain: "chatbot-53c37.firebaseapp.com",
databaseURL: "https://chatbot-53c37.firebaseio.com",
projectId: "chatbot-53c37",
storageBucket: "chatbot-53c37.appspot.com",
messagingSenderId: "434930699010"
};
firebase.initializeApp(config);
var database = firebase.database();
// End Firebase Initialize
===================================================
// Add data to Firebase
var keyWord = "none";
var accessToken = "2d39bfb1417c41a1b31dba35018c1b74"; // Done
var baseUrl = "https://api.dialogflow.com/v1/";
// Stuff we get from the user responding to the chatbot
=========================
var text; // user's input
var name; // user's name
var lang = '&lang=en';
var query = "What time is it?";
var sessionID = Math.floor(Math.random() * 10000000);
var connected = database.ref(".info/connected");
// Get initial message from bot "Hi Whats your name"
============================================================
$.ajax({
type: "GET",
url: baseUrl + "query?v=20150910&e=event_name" + lang + '&query=' +
query + '&sessionId=' + sessionID,
contentType: "application/json; charset=utf-8",
dataType: "json",
}).done(function(response) {
// console.log(response);
// console.log(response.result.fulfillment.speech);
}).fail(function(err) {
throw err;
});
Upvotes: 0
Views: 911
Reputation: 3469
GET and POST queries for Dialogflow require a different type of request:
Also, note that you need to have billing enabled for Firebase functions to perform outgoing network requests.
Sources
Upvotes: 2