PHP code example of felipedamacenoteodoro / laravel-whatsapp-notification-channel

1. Go to this page and download the library: Download felipedamacenoteodoro/laravel-whatsapp-notification-channel 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/ */

    

felipedamacenoteodoro / laravel-whatsapp-notification-channel example snippets


# config/whatsapp-notification-channel/services.php

'whatsapp-bot-api' => [
        'whatsappSessionFieldName' => env('WHATSAPP_API_SESSION_FIELD_NAME', ''), //Session field name
        'whatsappSession' => env('WHATSAPP_API_SESSION', ''), // session value
        'base_uri' => env('WHATSAPP_API_BASE_URL', ''), //  Your venom base url api
        'mapMethods' => [ 
            'sendMessage' => 'sendText',
            'sendDocument' => 'sendFile',
        ], /* If you want to change the methods that will be called in the api, you can map them here, example: sendMessage will be replaced by the sendText method of the api */
    ],

use NotificationChannels\Whatsapp\WhatsappMessage;
use Illuminate\Notifications\Notification;

class InvoicePaid extends Notification
{
    public function via($notifiable)
    {
        return ["whatsapp"];
    }

    public function toWhatsapp($notifiable)
    {
        $url = url('/invoice/' . $this->invoice->id);

        return WhatsappMessage::create()
            // Optional recipient user id.
            ->to($notifiable->whatsapp_number)
            // Markdown supported.
            ->content("Hello there!\nYour invoice has been *PAID*")

            // (Optional) Blade template for the content.
            // ->view('notification', ['url' => $url])
    }
}

public function toWhatsapp($notifiable)
{
    return WhatsappFile::create()
            ->to($notifiable->whatsapp_number) // Optional
            ->content('Audio') // Optional Caption
            ->audio('/path/to/audio.mp3');
}

public function toWhatsapp($notifiable)
{
    return WhatsappFile::create()
        ->to($notifiable->whatsapp_number) // Optional
        ->content('Awesome *bold* text')
        ->file('/storage/archive/6029014.jpg', 'photo'); // local photo

        // OR using a helper method with or without a remote file.
        // ->photo('https://file-examples-com.github.io/uploads/2017/10/file_example_JPG_1MB.jpg');
}

public function toWhatsapp($notifiable)
{
    return WhatsappFile::create()
        ->to($notifiable->whatsapp_number) // Optional
        ->content('Did you know we can set a custom filename too?')
        ->document('https://file-examples-com.github.io/uploads/2017/10/file-sample_150kB.pdf', 'sample.pdf');
}

public function toWhatsapp($notifiable)
{
    return WhatsappLocation::create()
        ->latitude('40.6892494')
        ->longitude('-74.0466891');
}

public function toWhatsapp($notifiable)
{
    return WhatsappFile::create()
        ->content('Sample *video* notification!')
        ->video('https://file-examples-com.github.io/uploads/2017/04/file_example_MP4_480_1_5MG.mp4');
}

public function toWhatsapp($notifiable)
{
    return WhatsappFile::create()
        ->content('Woot! We can send animated gif notifications too!')
        ->animation('https://sample-videos.com/gif/2.gif');

        // Or local file
        // ->animation('/path/to/some/animated.gif');
}

/**
 * Route notifications for the Whatsapp channel.
 *
 * @return int
 */
public function routeNotificationForWhatsapp()
{
    return $this->whatsapp_number;
}

use Illuminate\Support\Facades\Notification;

Notification::route('whatsapp', 'WHATSAPP_SESSION')
            ->notify(new InvoicePaid($invoice));

use Illuminate\Support\Facades\Notification;

// Recipients can be an array of numbers or collection of notifiable entities.
Notification::send($recipients, new InvoicePaid());
bash
php artisan vendor:publish --tag=whatsapp-notification-channel-config