Set state for current user. :param state: State object or state name. :type state: Union[State, str] .. code-block:: python3 @bot.message_handler(commands=['start']) def start_ex(message: types.Message, state_context: StateContext):
(self, state: Union[State, str])
| 28 | self.bot_id = self.bot.bot_id |
| 29 | |
| 30 | def set(self, state: Union[State, str]) -> bool: |
| 31 | """ |
| 32 | Set state for current user. |
| 33 | |
| 34 | :param state: State object or state name. |
| 35 | :type state: Union[State, str] |
| 36 | |
| 37 | .. code-block:: python3 |
| 38 | |
| 39 | @bot.message_handler(commands=['start']) |
| 40 | def start_ex(message: types.Message, state_context: StateContext): |
| 41 | state_context.set(MyStates.name) |
| 42 | bot.send_message(message.chat.id, 'Hi, write me a name', reply_to_message_id=message.message_id) |
| 43 | """ |
| 44 | |
| 45 | chat_id, user_id, business_connection_id, bot_id, message_thread_id = resolve_context(self.message, self.bot.bot_id) |
| 46 | if isinstance(state, State): |
| 47 | state = state.name |
| 48 | return self.bot.set_state( |
| 49 | chat_id=chat_id, |
| 50 | user_id=user_id, |
| 51 | state=state, |
| 52 | business_connection_id=business_connection_id, |
| 53 | bot_id=bot_id, |
| 54 | message_thread_id=message_thread_id |
| 55 | ) |
| 56 | |
| 57 | def get(self) -> str: |
| 58 | """ |