When I send "teste" to my bot, it should response "Testing OK"
I'm trying to test with a chat directly with the bot:
test
/test
@my_bot test
@my_bot /test
Nothing happens
I configured my Hook file setting variable $commands_paths = [
__DIR__ . '/ComandosPersonalizados',
];, that there is only one file in this folder, called TestCommand.php.
hook.php:
<?php
// Load composer
require __DIR__ . '/vendor/autoload.php';
$API_KEY = '';
$BOT_NAME = '';
$commands_paths = [
__DIR__ . '/ComandosPersonalizados',
];
try {
// Create Telegram API object
$telegram = new Longman\TelegramBot\Telegram($API_KEY, $BOT_NAME);
// Handle telegram webhook request
$telegram->handle();
} catch (Longman\TelegramBot\Exception\TelegramException $e) {
// Silence is golden!
// log telegram errors
// echo $e;
}
TestCommand.php:
<?php
namespace Longman\TelegramBot\Commands\UserCommands;
use Longman\TelegramBot\Commands\UserCommand;
use Longman\TelegramBot\Request;
class TestCommand extends UserCommand
{
protected $name = 'test'; // Your command's name
protected $description = 'A command for test'; // Your command description
protected $usage = '/test'; // Usage of your command
protected $version = '1.0.0'; // Version of your command
public function execute()
{
$message = $this->getMessage(); // Get Message object
$chat_id = $message->getChat()->getId(); // Get the current Chat ID
$data = [ // Set up the new message data
'chat_id' => $chat_id, // Set Chat ID to send the message to
'text' => 'Testing OK', // Set message to send
];
return Request::sendMessage($data); // Send message!
}
}
In hook.php I forgot to add $telegram->addCommandsPaths($commands_paths); after create telegram class
@JulyanoF you included API token in your message, I've removed it but be sure to generate new one in @BotFather.
Thankyou @jacklul, but how can I generate e new one?
Use /revoke in @BotFather.
@jacklul I found it, thank you a lot :)
Hello!
I installed php on termux but when I run php bot.php it's not working. Please help.