Ask Your Question
0

What is the method for sending a message using a button in bale-messenger, using Python?

asked 2023-01-30 11:00:00 +0000

pufferfish gravatar image

edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted
3

answered 2021-06-26 06:00:00 +0000

qstack gravatar image

Here is an example code snippet using bale-bot library in Python to send a message using a button in bale-messenger:

from balebot.models.messages import TemplateMessageButton, TemplateMessage
from balebot.models.messages.banking.money_request_type import MoneyRequestType
from balebot.filters import TemplateResponseFilter
from balebot.handlers import MessageHandler
from balebot.updater import Updater

# create a button instance
button = TemplateMessageButton(text="Press me!", value="button_value")

# create a template message instance with the button
template_message = TemplateMessage("This is a message with a button", [button])

# set up the message handler
def handle_buttons(bot, update):
    button_value = update.template_message_response[0].value

    if button_value == "button_value":
        bot.send_message(template_message, update.get_effective_user(), success_callback=success_callback,
                         failure_callback=error_callback, parse_mode=None)

updater = Updater(token="YOUR_TOKEN_HERE", loop=loop)
dispatcher = updater.dispatcher

# register the message handler
dispatcher.register_conversation_handler(MessageHandler(TemplateResponseFilter(), handle_buttons))

# start the updater
updater.run()

This code creates a button instance, then creates a template message instance with the button, and finally sends the message when the button is pressed. The code also registers a message handler to listen for button responses from the user. When the user presses the button, the handle_buttons function is called and the button value is retrieved. If the button value matches the expected value, the template message is sent to the user.

edit flag offensive delete link more

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account. This space is reserved only for answers. If you would like to engage in a discussion, please instead post a comment under the question or an answer that you would like to discuss

Add Answer


Question Tools

Stats

Asked: 2023-01-30 11:00:00 +0000

Seen: 11 times

Last updated: Jun 26 '21