Twilio Laravel 不在同一频道中发送 Whatsapp 消息

Twilio Laravel Send Whatsapp Message not in same channel

我尝试使用 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));
}

您需要在 to/recipient 前加上 whatsapp: 前缀,以表明您要发送到 WhatsApp 号码。

Twilio 抱怨您正在尝试从 WhatsApp 号码向普通 phone 号码发送消息:

  • from: +123456789 -> to: whatsapp:+198765432 - 不允许
  • from: whatsapp:+123456789 -> to: +198765432 - 不允许
  • from: +123456789 -> to: +198765432 - 允许
  • from: whatsapp:+123456789 -> to: whatsapp:+198765432 - 允许