E
E
Ernest Vardanyan2020-06-29 15:57:59
Python
Ernest Vardanyan, 2020-06-29 15:57:59

How to specify the correct ID of the last SMS?

Hello, my code collects information from the site and sends SMS to the channel, after which it is updated and the new data is already entered into the same SMS, simply by editing it using (bot.edit_message_text('55555555', chat_id=-00000, message_id=15 ) After finishing work, it closes and reopens and sends SMS again, already new and the same system, but there is such a problem that with each new SMS id changes, the previous one was 15, and the next one will be 16, then 17 and so on, How can I write a code so that it just changes the last SMS?

from selenium import webdriver
import time
from selenium.common.exceptions import NoSuchElementException
from selenium.common.exceptions import TimeoutException
import telegram

browser = webdriver.Chrome()
browser.maximize_window()
browser.get('****************************')


def CC():

    BOT_TOKEN = '******************************'
    bot = telegram.Bot(token=BOT_TOKEN)
    bot.edit_message_text('55555555', chat_id=*************, message_id=15)

Answer the question

In order to leave comments, you need to log in

1 answer(s)
I
Igor, 2020-06-29
@adnim

I don't see the message being sent, only editing.
When sending the first message, save the reply:

response = bot.send_message(chat_id=chat_id, text=answer)
message_id = response.message_id

Attention! This part of the code (above) should only run once!
And the code below is as many times as needed.
Then in a loop or wherever you edit a message, use this message_id:
bot.edit_message_text('55555555', chat_id=*************, message_id=message_id)

And don't forget the scope.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question