I'm using the python-telegram-bot library to write a bot in Python that sends URLs into a channel where the bot is administrator.
Now, I would like to have the bot reading, let's say, the last 5 messages (I don't really care about the number as I just need to read the message on the chat) and store them into a list in the code for further elaborations.
I already have my bot working with:
bot = telegram.Bot(token='mytoken')
bot.sendMessage(chat_id='@mychatid', text=entry.link)
But I can't find a bot.getLastMessage
or bot.getMessage
kind of class into the python-telegram-bot library.
In case there's already no written class that does that, how can I implement it via the Telegram API as I'm a bit of a beginner when it comes to API implementation?
Thanks.
That's not possible in Bots unfortunately.
Here you can find all available methods (that python-telegram-bot
invokes behind the scenes) and there's no such method available to fetch messages on demand.
The closest you can get through the api is getChat
(which would return the pinned_message
in that chat).
What you can do in this case is, store the messages the bot sends as well as the message updates the bot receives (by setting up a handler) in some storage (database) and fetch from there later on.