API Reference¶
Conversation¶
- class telegrampy.ext.conversations.Conversation(*, chat: Chat, user: User, client: Client, abort_command: str = 'abort', timeout: float | None = None)¶
Represents a conversation with another user in Telegram
- Parameters:
chat (
telegrampy.Chat) – The chat that the conversation is taking place in.user (
telegrampy.User) – The user to listen to messages from.client (
Client) – The client associated with the conversation.abort_command (
str| None) – The name of the command that will stop the conversation. Defaults to'abort'.timeout (
float| None) – How long to wait before the conversation times out. Defaults toNone.
- await abort(message) None¶
This function is a coroutine.
Called when the abort command is used during a conversation. Can be overriden by subclasses.
- await ask(question: Question, *, send_question: bool = True) None¶
This function is a coroutine.
Ask a question.
- Parameters:
- Raises:
.RuntimeError – The conversation hasn’t been started
ValueError – The question provided is not registered to the conversation
- classmethod from_message(message: Message, *, client: Client, abort_command: str = 'abort', timeout: float | None = None) Self¶
Constructs a new conversation from a a
Message.:param
Message: The message associated with the conversation. :paramClient: The client associated with the conversation.
Question¶
- telegrampy.ext.conversations.question(text: str, *, starting_question: bool = False) Callable[[CoroFunc], Question]¶
Turn a function into a conversation
Question.
- class telegrampy.ext.conversations.Question(func: QuestionCallbackType, text: str, *, starting_question: bool = False)¶
Represents a question the bot will ask the user.
- Parameters:
func (coroutine) – The question’s callback, taking two arguments: The
Conversationinstance and theMessagethat triggered the callback.text (
str) – The content to ask the user.starting_question (
bool| None) – Designates the question as the starting question. Defaults toFalse.