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 to None.

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:
  • question (Question) – The Question to ask

  • send_question (bool) – Whether to send the question’s text before waiting for a response. Defaults to True.

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. :param Client: The client associated with the conversation.

await start(*, wait: bool = False) None

Start the conversation

Parameters:

wait (bool | None) – Whether to wait until the conversation is completed before returning.

stop() None

This function is a coroutine.

Stops the conversation.

await timed_out() None

This function is a coroutine.

Called when the conversation times out. Can be overriden by subclasses.

Question

telegrampy.ext.conversations.question(text: str, *, starting_question: bool = False) Callable[[CoroFunc], Question]

Turn a function into a conversation Question.

Parameters:
  • text (str) – The question to ask the user.

  • starting_question (bool | None) – Designates a Question as the starting question. Defaults to False.

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 Conversation instance and the Message that triggered the callback.

  • text (str) – The content to ask the user.

  • starting_question (bool | None) – Designates the question as the starting question. Defaults to False.