Hi, i have many problems to run this bot in my host.
composer require longman/telegram-bot for require project : | vendor --------- > | composer
| composer.json | guzzlehttp
| composer.lock | longman ---> telegram-bot ---> src
| psr
| ralouphie
| autoload.php
Do I have to upload all these files to my host ?!
I uploaded all the files and used the example-bot repository for set.php and hook.php and i uploaded these files in vendor/longman/telegram-bot/src.
In step 3, i created my robot in botfather.
Next, i edit set.php and hook.php for my robot and i used https://mysite/vendor/longman/telegram-bot/src/set.php for ser webhook!
By the way, these files are not capable of calling autoload.php file at all. So I changed the file path to the files:
- require_once __DIR__ . '/vendor/autoload.php';
+ require_once __DIR__ . '/../../../autoload.php';
This time I was able to set the webhook but every time i send a /start to the robot, I get this error on error_log and the robot does not work:
[09-Mar-2020 16:24:33 UTC] PHP Fatal error: Uncaught Error: Class 'Longman\TelegramBot\Commands\UserCommands\Request' not found in /home/mypath/public_html/bot/vendor/longman/telegram-bot/src/Commands/UserCommands/StartCommand.php:56
Stack trace:
#0 /home/mypath/public_html/bot/vendor/longman/telegram-bot/src/Commands/Command.php(182): Longman\TelegramBot\Commands\UserCommands\StartCommand->execute()
#1 /home/mypath/public_html/bot/vendor/longman/telegram-bot/src/Telegram.php(518): Longman\TelegramBot\Commands\Command->preExecute()
#2 /home/mypath/public_html/bot/vendor/longman/telegram-bot/src/Telegram.php(491): Longman\TelegramBot\Telegram->executeCommand('start')
#3 /home/mypath/public_html/bot/vendor/longman/telegram-bot/src/Telegram.php(416): Longman\TelegramBot\Telegram->processUpdate(Object(Longman\TelegramBot\Entities\Update))
#4 /home/mypath/public_html/bot/vendor/longman/telegram-bot/src/hook.php(69): Longman\TelegramBot\Telegram->handle()
#5 {main}
thrown in /home/mypath/public_html/bot/vendor/longman/telegram-bot/src/Commands/UserCommands/StartCommand.php on line 56
Please help me! 🤕 Excuse me if I had something wrong. 🎃
| ? | !
| --- | ---
| Operating system | Name and version
| PHP Telegram Bot version | Linux webhost
| PHP version | 7.2.28
| MySQL version | 5.6.43 / none
| Update Method | ...
| Self-signed certificate | yes
| RAW update (if available) | {...}
My problem was fixed!
Could you maybe post your solution, in case somebody else has the same problem at some point?
Thanks :+1:
Hi, Yes
In startCommand.php , I changed return parent :: execute () and sent a message instead.
public function execute()
{
//$message = $this->getMessage();
//$chat_id = $message->getChat()->getId();
//$user_id = $message->getFrom()->getId();
return parent::execute();
}
use Longman\TelegramBot\Request;
(...)
public function execute()
{
$message = $this->getMessage();
$chat_id = $message->getChat()->getId();
$user_id = $message->getFrom()->getId();
$username = $message->getFrom()->getUsername();
$result = Request::sendMessage([
'chat_id' => $chat_id,
'text' => "Hello {$username}",
]);
return $result;
}
The return of execute function, should not be return parent :: execute ().
I changed the path to __DIR__ . '/../../../autoload.php', to resolve the autoload path.
- require_once __DIR__ . '/vendor/autoload.php';
+ require_once __DIR__ . '/../../../autoload.php';
It worked for me! 🎉
i have the same problem, but i not understand what i do
thanks
@farmaworld Make sure you include the autoloader correctly. You can check the example-bot for examples