forked from zarincheg/telegram-bot-dialogs
-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add a new GitHub workflow "Run test bot on Laravel app"
- Loading branch information
Showing
2 changed files
with
73 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
name: Run test bot on Laravel app | ||
|
||
on: | ||
workflow_dispatch: | ||
|
||
jobs: | ||
|
||
tests: | ||
runs-on: ubuntu-latest | ||
|
||
steps: | ||
- name: Checkout code | ||
uses: actions/checkout@v4 | ||
|
||
- name: Setup PHP | ||
uses: shivammathur/setup-php@v2 | ||
with: | ||
php-version: 8.3 | ||
extensions: curl, bcmath, libxml, mbstring, fileinfo | ||
coverage: none | ||
|
||
- name: Create Laravel app | ||
run: | | ||
cd ../ | ||
composer create-project laravel/laravel:^11.0 test-app-laravel | ||
cd ./test-app-laravel | ||
composer config repositories.0 '{"type": "path", "url": "../telegram-bot-dialogs/"}' | ||
composer require "koot-labs/telegram-bot-dialogs:*@dev" --update-with-all-dependencies | ||
- name: Setup test Command | ||
run: cp -f ../telegram-bot-dialogs/tests/ci/console.php ./routes/console.php | ||
|
||
- name: Execute PHP tests | ||
run: php artisan telegram:dialog:test 20 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
<?php | ||
|
||
use Illuminate\Support\Facades\Artisan; | ||
use KootLabs\TelegramBotDialogs\DialogManager; | ||
use KootLabs\TelegramBotDialogs\Dialogs\HelloExampleDialog; | ||
use Telegram\Bot\BotsManager; | ||
use Telegram\Bot\Laravel\Facades\Telegram; | ||
|
||
Artisan::command('telegram:dialog:test {ttl=10}', function (DialogManager $dialogs, BotsManager $botsManager, int $ttl): void { | ||
$this->info("Listening for Telegram Bot updates for $ttl seconds..."); | ||
|
||
$end = microtime(true) + $ttl; | ||
|
||
while(microtime(true) < $end) { | ||
$updates = Telegram::commandsHandler(); | ||
$updates = is_array($updates) ? $updates : [$updates]; | ||
|
||
/** @var \Telegram\Bot\Objects\Update $update */ | ||
foreach ($updates as $update) { | ||
if ($dialogs->exists($update)) { | ||
$dialogs->proceed($update); | ||
} elseif (str_contains($update->getMessage()?->text, 'hello bot') || $update->getMessage()?->text === '/start') { | ||
$dialog = new HelloExampleDialog($update->getChat()->id); | ||
$dialogs->activate($dialog); | ||
$dialogs->proceed($update); | ||
} else { | ||
$botsManager->sendMessage([ // fallback message | ||
'chat_id' => $update->getChat()->id, | ||
'text' => 'There is no active dialog at this moment. You can also start a new dialog by typing "hello bot" in the chat.', | ||
]); | ||
} | ||
} | ||
|
||
// Sleep for 0.2 seconds to prevent the loop from running too fast | ||
usleep(200_000); | ||
} | ||
|
||
$this->info("Finished listening for Telegram Bot updates."); | ||
})->purpose('Test Telegram Bot and Dialogs'); |