PHP code example of craftsys / msg91-laravel-notification-channel

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

    

craftsys / msg91-laravel-notification-channel example snippets


// along with other services
'msg91' => [
    'key' => env("MSG91_KEY")
]



namespace App\Notifications;

use Illuminate\Notifications\Notification;
use Craftsys\Notifications\Messages\Msg91SMS

class OrderPicked extends Notification
{
  /**
   * Get the notification's delivery channels.
   *
   * @param  mixed  $notifiable
   * @return array
   */
  public function via($notifiable)
  {
    // add "msg91" channel to the channels array
    return ['msg91'];
  }

  /**
   * Get the Msg91 / SMS representation of the notification.
   *
   * @param  mixed  $notifiable
   * @return \Craftsys\Notifications\Messages\Msg91SMS
   */
  public function toMsg91($notifiable)
  {
    return (new Msg91SMS)
      ->flow('your_flow_id_here')
      // you can also set variable's values for your flow template
      // assuming you have ##order_id## variable in the flow
      ->variable('order_id', $notifiable->latestOrder->id);
  }

}

// your Notification
public function toMsg91($notifiable)
{
    return (new \Craftsys\Notifications\Messages\Msg91SMS)
        ->flow("your_flow_id");
}

// with variables
public function toMsg91($notifiable)
{
    return (new \Craftsys\Notifications\Messages\Msg91SMS)
        ->flow("your_flow_id")
        ->variable('name', $notifiable->name)
        ->variable('status', "Overdue");
}

// your Notification
public function toMsg91($notifiable)
{
    return (new \Craftsys\Notifications\Messages\Msg91OTP)
        ->from('12123');
        // ->otp(12123) // set a custom otp
        // ->resend() // if this is a resend otp notification
}

$otp_to_verify = 112312;
Msg91::otp($otp_to_verify)->to(919999999998)->verify();

class User {
    use Notifiable;
    /**
     * Route notifications for the Msg91 channel.
     *
     * @param  \Illuminate\Notifications\Notification  $notification
     * @return string
     */
    public function routeNotificationForMsg91 ($notification) {
        return $this->phone;
    }
}

public function toMsg91($notifiable)
{
    return (new \Craftsys\Notifications\Messages\Msg91SMS)
        ->to(91992123123) // you can also pass an array for bulk notifications
        ->flow('your_flow_id');
}

public function toMsg91($notifiable)
{
    return (new \Craftsys\Notifications\Messages\Msg91OTP)
        ->digits(6) // set the digits in otp message
        ->expiresInMinutes(1) // change the expiry time
        ->from("SNCBD"); // set a custom sender id
}