PHP code example of sajaddp / laravel-bale

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

    

sajaddp / laravel-bale example snippets


use Sajaddp\Bale\Facades\Bale;

$message = Bale::sendMessage(
    chatId: 123456789,
    text: 'گزارش شما آماده شد.',
);

use Sajaddp\Bale\Facades\Bale;

config(['bale.token' => 'test-token']);
Bale::fake();

Bale::sendMessage(
    chatId: 123456789,
    text: 'گزارش شما آماده شد.',
);

Bale::assertSent('sendMessage', [
    'chat_id' => 123456789,
    'text' => 'گزارش شما آماده شد.',
]);
Bale::assertSentTimes('sendMessage', 1);
Bale::assertNotSent('sendDocument');

use Sajaddp\Bale\Facades\Bale;

Bale::replyToMessage(
    message: $update['message'],
    text: 'پیام شما دریافت شد.',
);

use Sajaddp\Bale\Facades\Bale;

// آپلود فایل محلی
Bale::sendDocument(
    chatId: 123456789,
    document: new \SplFileInfo(storage_path('app/report.pdf')),
    options: ['caption' => 'گزارش آماده‌شده'],
);

// استفادهٔ دوباره از فایل موجود در بله
Bale::sendDocument(
    chatId: 123456789,
    document: 'bale-file-id',
);

// ارسال ویدیو از نشانی اینترنتی
Bale::sendVideo(
    chatId: 123456789,
    video: 'https://example.com/video.mp4',
);

use Illuminate\Support\Facades\Storage;
use Sajaddp\Bale\Facades\Bale;

$contents = Bale::downloadFile($fileId);

Storage::put('bale/report.pdf', $contents);

use Sajaddp\Bale\Facades\Bale;

Bale::sendMessage(
    chatId: 123456789,
    text: 'گزارش را دریافت کردید؟',
    options: [
        'reply_markup' => [
            'inline_keyboard' => [
                [
                    ['text' => 'بله، دریافت شد', 'callback_data' => 'report_received'],
                ],
            ],
        ],
    ],
);

use Sajaddp\Bale\Facades\Bale;

$callback = $update['callback_query'];

Bale::answerCallbackQuery(callbackQueryId: $callback['id']);

if (isset($callback['message'])) {
    Bale::editMessageText(
        chatId: $callback['message']['chat']['id'],
        messageId: $callback['message']['message_id'],
        text: 'دریافت گزارش تأیید شد.',
    );
}

use Illuminate\Http\Request;
use Illuminate\Support\Facades\Route;

Route::post('/bale/webhook', function (Request $request) {
    $update = $request->all();

    // اعتبارسنجی و پردازش رویداد را در برنامهٔ خود انجام دهید.

    return response()->noContent();
});

$middleware->preventRequestForgery(except: [
    'bale/webhook',
]);

use Sajaddp\Bale\Facades\Bale;

Bale::setWebhook('https://example.com/bale/webhook');

use Sajaddp\Bale\Facades\Bale;

$updates = Bale::getUpdates([
    'limit' => 100,
    'timeout' => 30,
]);

use Sajaddp\Bale\Facades\Bale;

Bale::askReview(
    userId: 123456789,
    delaySeconds: 30,
);
shell
php artisan vendor:publish --tag=bale-config