Added CommandHandler
This commit is contained in:
parent
eacc106666
commit
2362365865
5 changed files with 134 additions and 3 deletions
23
tests/commands/StartCommand.php
Normal file
23
tests/commands/StartCommand.php
Normal file
|
@ -0,0 +1,23 @@
|
|||
<?php
|
||||
|
||||
namespace commands;
|
||||
|
||||
use TgBotLib\Bot;
|
||||
use TgBotLib\Exceptions\TelegramException;
|
||||
use TgBotLib\Interfaces\CommandInterface;
|
||||
use TgBotLib\Objects\Telegram\Update;
|
||||
|
||||
class StartCommand implements CommandInterface
|
||||
{
|
||||
/**
|
||||
* @param Bot $bot
|
||||
* @param Update $update
|
||||
* @return void
|
||||
* @throws TelegramException
|
||||
*/
|
||||
public function handle(Bot $bot, Update $update): void
|
||||
{
|
||||
// reply to the incoming message
|
||||
$bot->sendMessage($update->getMessage()->getChat()->getId(), 'Hello, ' . $update->getMessage()->getFrom()->getFirstName());
|
||||
}
|
||||
}
|
|
@ -1,7 +1,13 @@
|
|||
<?php
|
||||
|
||||
use commands\StartCommand;
|
||||
|
||||
require 'ncc';
|
||||
import('net.nosial.tgbotlib');
|
||||
|
||||
$bot = new TgBotLib\Bot('5126030313:AAEn3QcwSvTJ2eAKUnSb_MkC5U0tlqkM1xw');
|
||||
$bot->sendMessage(chat_id: 570787098, text: 'Hello world!');
|
||||
require 'commands/StartCommand.php';
|
||||
|
||||
$bot = new TgBotLib\Bot('YOUR_BOT_TOKEN');
|
||||
$bot->setCommandHandler('start', new StartCommand());
|
||||
|
||||
$bot->handleGetUpdates(true);
|
Loading…
Add table
Add a link
Reference in a new issue