php-telegram-bot / core

PHP Telegram Bot based on the official Telegram Bot API
MIT License
3.9k stars 955 forks source link

Endless repetition in `Longman\TelegramBot\Telegram::handleGetUpdates()` for unknown updates #1194

Closed massadm closed 1 year ago

massadm commented 3 years ago

🐞 Bug Report

Critical

Required Information

? !
Operating system Linux 5.11.6-1-MANJARO
PHP Telegram Bot version 0.71.0
PHP version 8.0.1
MySQL version 10.5.8-MariaDB
Update Method getUpdates
Self-signed certificate no

Summary

Due to Telegram Bot API updates, the TelegramBot instance may receive updates that have not yet been implemented by the library. With the current implementation of getUpdates, processing of such updates will be repeated indefinitely.

How to reproduce

Get my_chat_member or any other currently unimplemented update from Telegram using getUpdates.

Expected behaviour

Need the way to process unknown updates.

massadm commented 3 years ago

Call to get incoming updates using long polling looks like this:

$response = Request::getUpdates(..., $offset = $this->last_update_id + 1)

$this->last_update_id populated from the database like this:

SELECT `id` FROM `telegram_update` ORDER BY `id` DESC LIMIT 1

The problem is that DB::insertRequest($this->update) does not populate the database with information about unknown updates. At the next iteration, the database will not contain information about the processing of unimplemented update, so $this->last_update_id will remain the same as in the previous iteration. And so it turns out to be an endless cycle.

noplanman commented 3 years ago

You're absolutely right, thanks for reporting. This will be fixed in the next version, which will also have the Bot API 5.1 integrated.

It will also be more future-proof for when new update types get added by Telegram 👌

massadm commented 3 years ago

I suggest to ALTER TABLE telegram_update by adding COLUMN unknown_update_id BIGINT UNSIGNED NULL referred to unknown_telegram_update TABLE by it's primary key. All unimplemented updates must be stored here in unknown_telegram_update table in serialized form.

An additional overridable system command can be considered to handle such updates (as a workaround for manual handling of the latest Telegram Bot API innovations, without waiting for implementation inside the library).

noplanman commented 3 years ago

@massadm Your suggestion sounds like a great idea! Would you like to make a PR for it? 😇

noplanman commented 3 years ago

Maybe we could combine this with #1124?

massadm commented 3 years ago

I'll see what I can do.