PHP code example of thinkstudeo / textlocal-notification-channel

1. Go to this page and download the library: Download thinkstudeo/textlocal-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/ */

    

thinkstudeo / textlocal-notification-channel example snippets


...
'textlocal' => [
    'url' => 'https://api.textlocal.com/send/'	//or 'https://api.textlocal.in/send/ - for India

    //Textlocal Transactional Account
    'transactional' => [
        'apiKey' => env('TEXTLOCAL_TRANSACTIONAL_KEY'),
        'from' => env('TEXTLOCAL_TRANSACTIONAL_FROM', 'TXTLCL')
	],

    //Textlocal Promotional Account
    'promotional' => [
        'apiKey' => env('TEXTLOCAL_PROMOTIONAL_KEY'),
        'from' => env('TEXTLOCAL_PROMOTIONAL_FROM', 'TXTLCL')
    ]
],
...

use Illuminate\Notifications\Notification;
use NotificationChannels\Textlocal\TextlocalChannel;
use NotificationChannels\Textlocal\TextlocalMessage;

class SendBlackFridaySaleAnnouncement extends Notification
{
    /**
     * Get the notification's delivery channels.
     *
     * @param  mixed  $notifiable
     * @return array
     */
    public function via($notifiable)
    {
        return [TextlocalChannel::class];
    }

    /**
     * Get the Textlocal / SMS representation of the notification.
     *
     * @param  mixed  $notifiable
     * @return NexmoMessage
     */
    public function toTextlocal($notifiable)
    {
        return (new TextlocalMessage())
            //Required
            // To send sms via your Textlocal promotional account
            //or transactional() to sent via Textlocal transactional account
            ->promotional()

            //Optional
            //If you don't provide a from, it will pick up the value from the config
            ->from('TXTLCL')

            //Optional
            //If you want to send a copy of the sms to another number eg an Admin
            ->cc('914545454545')

            //Required
            ->content('We are running a BlackFriday sale from tomorrow for 3 days with 40% off. Hurry !!! Grab the opportunity!');
    }
}

use Illuminate\Notifications\Notification;
use NotificationChannels\Textlocal\TextlocalChannel;
use NotificationChannels\Textlocal\TextlocalMessage;

class SendLoginOtp extends Notification
{
    /**
     * Get the notification's delivery channels.
     *
     * @param  mixed  $notifiable
     * @return array
     */
    public function via($notifiable)
    {
        return [TextlocalChannel::class];
    }

    /**
     * Get the Textlocal / SMS representation of the notification.
     *
     * @param  mixed  $notifiable
     * @return NexmoMessage
     */
    public function toTextlocal($notifiable)
    {
        return (new TextlocalMessage())
            //Required
            // To send sms via your Textlocal transactional account
            //or promotional() to sent via Textlocal promotional account
            ->transactional()

            //Optional
            //If you don't provide a from, it will pick up the value from the config
            ->from('TXTLCL')

            //Optional
            //If you want to send a copy of the sms to another number eg an Admin
            ->cc('914545454545')

            //Required
            //When sending through Textlocal transactional account, the content must conform to one of your approved templates.
            ->content('Your OTP for Application is 234567. It is valid for the next 10 minutes only.');
    }
}