Represents a conversation inside some chat.

A conversation keeps track of any messages sent or edited since it was started and until it was stopped, and allows waiting for events in it.

If you need a conversation across multiple chats, you should use multiple Conversation objects and synchronize them manually.

Constructors

Properties

Accessors

  • get inputPeer(): TypeInputPeer
  • Get the input peer that this conversation is with

    Returns TypeInputPeer

  • get lastMessage(): number
  • ID of the very last message in this conversation.

    Returns number

  • get lastReceivedMessage(): number
  • ID of the last incoming message in this conversation.

    Note that before any messages were received since the start of the conversation, this will equal to lastMessage

    Returns number

Methods

  • Mark the conversation as read up to a certain point.

    By default, reads until the last message. You can pass message=null to read the entire conversation, or pass message ID to read up until that ID.

    Parameters

    • __namedParameters: { clearMentions?: boolean; message?: null | number } = {}

    Returns Promise<void>

  • Send a media to this conversation.

    Wrapper over sendMedia

    Parameters

    • ...params: [
          media: string
          | InputMediaLike,
          params?: CommonSendParams & {
              caption?: InputText;
              invert?: boolean;
              progressCallback?: (uploaded: number, total: number) => void;
              replyMarkup?: ReplyMarkup;
          },
      ]

    Returns Promise<Message>

  • Send a media group to this conversation.

    Wrapper over sendMediaGroup

    Parameters

    • ...params: [
          medias: (string | InputMediaLike)[],
          params?: CommonSendParams & {
              invertMedia?: boolean;
              progressCallback?: (
                  index: number,
                  uploaded: number,
                  total: number,
              ) => void;
          },
      ]

    Returns Promise<Message[]>

  • Send a text message to this conversation.

    Wrapper over sendText

    Parameters

    • ...params: [
          text: InputText,
          params?: CommonSendParams & {
              disableWebPreview?: boolean;
              invertMedia?: boolean;
              replyMarkup?: ReplyMarkup;
          },
      ]

    Returns Promise<Message>

  • Start the conversation

    Returns Promise<void>

  • Stop the conversation

    Returns void

  • Wait for a message to be edited in the conversation. By defaults wait for the last message sent by the other party (at the moment) to be edited.

    Returns the edited message.

    Parameters

    • Optionalfilter: (msg: Message) => MaybePromise<boolean>

      Filter for the handler. You can use any filter you can use for dispatcher

    • Optionalparams: { message?: number; timeout?: null | number }
      • Optionalmessage?: number

        Message for which to wait for reply for.

        last received message
        
      • Optionaltimeout?: null | number

        Timeout for the handler in ms. Pass null to disable.

        When the timeout is reached, TimeoutError is thrown.

        15000 (15 sec)

    Returns Promise<Message>

  • Wait for a new message in the conversation

    Parameters

    • Optionalfilter: (msg: Message) => MaybePromise<boolean>

      Filter for the handler. You can use any filter you can use for dispatcher

    • Optionaltimeout: null | number = 15000

      Timeout for the handler in ms. Pass null to disable. When the timeout is reached, MtTimeoutError is thrown.

    Returns Promise<Message>

  • Wait for the message to be read by the other party.

    Note that reading the message doesn't mean the response was sent, and if the response was sent, it doesn't mean that the message was read.

    Parameters

    • Optionalmessage: number

      Message for which to wait for read for. Defaults to last message.

    • timeout: null | number = 15000

      Timeout for the handler in ms, def. 15 sec. Pass null to disable. When the timeout is reached, TimeoutError is thrown.

    Returns Promise<void>

  • Wait for the reply for the given message' (def. the last one) in the conversation.

    Parameters

    • Optionalfilter: (msg: Message) => MaybePromise<boolean>

      Filter for the handler. You can use any filter you can use for dispatcher

    • Optionalparams: { message?: number; timeout?: null | number }
      • Optionalmessage?: number

        Message for which to wait for reply for.

        last sent/received message
        
      • Optionaltimeout?: null | number

        Timeout for the handler in ms. Pass null to disable.

        When the timeout is reached, TimeoutError is thrown.

        15000 (15 sec)

    Returns Promise<Message>

  • Wait for a response for the given message (def. the last one) in the conversation.

    A message is considered to be a response if it was sent after the given one.

    Parameters

    • Optionalfilter: (msg: Message) => MaybePromise<boolean>

      Filter for the handler. You can use any filter you can use for dispatcher

    • Optionalparams: { message?: number; timeout?: null | number }
      • Optionalmessage?: number

        Message for which to wait for response for.

        last sent/received message
        
      • Optionaltimeout?: null | number

        Timeout for the handler in ms. Pass null to disable.

        When the timeout is reached, TimeoutError is thrown.

        15000 (15 sec)

    Returns Promise<Message>

  • Helper method that calls start, the provided function and then stop.

    It is preferred that you use this function rather than manually starting and stopping the conversation.

    If you don't stop the conversation when you're done, it will lead to memory leaks.

    Type Parameters

    • T

    Parameters

    Returns Promise<T>

  • Pass the update to the conversation manager and all registered conversations on this client.

    Parameters

    Returns boolean

    true if the update was handled by some conversation