Search code examples
telegramreplytelepot

How to reply a massage in Telepot?


I am making a telegram bot with telepot , but I don't know how to do it. I tried many solutions, but I didn't get an answer and the bot only sent simple messages without reply! My source is supposed to run on the pythoneverywhere site, so I have the limitation of using other libraries like telethon.

here is my code :

import telepot
import urllib3
import random, time

proxy_url = "http://proxy.server:3128"
telepot.api._pools = {
    'default': urllib3.ProxyManager(proxy_url=proxy_url, num_pools=3, maxsize=10, retries=False, timeout=30),
}

telepot.api._onetime_pool_spec = (urllib3.ProxyManager, dict(proxy_url=proxy_url, num_pools=1, maxsize=1, retries=False, timeout=30))

bot = telepot.Bot('')

def handle(msg):
    content_type, chat_type, chat_id .= telepot.glance(msg)
    massage = msg["text"]
    bot.sendMessage(chat_id, text="Reply From Bot!" ,reply_to_message_id=massage)

bot.message_loop(handle)

print('RUNNING!')

while 1:
    time.sleep(10)

I tried : bot.sendMessage(chat_id, text="Reply From Bot!" ,reply_to_message_id=massage)

and I expected : Reply From Bot!


Solution

  • Instead of using massage you can use msg['message_id']

    def handle(msg):
        content_type, chat_type, chat_id .= telepot.glance(msg)
        massage = msg["text"]
        bot.sendMessage(chat_id, text="Reply From Bot!" ,reply_to_message_id=msg['message_id'])
    

    And also just mentioning; it seems like telepot is no longer maintained by developers as mentioned in telepot's GitHub repository. It would be better to switch into a library like python-telegram-bot