skip to Main Content

I am creating a facebook bot i used chatfuel to create the bot,i send all the replies of the user to my server using Json API because” i want to pass data retrieved from the user’s message to my Json API to get/add data from/to my database
for example:
user reply:
my name is Peter
i want to send “Peter” to my api and add it in my database using get or post request “
i was told here to use wit.ai:
https://community.chatfuel.com/t/send-variables-from-the-users-message-to-the-json-api/4406
I would like to link my php server which is connected to my database with wit.ai to create the AI for my Bot.
I need detailed steps to follow or a simple template.
Any simple information would help a lot
Thanks

2

Answers


  1. It looks like you want to use Wit.ai for Entity extraction. The entity being the contact’s name. In your example, this will be Peter.

    Wit have an HTTP API you can use.

    https://wit.ai/docs/http/20160526

    First, create an app in Wit. Then have your PHP application pass on the message to the Wit API.

    curl 
     -H 'Authorization: Bearer <BEARER_TOKEN>' 
     'https://api.wit.ai/message?v=20170220&q=My%25name%25is%25Peter'
    

    You can get the ‘BEARER_TOKEN’ from the app settings.

    The API will return JSON output with the entity and a confidence score.

    {
      "msg_id" : "c811ca24-4322-4a6e-b251-192ee59a8b83",
      "_text" : "My%name%is%Peter",
      "entities" : {
        "contact" : [ {
          "confidence" : 0.8265228299921754,
          "type" : "value",
          "value" : "Peter",
          "suggested" : true
        } ]
      }
    

    You should then be able to take the entity from the JSON output and add to your database.

    Login or Signup to reply.
  2. To follow on from Bcf Ant’s comment above – here’s how to do the call in PHP. Put the string you want to parse in $input_utterance and replace XXXXXXXXXXX with your token ID:

    $witRoot = "https://api.wit.ai/message?";
    $witVersion = "20170221";
    
    $witURL = $witRoot . "v=" . $witVersion . "&q=" . $input_utterance;
    
    $ch = curl_init();
    $header = array();
    $header[] = "Authorization: Bearer XXXXXXXXXX”;
    
    curl_setopt($ch, CURLOPT_URL, $witURL);
    curl_setopt($ch, CURLOPT_POST, 1);  //sets method to POST (1 = TRUE)
    curl_setopt($ch, CURLOPT_HTTPHEADER,$header); //sets the header value above - required for wit.ai authentication
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); //inhibits the immediate display of the returned data
    
    $server_output = curl_exec ($ch); //call the URL and store the data in $server_output
    
    curl_close ($ch);  //close the connection
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search