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:

Platform Doc
Console APIReference-ConsoleContext
Messenger APIReference-MessengerContext
LINE APIReference-LineContext
Slack APIReference-SlackContext
Telegram APIReference-TelegramContext
Viber APIReference-ViberContext

platform

Example:

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

client

The client instance. Client type depends on your platform.

See Messaging APIs for more information.

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.user.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.

Param Type Description
milliseconds Number Wait for milliseconds and show typing.

Example:

bot.onEvent(async 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');