You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
<?php
/**
* This file is part of the PHP Telegram Bot example-bot package.
* https://github.com/php-telegram-bot/example-bot/
*
* (c) PHP Telegram Bot Team
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Longman\TelegramBot\Commands\SystemCommands;
use Longman\TelegramBot\Commands\SystemCommand;
use Longman\TelegramBot\Entities\ServerResponse;
use Longman\TelegramBot\Exception\TelegramException;
/**
* Generic command
*
* Gets executed for generic commands, when no other appropriate one is found.
*/
class GenericCommand extends SystemCommand
{
/**
* @var string
*/
protected $name = 'generic';
/**
* @var string
*/
protected $description = 'Handles generic commands or is executed by default when a command is not found';
/**
* @var string
*/
protected $version = '1.1.0';
/**
* Main command execution
*
* @return ServerResponse
* @throws TelegramException
*/
public function execute(): ServerResponse
{
$message = $this->getMessage();
$user_id = $message->getFrom()->getId();
$command = $message->getCommand();
// To enable proper use of the /whois command.
// If the user is an admin and the command is in the format "/whoisXYZ", call the /whois command
if (stripos($command, 'whois') === 0 && $this->telegram->isAdmin($user_id)) {
return $this->telegram->executeCommand('whois');
}
return $this->replyToChat("Command /{$command} not found.. :(");
}
}
File Commands/Message/GenericmessageCommand.php:
<?php
namespace Longman\TelegramBot\Commands\SystemCommands;
use Longman\TelegramBot\Commands\SystemCommand;
use Longman\TelegramBot\Entities\ServerResponse;
use Longman\TelegramBot\Request;
class GenericmessageCommand extends SystemCommand
{
protected $name = 'genericmessage';
protected $description = 'Handle generic message';
protected $version = '1.0.0';
public function execute(): ServerResponse
{
$message = $this->getMessage();
$message_text = $message->getText(true);
$result = Request::sendMessage([
'chat_id' => $message->getFromId(),
'text' => $message_text
]);
return Request::emptyResponse();
}
}
🐞 Bug Report
Required Information
{...}
Summary
I made a simple bot and it doesn't work. I need to process any commands in GenericCommand.php file
Current behaviour
Commands don't work! the request comes to the server without problems
How to reproduce
My Code
hook.php:
File Commands/GenericCommand.php:
File Commands/Message/GenericmessageCommand.php:
composer.json:
Expected behaviour
This should work as an echo bot and also throw an error on unknown commands!
The text was updated successfully, but these errors were encountered: