Skip to main content
The context object contains information about the incoming message and user. It’s the first parameter passed to all flow callback functions.

Usage

const flow = addKeyword('hello')
  .addAnswer('Hi!', null, async (ctx, { flowDynamic }) => {
    console.log(ctx.body) // message text
    console.log(ctx.from) // sender number
  })

Properties

body
string
required
The text content of the incoming message.
from
string
required
The phone number of the message sender (e.g., “[email protected]”).
name
string
The name of the contact who sent the message.
host
object
Information about the bot host.
pushName
string
The push name (display name) of the sender.

Additional Properties

Depending on the message type, the context may include additional properties:
mediaUrl
string
URL of the media file (for media messages).
mediaType
string
Type of media: image, video, audio, document.
caption
string
Caption text for media messages.
lat
number
Latitude for location messages.
lng
number
Longitude for location messages.

Example

const welcomeFlow = addKeyword(['hello', 'hi'])
  .addAnswer(
    'Welcome!',
    null,
    async (ctx) => {
      const { body, from, name } = ctx
      
      console.log(`Message: ${body}`)
      console.log(`From: ${from}`)
      console.log(`Name: ${name}`)
    }
  )

Build docs developers (and LLMs) love