1. Go to this page and download the library: Download silasrm/chat-api library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
use Illuminate\Notifications\Notification;
use Silasrm\ChatApi\ChatApiMessage;
use Silasrm\ChatApi\ChatApiChannel;
class OrderCreated extends Notification
{
public function via($notifiable): array
{
return [
ChatApiChannel::class,
];
}
public function toRocketChat($notifiable): ChatApiMessage
{
return ChatApiMessage::create('John Doe create a new order with value US$ 50.0')
->to('NNNNNNNNNNNNNN'); // Phone number with country code
}
}
public function routeNotificationForChatApi(): string
{
return $this->phone;
}
public function toChatApi($notifiable)
{
return ChatApiMessage::create('Test message')
->to('NNNNNNNNNNNNNN') // Phone number with country code
->attachments([
// url (for remote) or path (for local), file
ChatApiAttachment::create()->url('test'),
ChatApiAttachment::create(['url' => 'test']),
new ChatApiAttachment(['url' => 'test']),
['url' => 'test']
]);
}