Skip to content

Config handler

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

This is a private handler for configure 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 responsability of configuring the group discussion.

All the groups in wich 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 addition mode begins.

Addition 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 deletion mode.

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

Deletion 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 auntomatically change to addition mode and send you a notification.

Change between modes

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

  1. /add: Change to addition mode
  2. /del: Change to deletion mode

Step 3: Save the configuration

When you are done adding the option then type the additional command /done to save the configuration. This action has permanet effect, that means that you will not be able to edit the configuration. Also you 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 trow 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 deletion 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 addition mode.

This method simply handle the /add command, and change to addition 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 doc to know how it work.

Clone this wiki locally