【发布时间】:2021-03-16 07:02:49
【问题描述】:
我尝试使用 twilio 从 php(laravel) 创建 MEssage, 当我发送消息并且系统回复它时,
但是当我想直接从系统发送消息时我遇到了一些问题,我从 POSTMAN 调用我的服务但它总是会显示这样的错误通知
Twilio\Exceptions\RestException: [HTTP 400] Unable to create record: From(whatsapp:+14155238886) and To(+6281210357927) addresses should be of the same channel. in file D:\WelldyNew\LARAVUE\pwi\vendor\twilio\sdk\src\Twilio\Version.php on line 88
是因为我从 POSTMAN 调用 api 吗?那么我如何通过调用我的 api 来发送消息?
public function sendTest(Request $request){
$from = $request->input('From');
$body = $request->input('Body');
$this->sendWhatsAppMessage($body,$from);
return;
}
public function sendWhatsAppMessage(string $message, string $recipient)
{
$twilio_whatsapp_number = getenv('TWILIO_WHATSAPP_NUMBER');
$account_sid = getenv("TWILIO_SID");
$auth_token = getenv("TWILIO_AUTH_TOKEN");
$client = new Client($account_sid, $auth_token);
return $client->messages->create($recipient, array('from' => "whatsapp:$twilio_whatsapp_number", 'body' => $message));
}
【问题讨论】:
标签: laravel twilio twilio-api twilio-php