First you need to pull in the Twilio Driver.
composer require botman/driver-twilio
Then load the driver before creating the BotMan instance (only when you don't use BotMan Studio):
DriverManager::loadDriver(\BotMan\Drivers\Twilio\TwilioVoiceDriver::class);
DriverManager::loadDriver(\BotMan\Drivers\Twilio\TwilioMessageDriver::class);
// Create BotMan instance
BotManFactory::create($config);
Or if you use BotMan Studio:
php artisan botman:install-driver twilio
{callout-info} ngrok is a great tool to create a public URL for your local application. If you use Laravel Valet, you can create it with "valet share" as well.
To connect BotMan with Twilio, you first need to create a Twilio account here and buy a phone number, which is capable of sending SMS/MMS or making phone calls.
Place your Twilio auth token in your BotMan configuration. If you use BotMan Studio, you can find the configuration file located under config/botman/twilio.php
.
If you dont use BotMan Studio, add these line to $config array that you pass when you create the object from BotManFactory.
'twilio' => [
'token' => 'YOUR-TWILIO-TOKEN-HERE',
]
To let Twilio send your chatbot a notifications when you receive an incoming call or receive a SMS, you have to register the URL where BotMan is running at, with Twilio.
You can do this on the configuration page of your phone numbers.
If you want to make use of Twilio's voice services: Place your webhook URL in the input field: A CALL COMES IN
.
If you want to make use of Twilio's SMS/messaging services: Place your webhook URL in the input field: A MESSAGE COMES IN
.
To let your chatbot react to incoming phone calls, you can listen for the TwilioVoiceDriver::INCOMING_CALL
event.
$botman->on(TwilioVoiceDriver::INCOMING_CALL, function($payload, $bot) {
$bot->startConversation(new ExampleConversation);
});
If you want total control over the output of your Twilio based chatbot, you can also directly reply any TwiML response using the official Twilio PHP SDK.
$twiml = new Twiml();
$twiml->record(['timeout' => 10, 'transcribe' => 'true']);
$bot->reply($twiml);
This is a list of features that the driver supports. If a driver does not support a specific action, it is in most cases a limitation from the messaging service - not BotMan.
Feature | Supported? |
---|---|
Question-Buttons | ❌ |
Image Attachment | ✅ |
Video Attachment | ✅ |
Audio Attachment | ✅ |
Location Attachment | ❌ |