我尝试使用 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));
}
答案 0 :(得分:1)
您需要在 to
/recipient
前加上 whatsapp:
以表明您要发送到 WhatsApp 号码。
Twilio 抱怨您试图从 WhatsApp 号码向普通电话号码发送消息:
from
:+123456789
-> to
:whatsapp:+198765432
- 不允许from
:whatsapp:+123456789
-> to
:+198765432
- 不允许from
:+123456789
-> to
:+198765432
- 允许from
:whatsapp:+123456789
-> to
:whatsapp:+198765432
- 允许