1. Go to this page and download the library: Download spits-online/laravel-bird 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/ */
spits-online / laravel-bird example snippets
use Illuminate\Notifications\Notification;
use SpitsOnline\Bird\Channels\SmsChannel;
use SpitsOnline\Bird\Messages\SmsMessage;
class OrderShipped extends Notification
{
public function via(object $notifiable): array
{
return [SmsChannel::class];
}
public function toBirdSms(object $notifiable): SmsMessage
{
return SmsMessage::create('Your order has shipped!');
}
}
use SpitsOnline\Bird\Bird;
use SpitsOnline\Bird\Messages\SmsMessage;
$bird = Bird::fromConfig([
'access_key' => 'other-key',
'workspace_id' => 'other-workspace',
'channels' => ['sms' => 'other-sms-channel'],
]);
$bird->send(SmsMessage::create('Hi!')->to('+31612345678'));
class User extends Authenticatable
{
use Notifiable;
public function routeNotificationForBird(): string
{
return $this->phone_number; // international format: +31612345678
}
}
use SpitsOnline\Bird\Data\Identifier;
SmsMessage::create('Your order has shipped!')
->to('+31612345678', '+31687654321');
SmsMessage::create('Your order has shipped!')
->to(Identifier::phone('+31612345678'));
use SpitsOnline\Bird\Channels\WhatsAppChannel;
use SpitsOnline\Bird\Messages\Template;
use SpitsOnline\Bird\Messages\WhatsAppMessage;
public function via(object $notifiable): array
{
return [WhatsAppChannel::class];
}
public function toBirdWhatsApp(object $notifiable): WhatsAppMessage
{
return WhatsAppMessage::template(
Template::create(
projectId: 'your-project-id',
parameters: ['name' => $notifiable->first_name],
locale: 'nl',
),
);
}
WhatsAppMessage::body([
'type' => 'text',
'text' => ['text' => 'Thanks, we received your reply.'],
]);
public function via(object $notifiable): array
{
return [SmsChannel::class, WhatsAppChannel::class];
}
public function toBirdSms(object $notifiable): SmsMessage
{
return SmsMessage::create('Your order has shipped!');
}
public function toBirdWhatsApp(object $notifiable): WhatsAppMessage
{
return WhatsAppMessage::template(
Template::named('order_shipped', ['name' => $notifiable->first_name]),
);
}
use SpitsOnline\Bird\Facades\Bird;
use SpitsOnline\Bird\Messages\SmsMessage;
$sent = Bird::send(
SmsMessage::create('Your code is 123456')->to('+31612345678'),
);
$sent->id; // Bird's message id
$sent->status; // "accepted"
$sent->raw; // the full answer from Bird
use SpitsOnline\Bird\Data\Identifier;
use SpitsOnline\Bird\Facades\Bird;
$contact = Bird::contacts()->upsert('+31612345678', [
'firstName' => 'Jane',
'lastName' => 'Doe',
]);
$contact = Bird::contacts()->upsert(Identifier::email('[email protected]'), ['firstName' => 'Jane']);
$contact = Bird::contacts()->find($contactId);
$contact->id; // Bird's contact id
$contact->displayName; // "Jane Doe"
$contact->phoneNumber; // "+31612345678"
$contact->emailAddress; // "[email protected]" or null
$contact->attributes; // ['firstName' => 'Jane', ...]
$contact->raw; // the full answer from Bird
Bird::contacts()->delete($contactId);
$page = Bird::contacts()->list(limit: 100);
foreach ($page->contacts as $contact) {
// ...
}
$next = Bird::contacts()->list(
limit: 100,
pageToken: $page->nextPageToken, // null on the last page
);
use SpitsOnline\Bird\Enums\IdentifierKey;
$message->channel(); // "sms" or "whatsapp", its key in `bird.channels`
$message->recipients(); // list<Identifier>
$message->recipients()[0]->key === IdentifierKey::PHONE_NUMBER;
$message->hasRecipients(); // false until a recipient is set
$message->toArray(); // the request body Bird gets
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.