Home>

Using official Telegram Bot API

The problem is that when I send a getUpdates request, I get data about a person's message, the message_id in the json response only changes when a person sends a message, what are the official methods to not re-send a response to the "/start" message?

import requests
token= 'TOKEN'
url= f'https://api.telegram.org/bot{token}'
def check_last_message(txt):
    message= requests.get(url + '/getUpdates?offset=-1').json()
    if message['result'][0]['message']['text']== txt:
        chat_id= message['result'][0]['message']['from']['id']
        message_id= message['result'][0]['message']['message_id']
        return chat_id, message_id
    else:
        return 0
def send_message(method, chat_id, text):
    send= requests.get(url + f'/{method}?chat_id={chat_id}&
text={text}')
    print(send.json()['ok'])
def main():
    send_message('sendMessage', check_last_message('/start')[0], 'Hello')
if __name__== '__main__':
    main()

DB use...

Qwertiy2022-01-17 20:03:37

@Qwertiy no more? Can you somehow update the list of messages? they seem to be removed after 24 hours, but it's a long time.

Robot2022-01-17 20:38:13