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
id
string
expectedSender?
string
When set (e.g. in a group), ask only resolves for this participant.
Returns
Conversation
Overrides
Properties
client
protectedreadonlyclient:Client
Defined in: structures/Chat.ts:27
Inherited from
id
readonlyid:string
Defined in: structures/Chat.ts:29
Chat JID.
Inherited from
name?
readonlyoptionalname?:string
Defined in: structures/Chat.ts:31
Chat name, if known.
Inherited from
Accessors
isGroup
Get Signature
get isGroup():
boolean
Defined in: structures/Chat.ts:35
Is it a group?
Returns
boolean
Inherited from
state
Get Signature
get state():
ConversationState
Defined in: structures/Conversation.ts:69
Persistent per-chat state.
Returns
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
options?
Returns
Promise<Message>
Inherited from
block()
block():
Promise<void>
Defined in: structures/Chat.ts:100
Blocks this contact.
Returns
Promise<void>
Inherited from
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
options?
Returns
Promise<Message>
Inherited from
fromLink()
fromLink(
link,options?):Promise<Message>
Defined in: structures/Chat.ts:77
Sends whatever a link points to, auto-detecting the media kind.
Parameters
link
string
options?
Returns
Promise<Message>
Inherited from
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
options?
Returns
Promise<Message>
Inherited from
location()
location(
location,options?):Promise<Message>
Defined in: structures/Chat.ts:72
Parameters
location
options?
MiscMessageGenerationOptions
Returns
Promise<Message>
Inherited from
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
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
subscribePresence()
subscribePresence():
Promise<void>
Defined in: structures/Chat.ts:95
Subscribes to this contact's presence updates.
Returns
Promise<void>
Inherited from
text()
text(
body,options?):Promise<Message>
Defined in: structures/Chat.ts:47
Parameters
body
string
options?
Returns
Promise<Message>
Inherited from
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
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
unblock()
unblock():
Promise<void>
Defined in: structures/Chat.ts:105
Unblocks this contact.
Returns
Promise<void>
Inherited from
video()
video(
source,options?):Promise<Message>
Defined in: structures/Chat.ts:55
Parameters
source
options?
Returns
Promise<Message>
Inherited from
voice()
voice(
source,options?):Promise<Message>
Defined in: structures/Chat.ts:64
Voice note (audio with ptt: true).
Parameters
source
options?
MiscMessageGenerationOptions
Returns
Promise<Message>