![]() answer( "Invalid password.")ĭata = notification. message_text if not 8 <= len( password) <= 20: value) def username_handler( notification: Notification) -> None: message( command = "cancel") def cancel_handler( notification: Notification) -> None: message( state = None) def message_handler( notification: Notification) -> None: USERNAME = "username" PASSWORD = "password" bot. It can be found by calling nder.įrom whatsapp_chatbot_python import BaseStates, GreenAPIBot, Notification bot = GreenAPIBot( If no data exists, the data will be created If the state exists, it updates the data. If the state exists, it changes the data to the new data If the state exists, it returns the data in the form of a dictionary (dict) If not, it creates a new stateĭeletes the user's state. If the state exists then the data will be deleted Returns a state class with state name and user data You also have the option to save the user's data in his state. The manager has methods for getting, setting, updating and deleting state. We need to use notification.state_manager. Import the BaseStates class and inherit from it. To manage user states, we need to create states. Notification.answer_buttons("Choose a color", [Īs an example, a bot was created for user registration. How to add filters through the buttons_handler(notification: Notification) -> None: Your function will be executed if the prefix and the command match your values completely R"message" or (r"message", re.IGNORECASE) Your function will be executed if the text matches the regular expression pattern Your function will be executed if the text fully matches the text Filter nameĬhats or chats from which you want to receive or sender or senders from whom you want to receive or type or types of message to be handled Below is a table with filter names and possible values. The message text can be filtered by text, command, and regularĮxpressions. To filter chat, sender, and message type, you can useĪ string ( str) or a list of strings ( list). Messages can be filtered by chat, sender, message type, and text. Link to example: message_handler(notification: Notification) -> None: ![]() In this example, the bot will only answer the message message. You can stop the bot with the key combination Ctrl + C. To start the bot, call the bot.run_forever function. This can be done with the ĭecorator as in the example or with the _handler function. ![]() ![]() Next, you need to add the handler function to the list of handlers. You don't need to pass the chatId parameter because it is automatically taken from the Send a text message in response to a notification, you need to call the notification.answer function and pass there Parameter is the class where the notification object ( event) and the functions to answer the message are stored. To start receiving messages, you must create a handler function with one parameter ( notification). How to start receiving and answering messages Notifications category, enable all notifications that you want to receive. Select an instance from the list and click on it. To start receiving incoming notifications, you need to set up an instance.
0 Comments
Leave a Reply. |
Details
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |