Skip to main content

Class: Context

Defined in: router/Context.ts:21

Context received by the router handlers. It gathers everything needed to read the incoming message and reply, without having to touch the socket.

Constructors

Constructor

new Context(client, message): Context

Defined in: router/Context.ts:25

Parameters

client

Client

Client that originated the context (low-level access if needed).

message

Message

Incoming message.

Returns

Context

Properties

client

readonly client: Client

Defined in: router/Context.ts:27

Client that originated the context (low-level access if needed).


match?

optional match?: RegExpMatchArray

Defined in: router/Context.ts:23

Result of the RegExp if the message matched a hears(/…/).


message

readonly message: Message

Defined in: router/Context.ts:29

Incoming message.

Accessors

args

Get Signature

get args(): string[]

Defined in: router/Context.ts:88

Arguments following the command (!add 2 3 -> ['2','3']).

Returns

string[]


chat

Get Signature

get chat(): Chat

Defined in: router/Context.ts:43

Fluent handle for the originating chat.

Returns

Chat


chatId

Get Signature

get chatId(): string

Defined in: router/Context.ts:38

Chat JID (user or group).

Returns

string


command

Get Signature

get command(): string | undefined

Defined in: router/Context.ts:79

Command name if the text starts with a prefix (!, /…), lowercased and without the prefix. undefined if it is not a command.

Returns

string | undefined


conversation

Get Signature

get conversation(): Conversation

Defined in: router/Context.ts:56

Rich per-user handle for this chat: state, history, and ask. Scoped to the sender, so ask/awaitReply resolve for the same person even in groups.

Returns

Conversation


fromMe

Get Signature

get fromMe(): boolean

Defined in: router/Context.ts:71

Is it your own message?

Returns

boolean


group

Get Signature

get group(): Group | undefined

Defined in: router/Context.ts:48

Group handle if this message comes from a group, otherwise undefined.

Returns

Group | undefined


isGroup

Get Signature

get isGroup(): boolean

Defined in: router/Context.ts:66

Does it come from a group?

Returns

boolean


sender

Get Signature

get sender(): Sender

Defined in: router/Context.ts:61

Identity of whoever sent the message (LID/PN-aware).

Returns

Sender


text

Get Signature

get text(): string

Defined in: router/Context.ts:33

Message text (caption included).

Returns

string

Methods

awaitReply()

awaitReply(options?): Promise<Context>

Defined in: router/Context.ts:178

Waits for the next reply in this chat (from the same sender by default). Great for question→answer flows.

Parameters

options?
fromSameSender?

boolean

timeoutMs?

number

Returns

Promise<Context>


delete()

delete(): Promise<void>

Defined in: router/Context.ts:170

Deletes the message for everyone.

Returns

Promise<void>


downloadMedia()

downloadMedia(): Promise<Buffer<ArrayBufferLike>>

Defined in: router/Context.ts:160

Downloads the message media as a Buffer.

Returns

Promise<Buffer<ArrayBufferLike>>


forward()

forward(to): Promise<Message>

Defined in: router/Context.ts:165

Forwards the message to another chat.

Parameters

to

string

Returns

Promise<Message>


react()

react(emoji): Promise<void>

Defined in: router/Context.ts:106

React to the message with an emoji (empty string to remove).

Parameters

emoji

string

Returns

Promise<void>


reply()

reply(content): Promise<Message>

Defined in: router/Context.ts:96

Reply quoting the message.

Parameters

content

string | AnyMessageContent

Returns

Promise<Message>


replyWithAudio()

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

Defined in: router/Context.ts:126

Parameters

source

MediaSource

options?

AudioOptions = {}

Returns

Promise<Message>


replyWithDocument()

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

Defined in: router/Context.ts:134

Parameters

source

MediaSource

options?

DocumentOptions = {}

Returns

Promise<Message>


replyWithImage()

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

Defined in: router/Context.ts:118

Parameters

source

MediaSource

options?

CaptionOptions = {}

Returns

Promise<Message>


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

Defined in: router/Context.ts:143

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

Parameters

string

options?

SendFromLinkOptions = {}

Returns

Promise<Message>


replyWithLocation()

replyWithLocation(location): Promise<Message>

Defined in: router/Context.ts:138

Parameters

location

LocationInput

Returns

Promise<Message>


replyWithTyping()

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

Defined in: router/Context.ts:111

Shows "typing…" for a moment, then replies, which feels more human.

Parameters

content

string

options?
delayMs?

number

Returns

Promise<Message>


replyWithVideo()

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

Defined in: router/Context.ts:122

Parameters

source

MediaSource

options?

CaptionOptions = {}

Returns

Promise<Message>


replyWithVoice()

replyWithVoice(source): Promise<Message>

Defined in: router/Context.ts:130

Parameters

source

MediaSource

Returns

Promise<Message>


seen()

seen(): Promise<void>

Defined in: router/Context.ts:155

Marks the message as read.

Returns

Promise<void>


send()

send(content): Promise<Message>

Defined in: router/Context.ts:101

Send to the same chat without quoting.

Parameters

content

string | AnyMessageContent

Returns

Promise<Message>


typing()

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

Defined in: router/Context.ts:150

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

Returns

Promise<() => Promise<void>>