如何在我的 php 应用程序中存储来自 twilio 的发送和传入消息?
How to store send and incomming messages from twilio in my php application?
我需要在我的 php appication.I 阅读 twilio 文档中存储传入消息并将消息发送到我的数据库,但我找不到任何资源 requirement.Can 任何人都可以帮助我那。
您阅读过他们的 webhooks 文档了吗?
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 事件处理程序。
您需要将此文件的路径添加到您的 twilio 控制台 webhook 配置中。
我需要在我的 php appication.I 阅读 twilio 文档中存储传入消息并将消息发送到我的数据库,但我找不到任何资源 requirement.Can 任何人都可以帮助我那。
您阅读过他们的 webhooks 文档了吗?
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 事件处理程序。
您需要将此文件的路径添加到您的 twilio 控制台 webhook 配置中。