格式将ajax请求发送到chatbase(API.AI)

时间:2017-06-28 22:38:41

标签: ajax chatbot dialogflow chatbase

这是一个格式示例:

请求网址[POST]: https://chatbase.com/api/message

发送代理消息:
请求机构:

{
  "api_key": "49448d10-8ca6-4195-8442-2c95b7f1f40c",
  "type": "agent",
  "user_id": "00124248149764",
  "time_stamp": "1481333024000",
  "platform": "kik",
  "message": "I love kittens!",
  "not_handled": true
}

响应:

{
  "message_id": "6150732209437924",
  "status": 200
}

请帮忙!

1 个答案:

答案 0 :(得分:0)

我使用这个要点建立了一个聊天机器人。试试这个:

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({ q: text, lang: "en" }),
                success: function(data) {
                    setResponse(JSON.stringify(data, undefined, 2));
                },
                error: function() {
                    setResponse("Internal Server Error");
                }
            });
            setResponse("Loading...");
        }

检查此要点以获取完整代码。 https://gist.github.com/artemgoncharuk/b31b6a656c954a2866e8