DEV Community

Cover image for Create Chatbot in PHP using Twilio Autopilot
Chetan Rohilla
Chetan Rohilla

Posted on • Updated on • Originally published at

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:

  1. 24/7 Customer Support or Customer Service with ChatBots
  2. Booking Tickets with ChatBots
  3. Finding Products with ChatBots
  4. Process and Exchange Requests with ChatBots
  5. Confirm Orders And Track Shipping with ChatBots
  6. Collect Customer Feedback with ChatBots
  7. Assign Customer Requests with ChatBots
  8. Generate Leads with ChatBots
  9. Build Email Lists with ChatBots
  10. Simplify Pricing with ChatBots
  11. Promote Products with ChatBots
  12. Improve your Marketing with ChatBots
  13. Quizzes, Promotions with ChatBots
  14. 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


// Update the path below to your autoload.php,

require_once 'vendor/autoload.php';

use Twilio\Rest\Client;


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

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

  $assistantID = "UA95260d662422f2c10da3bc5cf5b4c51456a5";

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

  /*update task actions*/
  $task_actions = $twilio->autopilot->v1->assistants($assistantID)
   "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",

  /*update task actions*/

/*get assistants*/
Enter fullscreen mode Exit fullscreen mode

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.

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

Please like share and give positive feedback to motivate me to write more.

For more tutorials please visit my website

Happy Coding:)

Top comments (0)