Agent context
Every Agent SDK handler receives a context. The available surface depends on the event.
| Property or method | Purpose |
|---|---|
client | Node SDK client |
conversation | Current conversation |
message | Current decoded message, for message events |
getClientAddress() | Current client’s account identifier |
isDm(), isGroup() | Narrow the conversation type |
isAllowed, isDenied, isUnknown | Read conversation consent state |
sendRemoteAttachment(file, callback) | Encrypt, upload, and send a file |
usesCodec(Codec) | Narrow custom content |
isMarkdown(), isText() | Narrow text content |
isReply(), isReaction() | Narrow reply or reaction content |
isReadReceipt() | Narrow read-receipt content |
isRemoteAttachment() | Narrow remote-attachment content |
isTransactionReference() | Narrow transaction-reference content |
isWalletSendCalls() | Narrow wallet-call content |
sendReaction(content, schema?) | React to the current message |
sendMarkdownReply(markdown) | Reply with Markdown |
sendTextReply(text) | Reply with text |
getSenderAddress() | Resolve the sender’s first account identifier |
const agent: Agent<BuiltInContentTypes>
agent.NodeJS.EventEmitter<EventHandlerMap<BuiltInContentTypes>>.on<"message">(eventName: keyof EventHandlerMap<BuiltInContentTypes>, listener: (ctx: MessageContext<unknown, BuiltInContentTypes>) => void): Agent<BuiltInContentTypes>
Adds the listener function to the end of the listeners array for the event
named eventName. No checks are made to see if the listener has already
been added. Multiple calls passing the same combination of eventName and
listener will result in the listener being added, and called, multiple times.
server.on('connection', (stream) => { console.log('someone connected!');});
Returns a reference to the EventEmitter, so that calls can be chained.
By default, event listeners are invoked in the order they are added. The emitter.prependListener() method can be used as an alternative to add the
event listener to the beginning of the listeners array.
import { EventEmitter } from 'node:events';const myEE = new EventEmitter();myEE.on('foo', () => console.log('a'));myEE.prependListener('foo', () => console.log('b'));myEE.emit('foo');// Prints:// b// a
on("message", async (ctx: MessageContext<unknown, BuiltInContentTypes>
ctx) => { if (ctx: MessageContext<unknown, BuiltInContentTypes>
ctx.MessageContext<unknown, BuiltInContentTypes>.isText(): this is MessageContext<string>
Narrow the message to plain text content.
isText()) { const const sender: string | undefined
sender = await ctx: MessageContext<unknown, BuiltInContentTypes> & MessageContext<string, unknown>
ctx.MessageContext<MessageContentType = unknown, ContentTypes = unknown>.getSenderAddress(): Promise<string | undefined>
Resolve the sender's first identifier from the local inbox state.
getSenderAddress(); await ctx: MessageContext<unknown, BuiltInContentTypes> & MessageContext<string, unknown>
ctx.MessageContext<MessageContentType = unknown, ContentTypes = unknown>.sendTextReply(text: string): Promise<void>
Reply to this message with plain text content.
sendTextReply(`Hello ${const sender: string | undefined
sender ?? "there"}`); }});
The context exposes the underlying conversation. Use its SDK methods for members, messages, metadata, and content-type send helpers.

