Skip to main content

Class: Conversation

Defined in: structures/Conversation.ts:58

A per-user chat experience: everything Chat can send, plus persistent per-chat state, recent history, and ask to prompt the user and await their reply.

Get one with client.conversation(jid) or, inside a handler, ctx.conversation.

Example

wa.command('name', async (ctx) => {
const convo = ctx.conversation;
const answer = await convo.ask('What is your name?');
await convo.state.set('name', answer.text);
await convo.text(`Nice to meet you, ${answer.text}!`);
});

Extends

Constructors

Constructor

new Conversation(client, id, expectedSender?): Conversation

Defined in: structures/Conversation.ts:59

Parameters

client

Client

id

string

expectedSender?

string

When set (e.g. in a group), ask only resolves for this participant.

Returns

Conversation

Overrides

Chat.constructor

Properties

client

protected readonly client: Client

Defined in: structures/Chat.ts:27

Inherited from

Chat.client


id

readonly id: string

Defined in: structures/Chat.ts:29

Chat JID.

Inherited from

Chat.id


name?

readonly optional name?: string

Defined in: structures/Chat.ts:31

Chat name, if known.

Inherited from

Chat.name

Accessors

isGroup

Get Signature

get isGroup(): boolean

Defined in: structures/Chat.ts:35

Is it a group?

Returns

boolean

Inherited from

Chat.isGroup


state

Get Signature

get state(): ConversationState

Defined in: structures/Conversation.ts:69

Persistent per-chat state.

Returns

ConversationState

Methods

ask()

ask(question, options?): Promise<Context>

Defined in: structures/Conversation.ts:100

Sends a prompt and resolves with the user's next reply in this chat. In groups, restricts to the expected sender when known.

Parameters

question

string

options?

AskOptions = {}

Returns

Promise<Context>


askText()

askText(question, options?): Promise<string>

Defined in: structures/Conversation.ts:111

Like ask, but resolves with the reply text directly.

Parameters

question

string

options?

AskOptions = {}

Returns

Promise<string>


audio()

audio(source, options?): Promise<Message>

Defined in: structures/Chat.ts:59

Parameters

source

MediaSource

options?

AudioOptions

Returns

Promise<Message>

Inherited from

Chat.audio


block()

block(): Promise<void>

Defined in: structures/Chat.ts:100

Blocks this contact.

Returns

Promise<void>

Inherited from

Chat.block


confirm()

confirm(question, options?): Promise<boolean>

Defined in: structures/Conversation.ts:128

Asks the user to confirm and resolves to true/false. Great for confirming a value ("Is your email …? (yes/no)"). Unrecognized answers are re-prompted up to retries times; if still unclear, resolves to false.

Parameters

question

string

options?

ConfirmOptions = {}

Returns

Promise<boolean>

Example

const email = await convo.askText('What is your email?');
if (await convo.confirm(`Confirm your email is ${email}? (yes/no)`)) {
await convo.state.set('email', email);
}

document()

document(source, options?): Promise<Message>

Defined in: structures/Chat.ts:68

Parameters

source

MediaSource

options?

DocumentOptions

Returns

Promise<Message>

Inherited from

Chat.document


fromLink(link, options?): Promise<Message>

Defined in: structures/Chat.ts:77

Sends whatever a link points to, auto-detecting the media kind.

Parameters

string

options?

SendFromLinkOptions

Returns

Promise<Message>

Inherited from

Chat.fromLink


history()

history(): Message[]

Defined in: structures/Conversation.ts:74

Recent messages seen in this chat (oldest first).

Returns

Message[]


image()

image(source, options?): Promise<Message>

Defined in: structures/Chat.ts:51

Parameters

source

MediaSource

options?

CaptionOptions

Returns

Promise<Message>

Inherited from

Chat.image


location()

location(location, options?): Promise<Message>

Defined in: structures/Chat.ts:72

Parameters

location

LocationInput

options?

MiscMessageGenerationOptions

Returns

Promise<Message>

Inherited from

Chat.location


profilePictureUrl()

profilePictureUrl(highRes?): Promise<string | undefined>

Defined in: structures/Chat.ts:90

Profile picture URL of this chat/contact.

Parameters

highRes?

boolean = false

Returns

Promise<string | undefined>

Inherited from

Chat.profilePictureUrl


send()

send(content, options?): Promise<Message>

Defined in: structures/Chat.ts:40

Sends raw Baileys content (or text).

Parameters

content

string | AnyMessageContent

options?

MiscMessageGenerationOptions

Returns

Promise<Message>

Inherited from

Chat.send


subscribePresence()

subscribePresence(): Promise<void>

Defined in: structures/Chat.ts:95

Subscribes to this contact's presence updates.

Returns

Promise<void>

Inherited from

Chat.subscribePresence


text()

text(body, options?): Promise<Message>

Defined in: structures/Chat.ts:47

Parameters

body

string

options?

TextOptions

Returns

Promise<Message>

Inherited from

Chat.text


toMessages()

toMessages(options?): ChatMessage[]

Defined in: structures/Conversation.ts:84

Builds a { role, content } transcript from the chat history: your messages become assistant turns, the other party's become user turns, with an optional system prompt first. Feed it to your own agent (e.g. the Vercel AI SDK). This SDK stays out of the LLM's way.

Parameters

options?
limit?

number

systemPrompt?

string

Returns

ChatMessage[]


typing()

typing(): Promise<() => Promise<void>>

Defined in: structures/Chat.ts:82

Shows "typing…". Returns a function to stop showing it.

Returns

Promise<() => Promise<void>>

Inherited from

Chat.typing


unblock()

unblock(): Promise<void>

Defined in: structures/Chat.ts:105

Unblocks this contact.

Returns

Promise<void>

Inherited from

Chat.unblock


video()

video(source, options?): Promise<Message>

Defined in: structures/Chat.ts:55

Parameters

source

MediaSource

options?

CaptionOptions

Returns

Promise<Message>

Inherited from

Chat.video


voice()

voice(source, options?): Promise<Message>

Defined in: structures/Chat.ts:64

Voice note (audio with ptt: true).

Parameters

source

MediaSource

options?

MiscMessageGenerationOptions

Returns

Promise<Message>

Inherited from

Chat.voice