How To Work Around GetUpdates Limit? (Telegram BOT)
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 "https://api.telegram.org/bot{}/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.
Answer
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
Related Questions
- → What are the pluses/minuses of different ways to configure GPIOs on the Beaglebone Black?
- → Django, code inside <script> tag doesn't work in a template
- → React - Django webpack config with dynamic 'output'
- → GAE Python app - Does URL matter for SEO?
- → Put a Rendered Django Template in Json along with some other items
- → session disappears when request is sent from fetch
- → Python Shopify API output formatted datetime string in django template
- → Can't turn off Javascript using Selenium
- → WebDriver click() vs JavaScript click()
- → Shopify app: adding a new shipping address via webhook
- → Shopify + Python library: how to create new shipping address
- → shopify python api: how do add new assets to published theme?
- → Access 'HTTP_X_SHOPIFY_SHOP_API_CALL_LIMIT' with Python Shopify Module