1

I'm writing a telegram bot group administrator using python-telegram-api and I want my bot to reply to messages in groups like this but the only similar thing I can get with it is this. Is there a way to reply to messages like in the first picture?

from telegram.ext import (Updater, CommandHandler, MessageHandler, 
Filters, ConversationHandler)
import telegram
import logging

telegram_token = "BOT TOKEN"

updater = Updater(token=telegram_token, use_context=True);
dispatcher = updater.dispatcher;
logging.basicConfig(format='%(asctime)s - %(name)s - %(levelname)s - % 
(message)s', level=logging.INFO);

def mesgs_hand(update, context): 
    if(update.message.text == "Hi"):
        context.bot.forward_message(chat_id=update.effective_chat.id, 
        from_chat_id=update.effective_chat.id, 
        message_id=update.message.message_id, text="Hey there!"); 
        #this method forwards the message but without adding 'Hey there!' 

    elif(update.message.text == "Hello"):
        context.bot.send_message(chat_id=update.message.chat_id, text="Hello!"); 
        #this method just replies to the message without forwarding 

messages_handler = MessageHandler(Filters.text, mesgs_hand)
dispatcher.add_handler(messages_handler)


def bot():
    updater.start_polling();

if __name__ == "__main__":
    bot();
2
  • Can You Please Show Your Code? Commented Dec 1, 2019 at 16:00
  • Yes, sure. I've just added the code to the post. That's a sample but it works the same way Commented Dec 1, 2019 at 16:19

1 Answer 1

2

You can use the reply_to_message_id argument in the send_message function:

def mesgs_hand(update, context): 
    if(update.message.text == "Hi"):
        context.bot.send_message(
           chat_id=update.message.chat_id,
           reply_to_message_id=update.message.message_id,
           text="Hey there!")
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.