Live chat and bot on website - ChatAndBot ChatAndBot

How to connect to chatbot API

Description

Our service provides API access to connect third-party applications to the chatbot. Connecting via API has some limitations: first, there is no saving of chats, and second, you can't set "Actions, if there no operators and answers".

To send the question to the bot, use a POST request to https://chatandbot.com/api/ with the following parameters:

1. test="-1" - constant
2. bid - constant (The value can be found in the settings of the bot)
3. key- constant (This is the access key to the robot. The value can be found in the bot's settings. To avoid unauthorized access, keep it in secret.)
4. pid="0000000000" - initial value (To continue the dialog you must rewrite after each answer. The value "0000000000" means the beginning of a new dialog)
5. ask="" - your question

As a response comes the text in JSON format with two parameters:

1. reply - chat bot reply
2. pid-the new dialog ID to overwrite the pid

If the robot has no answer or if you have exceeded of the tariff limits then reply="" , pid=""

jQuery Example

1. Create an HTML form with one button and two text fields.
       <input type="text" id="reply" style="width:100px;">
           
       <input type="text" id="question" style="width:100px;">
           
       <input style="width:100px;" type="button" id="send_button" value="click!">
           
        
2. JS code
       <script type="text/javascript">
            var test_global='-1';
            var bid_global=1234567891234567; /*from the bot's settings in your personal account */
            var key_global='edac7ab83b0f8bf29b4284ae4c8e6f33526f3371'; /*from the bot's settings in your personal account */
            var pid_global='0000000000';
            
            var reply=$('#reply'); /*response field*/
            var question = $('#question'); /*question field*/
            var send_button = $('#send_button'); /*button to send a request*/



            /*handle the button click*/
            send_button.click(function () {
               var result=getApiAnwser(question.val());/*send a question to the robot*/
               var getobj= $.parseJSON(result); /*turn the response into a JSON object*/
               reply.val(getobj.reply); /*get the robot's response from the object*/
               pid_global=getobj.pid; /*overwrite pid*/
            });
            
           function getApiAnwser(ask) {
             var ret;
             $.ajax({
               dataType: "text",
               type: "POST",
               url: "https://chatandbot.com/api/",
               async: false,
               data: {test: test_global, pid: pid_global, ask: ask, bid: bid_global, key: key_global},
               success: function (result) {
                        ret = result;
                    }
                });
             return ret;
            }

        </script>