PHP code example of maxbond / telegram-custom-url

1. Go to this page and download the library: Download maxbond/telegram-custom-url 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/ */

    

maxbond / telegram-custom-url example snippets


// config/app.php
'providers' => [
    ...
    NotificationChannels\Telegram\TelegramServiceProvider::class,
],

// config/services.php
...
'telegram-bot-api' => [
    'token' => env('TELEGRAM_BOT_TOKEN', 'YOUR BOT TOKEN HERE')
],
...
 php
use NotificationChannels\Telegram\TelegramChannel;
use NotificationChannels\Telegram\TelegramMessage;
use Illuminate\Notifications\Notification;

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

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

        return TelegramMessage::create()
            ->to($this->user->telegram_user_id) // Optional.
            ->content("*HELLO!* \n One of your invoices has been paid!") // Markdown supported.
            ->button('View Invoice', $url); // Inline Button
    }
}
 php
...
    public function toTelegram($notifiable)
    {
        $url = url('/file/' . $this->file->id);

        return TelegramMessage::create()
            ->to($this->user->telegram_user_id) // Optional.
            ->content("*bold text* [inline URL](http://www.example.com/)") // Markdown supported.
            ->file('/storage/archive/6029014.jpg', 'photo') // local photo
            // OR
            // ->file('https://pisces.bbystatic.com/image2/BestBuy_US/images/products/6029/6029014_rd.jpg', 'photo') // remote photo
            ->button('Download PDF', $url); // Inline Button
    }
...
 php
...
    public function toTelegram($notifiable)
    {
        $url = url('/file/' . $this->file->id);

        return TelegramMessage::create()
            ->to($this->user->telegram_user_id) // Optional.
            ->content("*bold text* [inline URL](http://www.example.com/)") // Markdown supported.
            ->file('/storage/archive/file.pdf', 'document') // local file
            // OR
            // ->file('http://www.domain.com/file.pdf', 'document') // remote file
            ->button('Download PDF', $url); // Inline Button
    }
...
 php
...
/**
 * Route notifications for the Telegram channel.
 *
 * @return int
 */
public function routeNotificationForTelegram()
{
    return $this->telegram_user_id;
}
...