Core: Many problems to use :/

Created on 9 Mar 2020  ·  5Comments  ·  Source: php-telegram-bot/core

❓ Support Question

Hi, i have many problems to run this bot in my host.

  1. I used 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 ?!

  1. 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.

  2. In step 3, i created my robot in botfather.

  3. 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. 🎃

Required Information

| ? | !
| --- | ---
| 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) | {...}

question

All 5 comments

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

startCommand.php file

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 ().

Autoload path

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

Was this page helpful?
0 / 5 - 0 ratings

Related issues

NabiKAZ picture NabiKAZ  ·  4Comments

marcolino7 picture marcolino7  ·  3Comments

irmmr picture irmmr  ·  3Comments

NabiKAZ picture NabiKAZ  ·  3Comments

Bl0ck154 picture Bl0ck154  ·  3Comments