|
| 1 | +<?php |
| 2 | + |
| 3 | +declare(strict_types=1); |
| 4 | + |
| 5 | +include __DIR__ . '/basics.php'; |
| 6 | + |
| 7 | +use React\EventLoop\Factory; |
| 8 | +use unreal4u\TelegramAPI\Abstracts\TelegramTypes; |
| 9 | +use unreal4u\TelegramAPI\HttpClientRequestHandler; |
| 10 | +use unreal4u\TelegramAPI\Telegram\Methods\SetMyCommands; |
| 11 | +use unreal4u\TelegramAPI\Telegram\Types\BotCommand; |
| 12 | +use unreal4u\TelegramAPI\Telegram\Types\BotCommandScope; |
| 13 | +use unreal4u\TelegramAPI\TgLog; |
| 14 | + |
| 15 | +$loop = Factory::create(); |
| 16 | +$tgLog = new TgLog(BOT_TOKEN, new HttpClientRequestHandler($loop)); |
| 17 | + |
| 18 | +$scopeType = 'all_private_chats'; |
| 19 | + |
| 20 | +$method = new SetMyCommands(); |
| 21 | +$method->scope = new BotCommandScope(); |
| 22 | +$method->scope->type = $scopeType; |
| 23 | + |
| 24 | +$command = new BotCommand(); |
| 25 | +$command->command = 'help'; |
| 26 | +$command->description = sprintf('description for command help in scope %s', $scopeType); |
| 27 | +$method->commands[] = $command; |
| 28 | + |
| 29 | +$command = new BotCommand(); |
| 30 | +$command->command = 'settings'; |
| 31 | +$command->description = sprintf('%s icon and settings description in scope %s', "\u{2764}", $scopeType); |
| 32 | +$method->commands[] = $command; |
| 33 | + |
| 34 | +$command = new BotCommand(); |
| 35 | +$command->command = 'foo_bar'; |
| 36 | +$command->description = sprintf('just another command visible only in scope %s', $scopeType); |
| 37 | +$method->commands[] = $command; |
| 38 | + |
| 39 | +$promise = $tgLog->performApiRequest($method); |
| 40 | +$promise->then( |
| 41 | + function (TelegramTypes $response) use ($scopeType) { |
| 42 | + var_dump(sprintf('Commands for scope "%s" were set. Use GetMyCommands() to get list of them.', $scopeType)); |
| 43 | + }, |
| 44 | + function (\Exception $e) { |
| 45 | + var_dump($e->getTraceAsString()); |
| 46 | + } |
| 47 | +); |
| 48 | + |
| 49 | +$loop->run(); |
0 commit comments