Step
Represent a step in a Telegram bot command.
This is the base class for all user-defined steps.
Source code in django_telegram_app/bot/base.py
143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 | |
name
property
¶
Return the name of the step.
__call__(telegram_update)
¶
Execute the step.
This activates the appropriate translation based on the user's language code.
Source code in django_telegram_app/bot/base.py
__init__(command, unique_id=None, translate=None)
¶
Initialize the step.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
command
|
BaseBotCommand
|
The command this step belongs to. |
required |
unique_id
|
str | None
|
An optional unique identifier for the step. If not provided, the class name will be used. |
None
|
translate
|
bool | None
|
Whether to activate translation for this step. If None, the command's translate setting will be used. If True or False, it will override the command's setting. |
None
|
Source code in django_telegram_app/bot/base.py
add_waiting_for(message_key, data=None)
¶
Add waiting_for to the command settings.
The message_key will be used to store the user input in the callback data of the next step.
Source code in django_telegram_app/bot/base.py
cancel_callback(original_data=None, **kwargs)
¶
current_step_callback(original_data=None, **kwargs)
¶
Create a callback to reload the current step with the provided data.
get_callback_data(telegram_update)
¶
Get callback data from the telegram_update.
If the update is a message and not a command, check if we are waiting for user input. If so, retrieve the callback data using the waiting_for token and store the message text in the appropriate key in the callback data.
Otherwise, retrieve the callback data using the callback token from the update. If no callback token is provided, return default callback data.
Source code in django_telegram_app/bot/base.py
handle(telegram_update)
¶
next_step_callback(original_data=None, **kwargs)
¶
previous_step_callback(steps_back, original_data=None, **kwargs)
¶
Create a callback to return to the previous step.