简体   繁体   中英

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

"Call to a member function send() on null" in file vendor\signalwire\signalwire\src\Relay\Connection.php

$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.

So with the use of this event handler, you can resolve the bug "Call to a member function send() on null" in the file.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM