Create Chatbot in PHP using Twilio Autopilot

In this tutorial, we will create chatbot in php using Twilio Autopilot. Here we can have Whatsapp Bot which is a Chatbot. It automates our chat system using the predefined tasks and actions. It is a type of chatbot, which is a computer program that processes human conversation (either written or spoken). ChatBot allows humans to interact with digital devices, like they were communicating with a real person.

Where ChatBots mostly using:

  • 24/7 Customer Support or Customer Service with ChatBots
  • Booking Tickets with ChatBots
  • Finding Products with ChatBots
  • Process and Exchange Requests with ChatBots
  • Confirm Orders And Track Shipping with ChatBots
  • Collect Customer Feedback with ChatBots
  • Assign Customer Requests with ChatBots
  • Generate Leads with ChatBots
  • Build Email Lists with ChatBots
  • Simplify Pricing with ChatBots
  • Promote Products with ChatBots
  • Improve your Marketing with ChatBots
  • Quizzes, Promotions with ChatBots
  • Create Personal Shopping Assistants with ChatBots

Let’s start and create your first chatbot using php.

Here, we will use twilio autopilot which will help us to create whatsapp bot or chatbot.

Follow the steps given below to create chatbot

<?php

// Update the path below to your autoload.php,
require_once 'vendor/autoload.php';

use Twilio\Rest\Client;

$TWILIO_ACCOUNT_SID="AC27f24a3df2854TR4f2fa81fc0668f82b024f8";
$TWILIO_AUTH_TOKEN="cd60eb6f966FDd56e8a117a6efabc550aeeed";

$sid = $TWILIO_ACCOUNT_SID;
$token = $TWILIO_AUTH_TOKEN;
$twilio = new Client($sid, $token);

/*get assistants*/
$assistant = $twilio->autopilot->v1->assistants
->create();
if ($assistant) {

  $assistantID = "UA95260d662422f2c10da3bc5cf5b4c51456a5";

  /*create tasks*/
  $taskID = "UDc0141556e66f4965fa2a634bef16fe4dd36a";
  /*create tasks*/

  /*update task actions*/
  $task_actions = $twilio->autopilot->v1->assistants($assistantID)
  ->tasks($taskID)
  ->taskActions()
  ->update([
   "actions" => [
     "actions" => [
      [
        "collect" => [
          "name" => "collect_comments",
          "questions" => [
            [
              "question" => "What is your name?",
              "name" => "user_name"
            ],
            [
              "question" => "What is your date of birth",
              "name" => "user_dob"
            ]
          ],
          "on_complete" => [
            "redirect" => [
              "uri" => "task://question_complete",
            ]
          ]
        ]
      ]
    ]
  ]
]
);

  print($task_actions);
  /*update task actions*/

}
/*get assistants*/

In the above code, you will need a twilio account sid and twilio auth token. Create SID and Auth Token here. Now you will need a assistant id which you find under your bots list as SID. Now create a tasks and replace with your task id in above code. See the image given below. If unable to find task id you can right click and find id there. We have used some twilio autopilot actions.

whatsapp bot twilio

For Testing you will also get a testing twilio number here.

That’s it now you can Create Chatbot in PHP using Twilio Autopilot.

For More Tutorials visit here.

Recommended

How to Create Multiple Parameters Dynamic Routes in Laravel

Laravel 8 Multiple Database and Resource Routes with Controllers

How to read feeds in PHP

How to secure form submission in PHP

If you like this, share this.

Follow us on FacebookTwitterTumblrLinkedIn.