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
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 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 | |
name
property
¶
Return the name of the step.
This is either the unique_id provided during initialization or the class 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
__str__()
¶
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
callback_to(step, original_data=None, **kwargs)
¶
Create a callback that routes to a specific 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.