@botmesh/core - v2.0.0-alpha.2
    Preparing search index...

    Interface TestChat

    A (chat, sender) view over the test bot. See createTestBot.

    interface TestChat {
        jid: string;
        chatId: string;
        senderId: string;
        isGroup: boolean;
        displayName: string;
        send(text: string, opts?: { type?: MessageType }): Promise<void>;
        sendLocation(location: InboundLocation): Promise<void>;
        sendLocation(
            lat: number,
            lng: number,
            extra?: Omit<InboundLocation, "latitude" | "longitude">,
        ): Promise<void>;
        sendMedia(
            kind:
                | "image"
                | "video"
                | "audio"
                | "voice"
                | "document"
                | "sticker"
                | "location"
                | "contact",
            source: MockMediaSource,
            caption?: string | MockMediaOptions,
        ): Promise<void>;
        sendReaction(
            emoji: string,
            target?: MessageRef | { to?: MessageRef; removed?: boolean },
        ): Promise<void>;
        sendInteraction(
            data: string,
            opts?: {
                kind?: "list" | "button" | "command" | "modal" | "autocomplete";
                id?: string;
            },
        ): Promise<void>;
        pressButton(target: string | number): Promise<PressedButton>;
        expectReply(matcher: string | RegExp, timeoutMs?: number): Promise<string>;
        expectNoReply(opts?: number | { timeout?: number }): Promise<void>;
        replies(): string[];
        sent(): TestSent[];
        lastReply(): TestSent | undefined;
        transcript(opts: TestTranscriptOptions & { as: "text" }): string;
        transcript(opts?: TestTranscriptOptions): Transcript;
        as(userId: string, opts?: { displayName?: string }): TestChat;
    }
    Index
    jid: string

    Alias of chatId.

    chatId: string

    The chat this view drives (the user id on a DM, the group id on a group).

    senderId: string

    The simulated user (ctx.senderId).

    isGroup: boolean
    displayName: string

    Push name the simulated user shows (ctx.senderInfo.displayName).

    • Simulate an inbound message from this user, then yield one macrotask so the dispatch starts.

      Parameters

      Returns Promise<void>

    • Simulate an inbound media message: ctx.body is the caption, loadMediaOf(ctx) resolves with the bytes. A { url } source without bytes makes the download reject with MediaUnavailableError (the mock never touches the network).

      Parameters

      • kind:
            | "image"
            | "video"
            | "audio"
            | "voice"
            | "document"
            | "sticker"
            | "location"
            | "contact"
      • source: MockMediaSource
      • Optionalcaption: string | MockMediaOptions

      Returns Promise<void>

    • Simulate a reaction (bot.on('reaction'), 'reaction' hooks). Default target: the bot's last message in this chat, else the user's last message. { removed: true } retracts it.

      Parameters

      Returns Promise<void>

    • Simulate a raw interaction (provider.interaction): data is what ctx.body / ctx.interaction.data carry.

      Parameters

      • data: string
      • Optionalopts: { kind?: "list" | "button" | "command" | "modal" | "autocomplete"; id?: string }

      Returns Promise<void>

    • Press a native button, list row or card button of the LAST interactive message the bot sent to this chat: by id, by title (case-insensitive) or 1-based index. The bot receives what a real press produces (a 'buttons' message whose body is the id).

      Parameters

      • target: string | number

      Returns Promise<PressedButton>

    • Resolve with the first reply matching matcher (already sent or arriving before the timeout).

      Parameters

      • matcher: string | RegExp
      • OptionaltimeoutMs: number

      Returns Promise<string>

    • Resolve when no reply beyond the ones already consumed exists now nor arrives within timeout (default 300 ms); reject listing the unexpected replies. Consumes nothing.

      Parameters

      • Optionalopts: number | { timeout?: number }

      Returns Promise<void>

    • Snapshot of all text/caption replies sent to this chat so far (buttons and lists: their text).

      Returns string[]

    • Same chat seen by another participant (groups). On a DM: another DM with the same bot.

      Parameters

      • userId: string
      • Optionalopts: { displayName?: string }

      Returns TestChat