Skip to content

how would i implement a repeat send command #2259

@DonKannalie

Description

@DonKannalie

Not an issue! Just a question...

Please answer these questions before submitting your issue. Thanks!

  1. What version of pyTelegramBotAPI are you using?
    4.17.0

  2. What OS are you using?
    Ubuntu 22.04

  3. What version of python are you using?
    3.10.12

How would i implement a '/repeat' last command?

Kinda simplified pseudocode example:

previous_message = None

@bot.middleware_handler(update_types=["message"])
def modify_message(bot_instance, message):
    global previous_message

    d = get_command_elements(message)
    if d["command"] != "repeat":
        previous_message = message
        
@bot.message_handler(commands=["repeat"])
def repeat(message):
    global previous_message

    bot.forward_message(
        previous_message.chat.id, message.chat.id, previous_message.message_id
    )

# run '/status' command 
@bot.message_handler(commands=["status"])
def status_info(message):
    global previous_message

    previous_message = message
    status = get_status()
    
    bot.send_message(message.chat.id, status)

image
/repeat works, I can just click the forwarded message and it repeats the command

I also have a command that can be run either as '/info' (as a reply to a message) or as '/info item' to query info for 'item'.

send "/info item" as message

image

#OR: send "/info" as a reply to a message
image

@bot.message_handler(commands=["info"])
def info(message):
    global previous_message

    previous_message = message

    if 'item' in message.text:
        item = extract_item(message.text)
        result = run_query(item)
    elif message.json["reply_to_message"]["text"]:
        item = extract_item(message.json["reply_to_message"]["text"])
        result = run_query(item)
   
    bot.send_message(message.chat.id, result)

image
Does not work, as the forwarded 'command' only hotlinks "/info" not "/info item"
Same goes with the reply-type command...

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions