JSON API


The JSON API enables you to integrate your backend into your chat bots on Floatbot.

The JSON API Item enables you to integrate your backend into your floatbot chatbot

You can send data in multiple formats. Below shows the format of requests and response for sending data using Json API

The JSON API allows your bot to send HTTP GET and POST requests and interpret responses.

It allows you to generate dynamic content and get and set user attributes. If you select POST user attributes get to send in the body of the request. GET adds parameters as a query string.

You can customize JSON API items by assigning names according to your needs. This flexibility allows for easier management and organization of backend integrations within your Floatbot chatbot.

The 'As async' function enables the seamless execution of tasks in your chatbot by allowing it to continue its flow without waiting for API responses, enhancing overall performance and user experience.

JSON-API

Select the request type, enter the URL to call and user attributes to get from the user as shown in the above example. Use the response references to send text, text with button and text with quick reply.

  • The JSON API plugin enables you to integrate your backend into your chatbots on Floatbot.
  • The JSON API plugin enables your bot to send HTTP GET and POST requests and interpret responses

    It allows you to

    • Generate dynamic content
    • Get and set user attributes
    • Redirect users to another block in the bot
    • Create postbacks

    If you select POST user attributes get send in the body of the request. GET adds parameters as a query string.The max. timeout is 10 seconds in both cases.

    In your responses, you can

  • Combine several messages in one answer by sending several dictionaries in the messages array.
  • Use any content type header.
  • Send an empty response to not show the user any dynamic content.

Response Reference

Sending text

Use this response to send text messages.

<? php 
$data['data'][]['text']="Welcometo Floatbot!";
echo json_encode($data);
exit();
?>
Response
{ "data": [ { "text" : "Welcome to Floatbot!" } ] }

 

text with set attributes

 

<?php 
$set_response=array("set_attributes"=>array('error_code'=>"success"),"data"=>array(array("text"=>"Demo For Text With Set Attribute"))); echo json_encode($set_response); exit();
?>
Response
{
  "set_attributes" :
{
"error_code": "success" }, "data": [
{ "text" : "Demo For Text With Set Attribute" } ] }

 

Sending text with button

 

<?php 
$amount="200"; $buttons[]=array('type'=>'url','title'=>"Open link in Bot",'link'=>"<URL>",'target'=>true);
$buttons[]=array('type'=>'url','title'=>"Open link in new tab",'link'=>"<URL>",'target'=>false);
$buttons[]=array('type'=>'buy','title'=>"Pay Now",'price'=>$amount,'invoiceTable'=>array(array('name'=>'price','price'=>$amount)),'currency'=>"INR",'success_api_url'=>"<
PAYMENT_URL>",'success_attributes'=>array('user_id','mobile_no'));
$buttons[]=array('type'=>'flow','title'=>'Flow Redirection','redirect'=>'5c52a1bd734a4e47344fab42'); $set_response= array ( "set_attributes"=>array ( 'error_code'=>"success" ), "data"=> array ( array ( "text"=>"Demo For Text With Button", 'buttons'=>$buttons ) ) ); echo json_encode($set_response); exit(); ?> 
Response

{
  "set_attributes": 
{ "error_code": "success" }, "data": [ { "text": "Demo For Text With Button", "buttons":
[ { "type": "url", "title": "Open link in Bot", "link": "<URL>", "target": true }, { "type": "url", "title": "Open link in new tab", "link": "<URL>", "target": false }, { "type": "buy", "title": "Pay Now", "price": "200", "invoiceTable": [ { "name": "price", "price": "200" } ], "currency": "INR", "success_api_url":"<PAYMENT_URL>", "success_attributes":
[ "user_id","mobile_no" ] }, { "type": "flow", "title": "Flow Redirection", "redirect": "5b751e32bd021579e31f0772" } ] } ]

 

Use below sample code and response for quick reply with attributes

 

<?php 
$types_of_recharge=array("Postpaid Recharge","Prepaid Recharge","DTH Recharge"); $quick_reply=array(); foreach($types_of_recharge as $value) { $quick_reply[]=array("title"=>$value); } $json_data= array ( "set_attributes"=> array ( 'error_code'=>"success" ), "data"=> array ( array ( "text"=>" Please choose from a service below to get started: ", "attribute"=>"recharge_type", "quick_reply"=>$quick_reply, ) ) ); echo json_encode($json_data); exit(); ?>
Response

{
  "set_attributes":
  {
    "error_code": "success"
  },
    "data":
  [
    {
      "text":"Please choose from a service below to get started:",
      "attribute":"recharge_type",
      "quick_reply":
      [
        {
          "title": "Postpaid Recharge"
        },
        {
           "title": "Prepaid Recharge"
        },
        {
           "title":  "DTH Recharge"
        }
      ]
    }
  ]
}

 

Quick Reply With key and value

 

<?php 
$types_of_recharge=array("1"=>"Postpaid Recharge","2"=>"Prepaid Recharge","3"=>"DTH Recharge"); $quick_reply=array(); foreach($types_of_recharge as $key=>$value) { $quick_reply[]=array("title"=>$value,"key"=>$key); } $json_data= array ( "set_attributes"=> array ( 'error_code'=>"success" ), "data"=> array ( array ( "text"=>" Please choose from a service below to get started: ", "attribute"=>"recharge_value,recharge_type", "quick_reply"=>$quick_reply, ) ) ); echo json_encode($json_data); exit(); ?>
Response

{
  "set_attributes": 
{ "error_code": "success" }, "data":
[ { "text":"Please choose from a service below to get started: ", "attribute":"recharge_value,recharge_type", "quick_reply":
[ { "title":"Postpaid Recharge", "key":"key_postpaid" }, { "title":"Prepaid Recharge", "key":"key_prepaid" }, { "title": "DTH Recharge", "key": "key_dth" } ] } ] }

 

Use below sample code and response for Cards

 

<?php 
$result=''; $amount="100"; $new_cards=array(); $cards_iteam=array("example1","example2","exampl3"); $buttons=array(); $k=0; foreach($cards_iteam as $key=>$value) { $k++; if($k==1) { $buttons=array(array('type'=>'buy','title'=>"Pay Now",'price'=>$amount,'invoiceTable'=>array(array('name'=>'price','price'=>$amount)),'currency'=>"INR",'success_api_url'=>"<PAYMENT_URL>",'success_attributes'=>array('user_id','mobile_no'))); } if($k==2) { $buttons=array(array('type'=>'flow','title'=>'Flow Redirection','redirect'=>'5c52a1bd734a4e47344fab42')); } if($k==3) { $buttons=array(array('type'=>'url','title'=>"Open link in Bot",'link'=>"<URL>",'target'=>true)); } $new_cards[]= array ( "title"=>$value, "subtitle"=>"Description for ".$value, "item_url"=>"", "image_url"=>"<IMAGE_URL>", "buttons"=>$buttons ); } //if you want to use load more //$current_page=1; //$new_cards[]=array("type"=>'load_more',"flb_json_card_page_no"=>$current_page + 1); $json_data=array ( "data"=> array ( array ( "cards"=>$new_cards ) ) ); echo json_encode($json_data); exit(); ?>
Response

{
  "data": 
[ { "cards":
[ { "title":"example1", "subtitle":"Description for example1", "item_url":"", "image_url":"<IMAGE_URL>", "buttons":
[ { "type":"buy", "title":"Pay Now", "price":"100", "invoiceTable": [ { "name":"price", "price":"100" } ], "currency":"INR", "success_api_url":"<PAYMENT-URL>", "success_attributes": [ "user_id","mobile_no" ] } ] }, { "title":"example2", "subtitle":"Description for example2", "item_url":"", "image_url": "<IMAGE_URL>", "buttons": [ { "type": "flow", "title": "Flow Redirection", "redirect": "5c52a1bd734a4e47344fab42" } ] }, { "title":"example3", "subtitle":"Description for example3", "item_url":"", "image_url": "<IMAGE_URL>", "buttons": [ { "type": "url", "title": "Open link in Bot", "link": "<URL>" "target": true } ] } ] } ] }