Skip to content

Config handler

Lazaro Raul edited this page Nov 10, 2020 · 8 revisions

This is a private handler for the configuration of your groups discussions. This wiki show the configuration pipeline.

Step 1: Available chats

Once you use the create command in a group successfully, you automatically become the manager of that group and get the responsibility of configuring that group discussion.

All the groups in which you are the manager will be listed as an option when you use /config command.

Step 2: Adding/Deleting options.

When you select the chat that you want to configure, then the add mode begins.

Add mode

In order to add options you can start to write them one by one in separate messages. Every pure text message will be interpreted as a new option. Any time that you introduce a wrong option or simply want to delete some of the previous added you can change to delete mode.

Telegram handle different type of messages like text, pictures, locations, etc. Pure text refers to Telegram messages classified as text.

Delete mode

Every time you change to this mode, you will see all your saved options displayed in order to select the ones you want to delete one by one. Once all the options are deleted, the bot automatically change to add mode and send you a notification.

Change between modes

Once you are configuring a chat discussion, you can use the follow additional commands to change the current mode:

  1. /add: Change to add mode
  2. /del: Change to delete mode

Step 3: Save the configuration

When you are done adding the options, type the additional command /done to save the configuration. This action has permanent effect, that means that you will not be able to edit the configuration again. Also you will stop being the manager of the related group hence it will not appear any more when you use /config.

If you did not provide any option before using /done, the configuration process will fail. Don't worry you can try again later.

When you use the command successfully, the bot will publish the configuration in the related chat and start receiving the votes.

Cancel command

In any moment of the process you can use /cancel and stop configuration.


Navigating through the project files you can find the implementation of this handler in config.py. This second section pretend to explain what the methods listed there do.

This is the entry point of the configuration process, when you use /config command this method is triggered and the step-1 begins.

Once you provide the chat that you want to configure, this method check if you are the manager of the chat. If you are the manager then the step-2 begins, else the process will fail.

While you are in addition mode this method manage your options, and send a notification every time that you send a correct one.

Just as the previous method, while you are in delete mode this method manage your options, and send a notification every time that you send an option, even if the option is unknown. Also as mentioned here if you don't have options to delete automatically change to add mode.

This method simply handle the /add command, and change to add mode.

Just as the previous method, this one handle the /del command, and change to deletion mode only if there are options to delete.

This is the method that handle the /done command. Its behavior is described in step-3.

This last method handle the /cancel command and its function is simply stop the configuration.

Handler

Finally you can see the config_handler. Note that this is a ConversationHandler, read the python-telegram-bot documentation to know how it works.

Clone this wiki locally