PHP code example of devaspid / laravel-simple-telegram

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

    

devaspid / laravel-simple-telegram example snippets

 bash
php artisan vendor:publish --tag="telegram-config"
 php
return [
    'enable' => env('TELEGRAM_ENABLE', true),
    'bot_token' => env('TELEGRAM_BOT_TOKEN', ''),
    'chat_id' => env('TELEGRAM_CHAT_ID', ''),

    'topics' => [
        'transaction' => env('TELEGRAM_TOPIC_TRANSACTION', null),
    ],
];
 php
namespace App\Models;

use Devaspid\Telegram\Facades\Telegram;
use Illuminate\Database\Eloquent\Model;

class Order extends Model
{
    protected static function booted(): void
    {
        static::created(function (Order $order) {$message = "🚨 <b>Alert: New Order Created</b>\n"
                . "Order ID: #{$order->id}\n"
                . "Total: Rp " . number_format($order->total_amount);

            Telegram::send($message, config('telegram.topics.transaction'));
        });

        static::updated(function (Order $order) {
            if ($order->isDirty('status') &&$order->status === 'paid') {
                Telegram::send("💰 <b>Order #{$order->order_number} has been PAID!</b>");
            }
        });
    }
}