1

I'm doing a chatbot based project. I came across Chatbase and I wanted to implement chatbase to analyse the data more indept I get from my chatbot. However, I am confused as to how to write the post method to the chatbase api and keeps receiving error 405 or 400. I don't have much experience in writing ajax requests so most probably the problem might be with the format of the code. If anyone is willing to help me out, I would really appreciate it. Thanks

Code for reference:

function chatbaseInput() {
$.ajax({
    type: "POST",
    url: chatbaseURL,
    contentType: "charset=utf-8",
    dataType: "json",
    headers: {
        "Access-Control-Allow-Origin": "website link"
    },
    data: JSON.stringify({
        api_key: "apikey",
        type: "user",
        user_id: "140012004300",
        time_stamp: 1516765680000,
        platform: "Website",
        message: "Default Welcome Intent",
        intent: "Welcome Intent",
        version: "1.0"
    }),
    success: function (data) {
        setResponse("Chatbase works!");
    },
    error: function () {
        setResponse("Chatbase not working");
    }

});

}

1 Answers1

1

Chatbase requests are meant to be sent from your server, they do not accept calls from a browser (CORS is not enabled).

I did the exact same thing before I discovered the same as you. We now proxy our calls via the server.

Here is the link where they mention this: https://discuss.api.ai/t/chatbase-integration-and-api-ai/9966/15

PA Knudsen
  • 13
  • 1
  • 3
  • Any idea how this could be done?I am not so good with servers and such. My project is just a standard website(html,css,javascript) therefore I don't think I have a server for it – Brandon Christopher Jan 25 '18 at 01:22
  • Most hosting solutions have a serverside language available. Ie. C# (.NET), NodeJS, PHP or Python. But if you have created a "pure" HTML page you might not have that, and then you won't be able to relay the data to Chatbase servers. It seems like you already are somewhat familiar with Javascript, then I think NodeJS would be a good option for you as it uses Javascript on the server too. Can be run almost anywhere. https://nodejs.org/ And then you could use Chatbases NodeJS lib. to relay the message. https://github.com/google/chatbase-node Hope you find a solution! – PA Knudsen Jan 25 '18 at 12:05