PHP code example of alexsoft / laravel-notifications-telegram

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

    

alexsoft / laravel-notifications-telegram example snippets


'telegram-notifications-bot-token' => [
    'key' => env('TELEGRAM_BOT_API_TOKEN')
]



namespace App;

use Illuminate\Notifications\Notifiable;
use Illuminate\Foundation\Auth\User as Authenticatable;

class User extends Authenticatable
{
    use Notifiable;

    /**
     * Route notifications for the Nexmo channel.
     *
     * @return string
     */
    public function routeNotificationForTelegram()
    {
        return $this->telegram_user_id;
    }
}

/**
 * Get the telegram representation of the notification.
 *
 * @param  mixed  $notifiable
 * @return \Alexsoft\LaravelNotificationsTelegram\TelegramMessage
 */
public function toTelegram($notifiable)
{
    $url = url('/invoice/' . $this->invoice->id);

    return (new TelegramMessage)
        ->line('One of your invoices has been paid!')
        ->action('View Invoice', $url)
        ->line('Thank you for using our application!');
}

/**
 * Get the telegram representation of the notification.
 *
 * @param  mixed  $notifiable
 * @return \Alexsoft\LaravelNotificationsTelegram\TelegramMessage
 */
public function toTelegram($notifiable)
{
    $url = url('/invoice/' . $this->invoice->id);

    return (new TelegramMessage)
        ->error() // or success()
        ->line('Invoice could not be paid!')
        ->action('View Invoice', $url);
}