Skip to content Skip to sidebar Skip to footer

How To Connect My Chatbot User Interface To APIAI Serverhost Via Python Sdk Or Javascript?

how to exactly connect my chatbot UI which i made it in html and css to API.AI server by using the token provided by API.AI and python sdk api.aienter code here below is the html c

Solution 1:

Take a look at this example for a working case: https://gist.github.com/Dottenpixel/78d9a5487b4aeef32659a017058f75b9

So, using the code below, in your case you'd just need to link the send() function with an ng-click and bind your input field and upon click your sending to API.ai.

Then in API.ai check what you've set your callback URL as, and build an endpoint for processing the replies from API.ai. Let me know if you need an example for that

var accessToken = "<your agent access token>";
var baseUrl = "https://api.api.ai/v1/";

function send() {
  var text = $("#input").val();
  $.ajax({
    type: "POST",
    url: baseUrl + "query?v=20150910",
    contentType: "application/json; charset=utf-8",
    dataType: "json",
    headers: {
      "Authorization": "Bearer " + accessToken
    },
    data: JSON.stringify({
      query: text,
      lang: "en",
      sessionId: "<any random string>"
    }),
    success: function(data) {
      setResponse(JSON.stringify(data, undefined, 2));
    },
    error: function() {
      setResponse("Internal Server Error");
    }
  });
  setResponse("Loading...");
}

Post a Comment for "How To Connect My Chatbot User Interface To APIAI Serverhost Via Python Sdk Or Javascript?"