Читали ли вы их документацию веб-хуков?
https://www.twilio.com/docs/chat/webhook-events
Вот пример кода для захвата сообщений и событий канала и их сохранения в вашей базе данных.
<?php
// Keep in mind, its just a sample code, you need to make it secure on your end
// Capture the event type to identiy which event has occured
$event_type = $_POST['EventType'];
switch($event_type){
case 'onChannelAdded':
$sid = $_POST['ChannelSid']; // The SID of the newly added Channel
$attributes = $_POST['Attributes']; // The arbitrary JSON structure of the channel
$date_created = $_POST['DateCreated']; // The date of channel creation
$created_by = $_POST['CreatedBy']; // The identity of the user that created a channel
$friendly_name = $_POST['FriendlyName']; // The friendly name of the channel, if set
$unique_name = $_POST['UniqueName']; // The unique name of the channel, if set
$channel_type = $_POST['ChannelType']; // The Channel type. Either private or public
// INSERT a new channel into the channels table
break;
case 'onMessageSent':
$sid = $_POST['MessageSid']; // The Message SID of the new Message
$index = $_POST['Index']; // The index of the Message within the Channel Message list
$channel_sid = $_POST['ChannelSid']; // Channel SID identifier of the Channel the Message is being sent to
$body = $_POST['Body']; // The body of message
$attributes = $_POST['Attributes']; // Stringified JSON structure. This can be null if attributes are not present in message entity
$sender = $_POST['From']; // The author of the message
$date_created = $_POST['DateCreated']; // The timestamp of message creation
// INSERT a new message into the chat table
break;
}
?>
Этот код служитваш обработчик событий webhook POST.
Вам необходимо добавить путь к этому файлу в конфигурацию webhook консоли twilio.