php-telegram-bot / laravel

Laravel package for PHP Telegram Bot Library
Other
168 stars 50 forks source link

Commands don't answer after correct update data received from telegram. #5

Closed CodingJediKnight closed 5 years ago

CodingJediKnight commented 5 years ago

I've get confused when bot was silent on webhook method. DB updates correct. But bot don't answer on any command. So I desided to test on update method and got the same =( DB updating with correct recieving data from telegram, but don't answer. So I add Request::sendMessage to handleGetUpdates() in my controller to check if there any connect problems with telegram on my side:

public function handleGetUpdates(PhpTelegramBotContract $telegram)
{
    try {
        \Longman\TelegramBot\Request::initialize($telegram);
        \Longman\TelegramBot\Request::sendMessage(["chat_id" => "MY_TG_ID", "text" => "123"]);

        return $telegram->handleGetUpdates();
    } catch (TelegramException $e) {
        TelegramLog::error($e->getMessage());
    }
}

But bot breakes the silence)

So I thing there is some problems with Command factory, but I can't find where. Can somebody help me with this?

CodingJediKnight commented 5 years ago

https://github.com/php-telegram-bot/core/issues/572#issuecomment-317465569 was very helpfull! Lost a day to figure it out and find answer after 15 minutes after posting this issue)

CodingJediKnight commented 5 years ago

I find a thing that confuse me the most. For example I'm extending command like that:

<?php
namespace App\Telegram\Commands;

use \Longman\TelegramBot\Commands\AdminCommands\DebugCommand as NativeDebugCommand;

class HelpTestCommand extends NativeDebugCommand {
    protected $name = 'helptest';
    protected $usage = '/helptest';

    public function execute()
    {
        parent::execute();
    }
}

path file: /app/Telegram/Commands/HelpTestCommand.php

It doesn't work until I change namespace to this:

namespace Longman\TelegramBot\Commands\AdminCommands;
noplanman commented 5 years ago

@CodingJediKnight Yes, the command namespace is a bit troublesome at the moment. Sorry about that :confused:

mfissehaye commented 5 years ago

Please put this somewhere in the documentation or share if there is a fix. Spent hours trying to figure out what went wrong. (Nice library by the way)