I use telepot python library with my bot, in python 3.5. I want to read the text of a message that is already in a chat, knowing the id of the telegram chat and the id of the message. How can I do?
Asked
Active
Viewed 346 times
1 Answers
2
The telepot library is a wrapper around the Telegram Bot HTTP API and unfortunately the API doesn't have such method available at the moment. (see here for full list of all available methods). Additionally, telepot is no longer actively maintained.
Nonetheless, you can directly make requests to the telegram servers (skipping the intermediary HTTP API) by using mtproto protocol based libraries (such as Telethon, Pyrogram, MadelineProto, etc..) instead.
Here is an example using Telethon to give you an idea:
from telethon import TelegramClient
API_ID = ...
API_HASH = ' ... '
BOT_TOKEN = ' ... '
client = TelegramClient('bot_session', API_ID, API_HASH).start(bot_token = BOT_TOKEN)
async def main():
message = await client.get_messages(
-10000000000, # channel ID
ids=3 # message ID
)
print("MESSAGE:\n---\n")
print(message.text)
client.start()
client.loop.run_until_complete(main())
[user@pc ~]$ python main.py
MESSAGE:
---
test message
You can get values for API_ID
and API_HASH
by creating an application over my.telegram.org (see this page for more detailed instruction)

Tibebes. M
- 6,940
- 5
- 15
- 36