[英]getting error "Call to a member function send() on null" while sending sms through Signalwire api using laravel
Using relay client api to send sms from Signalwire it gives an error message使用中继客户端 api 从 Signalwire 发送短信时会出现错误消息
"Call to a member function send() on null" in file vendor\signalwire\signalwire\src\Relay\Connection.php
文件 vendor\signalwire\signalwire\src\Relay\Connection.php 中的“调用成员 function send() on null”
$this->_ws->send($msg->toJson()); $this->_ws->send($msg->toJson());
I am using these code below我在下面使用这些代码
use SignalWire\Relay\Client;
$client = new Client(['project' =>'project_id','token' => 'token_id']);
$params = [
'context' => 'office',
'from' => '+1++++',
'to' => '+1++++',
'body' => 'Welcome at SignalWire!'
];
Log::info('Sending SMS..');
$client->messaging->send($params)->done( function ($sendResult){
if ($sendResult->isSuccessful()) {
Log::info('SMS queued successfully!');
echo 'success';
} else {
Log::warning('Error sending SMS!');
echo 'error';
}
});
Attach an event handler for sending messages.附加用于发送消息的事件处理程序。
$client->on('signalwire.ready', function($client) use ($params){
$client->messaging->send($params)->done( function ($sendResult)
if ($sendResult->isSuccessful()) {
echo "Message ID: " . $sendResult->getMessageId();
} else {
echo 'error';
}
});
})->on('signalwire.error', function(\Exception $error) {
echo "Error";
});
signalwire.ready
method indicates that the session has been established and all other methods can now be used. signalwire.ready
方法表示 session 已经建立,现在可以使用所有其他方法。
So with the use of this event handler, you can resolve the bug "Call to a member function send() on null" in the file.因此,使用此事件处理程序,您可以解决文件中的错误“Call to a member function send() on null”。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.