How To Work Around GetUpdates Limit? (Telegram BOT)

- 1 answer

I have recently been trying to create a functional telegram BOT using the official API but I have some issues. The BOT's goal is to forward all the messages received from person x to group y.

The BOT checks "{}/getUpdates".format(TOKEN) for its latest received message so it can check what that message is and if it is send by person x. And this all used to work until my url stopped updating itself after it hit 100 records.

There must be a way to clear those records on an automatic basis right? I read a bit about "-offset" and tried to implement it via URL Query string, but it didn't seem to have a result.

Thank you for your help.



Solved the issue in a slightly different way using offset (guess after a given time even I can learn it).

Since after the instance where I send a message I dont need the old updates anymore I used this:

def get_update_id(updates):
    num_updates = len(updates["result"])
    last_update = num_updates - 1
    update_id = updates["result"][last_update]["update_id"]
    return (update_id)

where updates equals:

def get_updates(OFFSET):
    url = URL + "getUpdates?offset={}".format(OFFSET)
    js = get_json_from_url(url)
    return js

As said the def is called after the send_message statement in the form of:

OFFSET = get_update_id(get_updates(OFFSET))

which will make sure the last update in getUpdates will be the first update once the code is ran again