Skip to main content
Version: Next

Context

Bottender context encapsulates many helpful methods and exports session, client, event, etc., which makes you easier to develop chatbots on different platforms.

For platform specific methods, please check out following links:

PlatformDoc
MessengerAPIReference-MessengerContext
LINEAPIReference-LineContext
SlackAPIReference-SlackContext
TelegramAPIReference-TelegramContext
ViberAPIReference-ViberContext
ConsoleAPIReference-ConsoleContext

platform

Example:

context.platform; // 'console', 'messenger', 'line', 'slack', 'telegram', 'viber'...

client

The client instance. Client type depends on your platform.

For more information, see Messaging APIs.

Example:

context.client; // client from [Messaging APIs](https://github.com/Yoctol/messaging-apis)

event

The event instance. Event type depends on your platform.

Example:

context.event;

session

The session instance.

Example:

context.session.id;

state

The state object.

Example:

context.state;

setState(state)

Shallow merge changes to the state.

Example:

context.setState({
oneOfMyStateKey: '...',
});

resetState()

Reset the state to the initial state.

Example:

context.resetState();

typing(milliseconds)

Delay and show indicators for milliseconds.

ParamTypeDescription
millisecondsNumberWait for milliseconds and show typing.

Example:

async function MyAction(context) {
await context.typing(100); // turn on typing mode and wait 0.1 secs.
await context.sendText('Hello World');
}

sendText(text, options)

Send text to the owner of the session.

Example:

context.sendText('Hello');