westacks / telebot

Easy way to create Telegram bots in PHP
https://westacks.github.io/telebot/
MIT License
282 stars 44 forks source link

[BUG] message thread not found #77

Closed ghost closed 1 year ago

ghost commented 1 year ago

Hello. I have the following problem (most likely a bug). 1) created a new Laravel project. 2) installed the library. 3) in the .env file I registered access to the database 4) in the config/telebot.php file I registered a token, a webhook, and so on. 5) ran php artisan telebot:webhook --setup and got the response "Webhook has been set for 'myBot' bot!". 6) opened a conversation with the bot, checked the webhook - everything works. 7) added a bot to a chat with 10.000 participants - errors appeared, copied below.

Let's sum up:

I am attaching below: 1) error log 2) Update from chat 10.000 people

[2023-06-01 14:58:46] local.ERROR: Bad Request: message thread not found {"exception":"[object] (WeStacks\\TeleBot\\Exceptions\\TeleBotException(code: 400): Bad Request: message thread not found at /home/social13/myBot/vendor/westacks/telebot/src/Exceptions/TeleBotException.php:21)
[stacktrace]
#0 /home/social13/myBot/vendor/westacks/telebot/src/Contracts/TelegramMethod.php(97): WeStacks\\TeleBot\\Exceptions\\TeleBotException::requestError(Array)
#1 /home/social13/myBot/vendor/guzzlehttp/promises/src/Promise.php(209): WeStacks\\TeleBot\\Contracts\\TelegramMethod->WeStacks\\TeleBot\\Contracts\\{closure}(Array)
#2 /home/social13/myBot/vendor/guzzlehttp/promises/src/Promise.php(158): GuzzleHttp\\Promise\\Promise::callHandler(1, Object(GuzzleHttp\\Psr7\\Response), NULL)
#3 /home/social13/myBot/vendor/guzzlehttp/promises/src/TaskQueue.php(52): GuzzleHttp\\Promise\\Promise::GuzzleHttp\\Promise\\{closure}()
#4 /home/social13/myBot/vendor/guzzlehttp/guzzle/src/Handler/CurlMultiHandler.php(159): GuzzleHttp\\Promise\\TaskQueue->run()
#5 /home/social13/myBot/vendor/guzzlehttp/guzzle/src/Handler/CurlMultiHandler.php(185): GuzzleHttp\\Handler\\CurlMultiHandler->tick()
#6 /home/social13/myBot/vendor/guzzlehttp/promises/src/Promise.php(251): GuzzleHttp\\Handler\\CurlMultiHandler->execute(true)
#7 /home/social13/myBot/vendor/guzzlehttp/promises/src/Promise.php(227): GuzzleHttp\\Promise\\Promise->invokeWaitFn()
#8 /home/social13/myBot/vendor/guzzlehttp/promises/src/Promise.php(272): GuzzleHttp\\Promise\\Promise->waitIfPending()
#9 /home/social13/myBot/vendor/guzzlehttp/promises/src/Promise.php(229): GuzzleHttp\\Promise\\Promise->invokeWaitList()
#10 /home/social13/myBot/vendor/guzzlehttp/promises/src/Promise.php(69): GuzzleHttp\\Promise\\Promise->waitIfPending()
#11 /home/social13/myBot/vendor/westacks/telebot/src/Contracts/TelegramMethod.php(104): GuzzleHttp\\Promise\\Promise->wait()
#12 /home/social13/myBot/vendor/westacks/telebot/src/TeleBot.php(119): WeStacks\\TeleBot\\Contracts\\TelegramMethod->__invoke(Array)
#13 /home/social13/myBot/vendor/westacks/telebot/src/Handlers/UpdateHandler.php(64): WeStacks\\TeleBot\\TeleBot->__call(Object(WeStacks\\TeleBot\\Methods\\SendMessageMethod), Array)
#14 /home/social13/myBot/app/Telegram/HandlersUpdates/Updates.php(25): WeStacks\\TeleBot\\Handlers\\UpdateHandler->__call('sendMessage', Array)
#15 /home/social13/myBot/vendor/westacks/telebot/src/Handlers/UpdateHandler.php(94): App\\Telegram\\HandlersUpdates\\Updates->handle()
#16 /home/social13/myBot/vendor/westacks/telebot/src/Kernel.php(74): WeStacks\\TeleBot\\Handlers\\UpdateHandler->__invoke(Object(Closure))
#17 /home/social13/myBot/vendor/westacks/telebot/src/Kernel.php(46): WeStacks\\TeleBot\\Kernel->WeStacks\\TeleBot\\{closure}(Object(WeStacks\\TeleBot\\Objects\\Update), Object(Closure))
#18 /home/social13/myBot/vendor/westacks/telebot/src/Traits/HandlesUpdates.php(25): WeStacks\\TeleBot\\Kernel->run(Object(WeStacks\\TeleBot\\TeleBot), Object(WeStacks\\TeleBot\\Objects\\Update))
#19 /home/social13/myBot/vendor/westacks/telebot/src/Laravel/Controllers/WebhookController.php(13): WeStacks\\TeleBot\\TeleBot->handleUpdate(Object(WeStacks\\TeleBot\\Objects\\Update))
#20 /home/social13/myBot/vendor/laravel/framework/src/Illuminate/Routing/Controller.php(54): WeStacks\\TeleBot\\Laravel\\Controllers\\WebhookController->__invoke(Object(WeStacks\\TeleBot\\Laravel\\Requests\\UpdateRequest), 'chatgrouphelpv2', '5810466407:AAHJ...')
#21 /home/social13/myBot/vendor/laravel/framework/src/Illuminate/Routing/ControllerDispatcher.php(43): Illuminate\\Routing\\Controller->callAction('__invoke', Array)
#22 /home/social13/myBot/vendor/laravel/framework/src/Illuminate/Routing/Route.php(259): Illuminate\\Routing\\ControllerDispatcher->dispatch(Object(Illuminate\\Routing\\Route), Object(WeStacks\\TeleBot\\Laravel\\Controllers\\WebhookController), '__invoke')
#23 /home/social13/myBot/vendor/laravel/framework/src/Illuminate/Routing/Route.php(205): Illuminate\\Routing\\Route->runController()
#24 /home/social13/myBot/vendor/laravel/framework/src/Illuminate/Routing/Router.php(799): Illuminate\\Routing\\Route->run()
#25 /home/social13/myBot/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(141): Illuminate\\Routing\\Router->Illuminate\\Routing\\{closure}(Object(Illuminate\\Http\\Request))
#26 /home/social13/myBot/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(116): Illuminate\\Pipeline\\Pipeline->Illuminate\\Pipeline\\{closure}(Object(Illuminate\\Http\\Request))
#27 /home/social13/myBot/vendor/laravel/framework/src/Illuminate/Routing/Router.php(798): Illuminate\\Pipeline\\Pipeline->then(Object(Closure))
#28 /home/social13/myBot/vendor/laravel/framework/src/Illuminate/Routing/Router.php(777): Illuminate\\Routing\\Router->runRouteWithinStack(Object(Illuminate\\Routing\\Route), Object(Illuminate\\Http\\Request))
#29 /home/social13/myBot/vendor/laravel/framework/src/Illuminate/Routing/Router.php(741): Illuminate\\Routing\\Router->runRoute(Object(Illuminate\\Http\\Request), Object(Illuminate\\Routing\\Route))
#30 /home/social13/myBot/vendor/laravel/framework/src/Illuminate/Routing/Router.php(730): Illuminate\\Routing\\Router->dispatchToRoute(Object(Illuminate\\Http\\Request))
#31 /home/social13/myBot/vendor/laravel/framework/src/Illuminate/Foundation/Http/Kernel.php(200): Illuminate\\Routing\\Router->dispatch(Object(Illuminate\\Http\\Request))
#32 /home/social13/myBot/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(141): Illuminate\\Foundation\\Http\\Kernel->Illuminate\\Foundation\\Http\\{closure}(Object(Illuminate\\Http\\Request))
#33 /home/social13/myBot/vendor/laravel/framework/src/Illuminate/Foundation/Http/Middleware/TransformsRequest.php(21): Illuminate\\Pipeline\\Pipeline->Illuminate\\Pipeline\\{closure}(Object(Illuminate\\Http\\Request))
#34 /home/social13/myBot/vendor/laravel/framework/src/Illuminate/Foundation/Http/Middleware/ConvertEmptyStringsToNull.php(31): Illuminate\\Foundation\\Http\\Middleware\\TransformsRequest->handle(Object(Illuminate\\Http\\Request), Object(Closure))
#35 /home/social13/myBot/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(180): Illuminate\\Foundation\\Http\\Middleware\\ConvertEmptyStringsToNull->handle(Object(Illuminate\\Http\\Request), Object(Closure))
#36 /home/social13/myBot/vendor/laravel/framework/src/Illuminate/Foundation/Http/Middleware/TransformsRequest.php(21): Illuminate\\Pipeline\\Pipeline->Illuminate\\Pipeline\\{closure}(Object(Illuminate\\Http\\Request))
#37 /home/social13/myBot/vendor/laravel/framework/src/Illuminate/Foundation/Http/Middleware/TrimStrings.php(40): Illuminate\\Foundation\\Http\\Middleware\\TransformsRequest->handle(Object(Illuminate\\Http\\Request), Object(Closure))
#38 /home/social13/myBot/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(180): Illuminate\\Foundation\\Http\\Middleware\\TrimStrings->handle(Object(Illuminate\\Http\\Request), Object(Closure))
#39 /home/social13/myBot/vendor/laravel/framework/src/Illuminate/Foundation/Http/Middleware/ValidatePostSize.php(27): Illuminate\\Pipeline\\Pipeline->Illuminate\\Pipeline\\{closure}(Object(Illuminate\\Http\\Request))
#40 /home/social13/myBot/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(180): Illuminate\\Foundation\\Http\\Middleware\\ValidatePostSize->handle(Object(Illuminate\\Http\\Request), Object(Closure))
#41 /home/social13/myBot/vendor/laravel/framework/src/Illuminate/Foundation/Http/Middleware/PreventRequestsDuringMaintenance.php(86): Illuminate\\Pipeline\\Pipeline->Illuminate\\Pipeline\\{closure}(Object(Illuminate\\Http\\Request))
#42 /home/social13/myBot/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(180): Illuminate\\Foundation\\Http\\Middleware\\PreventRequestsDuringMaintenance->handle(Object(Illuminate\\Http\\Request), Object(Closure))
#43 /home/social13/myBot/vendor/laravel/framework/src/Illuminate/Http/Middleware/HandleCors.php(49): Illuminate\\Pipeline\\Pipeline->Illuminate\\Pipeline\\{closure}(Object(Illuminate\\Http\\Request))
#44 /home/social13/myBot/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(180): Illuminate\\Http\\Middleware\\HandleCors->handle(Object(Illuminate\\Http\\Request), Object(Closure))
#45 /home/social13/myBot/vendor/laravel/framework/src/Illuminate/Http/Middleware/TrustProxies.php(39): Illuminate\\Pipeline\\Pipeline->Illuminate\\Pipeline\\{closure}(Object(Illuminate\\Http\\Request))
#46 /home/social13/myBot/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(180): Illuminate\\Http\\Middleware\\TrustProxies->handle(Object(Illuminate\\Http\\Request), Object(Closure))
#47 /home/social13/myBot/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(116): Illuminate\\Pipeline\\Pipeline->Illuminate\\Pipeline\\{closure}(Object(Illuminate\\Http\\Request))
#48 /home/social13/myBot/vendor/laravel/framework/src/Illuminate/Foundation/Http/Kernel.php(175): Illuminate\\Pipeline\\Pipeline->then(Object(Closure))
#49 /home/social13/myBot/vendor/laravel/framework/src/Illuminate/Foundation/Http/Kernel.php(144): Illuminate\\Foundation\\Http\\Kernel->sendRequestThroughRouter(Object(Illuminate\\Http\\Request))
#50 /home/social13/myBot/public/index.php(51): Illuminate\\Foundation\\Http\\Kernel->handle(Object(Illuminate\\Http\\Request))
#51 {main}
"}
{
    "update_id": 29166232,
    "message": {
    "message_id": 4730393,
    "from": {
        "id": 5733982572,
            "is_bot": false,
            "first_name": "FirstName",
        "last_name": "lastName"
    },
    "chat": {
            "id": -100123456789,
        "title": "title chat",
            "username": "_chat",
            "type": "supergroup"
        },
    "date": 1685631455,
        "message_thread_id": 4730005,
    "text": "message text"
    }
}
ghost commented 1 year ago

The problem was solved by replacing the code on line 22. However, I think this is still a flaw, maybe it needs to be fixed?

image

punyflash commented 1 year ago

It seems like a bug with message_thread_id that being set within UpdateHandler. However I don't see any issues in library code - all data obtained from update should be correct https://github.com/westacks/telebot/blob/c00ad32a35e0b5064ac343b08db601865852e283/src/Handlers/UpdateHandler.php#L51

Would be nice if you could debug this on your supergroup and see what you get insede message_thread_id, cos I don't really have such big group to work with. I suspect this might be a bug from telegram side