PHP code example of spits-online / laravel-bird-api

1. Go to this page and download the library: Download spits-online/laravel-bird-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/ */

    

spits-online / laravel-bird-api example snippets


use Spits\Bird\Services\ContactService;

$birdContacts = app(new ContactService())->index(limit: 20, reverse: true);

use Spits\Bird\Services\ContactService;

$birdContact = app(new ContactService())->show('bird-contact-id-123');

use Spits\Bird\Models\Contact;
use Spits\Bird\Enums\IdentifierKey;
use Spits\Bird\Services\ContactService;

$contact = (new Contact())
    ->displayName('John Doe')
    ->phoneNumber('+12345678901')
    ->emailAdress('[email protected]');

$response = (new ContactService())->createOrUpdate($contact, IdentifierKey::PHONE_NUMBER);

use Spits\Bird\Services\ContactService;

$response = (new ContactService())->delete('contact-id-123');

if ($response === true) {
    // Successfully deleted the contact
    dd('Contact deleted successfully.');
} else {
    // Handle error
    dd($response);
}

use Spits\Bird\Models\Contact;

$contact = (new Contact())
    ->displayName('Jane Doe')
    ->phoneNumber('+98765432103')
    ->emailAdress('[email protected]')
    ->attribute('company', 'Acme Corp');

// The contact can then be passed to the `ContactService` for API interaction

use Illuminate\Notifications\Notification;
use Spits\Bird\Messages\SMSMessage;
use Spits\Bird\Notifications\Channels\SMSChannel;

class OrderNotification extends Notification
{
    public function via(): array
    {
        return [ SMSChannel::class ];
    }

    public function toSMS($notifiable): SMSMessage
    {
        $contact = (new Contact())
            ->displayName('Jane Doe')
            ->phoneNumber('+98765432103')
            ->emailAdress('[email protected]')
            ->attribute('company', 'Acme Corp');
        
        return (new SMSMessage())
            ->text('Your order has been shipped!')
            ->toContact($contact);
    }
}


'whatsapp' => [
    'foo_template' => [
        'template_project_id' => `template_project_id`,
        'template_version' => `template_version`,
        'template_locale' => `template_locale`,
    ],
]



namespace App\Notifications;

use Illuminate\Notifications\Notification;
use Spits\Bird\Models\Messages\WhatsappMessage;
use Spits\Bird\Notifications\Channels\WhatsappChannel;

class WhatsappNotification extends Notification
{
    public function __construct(
        public string $content
    )
    {
        $this->setChannels([
            WhatsappChannel::class
        ]);
    }

    public function toWhatsapp($notifiable): WhatsappMessage {
        $message = new WhatsappMessage(
            config('bird.templates.whatsapp.foo_message.template_project_id'),
            config('bird.templates.whatsapp.foo_message.template_version'),
            config('bird.templates.whatsapp.foo_message.template_locale'),
            receiver: '+31'.$notifiable->phone_number,
            templateVariables: [
                'variables' => `set in template`
                ]
        );
        return $message;
    }
}


use Illuminate\Support\Facades\Notification;

Notification::send($user, new OrderNotification());
bash
   php artisan vendor:publish --tag="bird-config"