Skip to main content

Bottender 1.2: Serverless, NLU Integration, and More

· 4 min read
C. T. Lin

We are excited to introduce Bottender 1.2 today, featuring:

All of these benefits are non-breaking and fully backward compatible. You can update it by running:

npm install bottender@latest

Serverless Supporting and Documentation

Since Bottender aims to be server-agnostic from the very beginning, this makes it possible to integrate with most of Node.js server frameworks and even serverless frameworks via HTTP protocol.

In the last few months, we were trying to deploy Bottender bot as a function on serverless environments such as Zeit Now or AWS Lambda and finally got succeeded.

You can check out step-by-step deployment guide for Zeit Now and AWS Lambda example for further details.

We understand that the bundle size and performance is quite sensitive while deploying to the serverless environment, more optimization and documentation or examples for Google Cloud Functions and Azure Functions are still ongoing.

Built-In Support for Intent Labeling

Bottender v1.2 introduces a new API context.setIntent() for labeling intent to the conversation context:

context.setIntent('greeting');

context.intent; // 'greeting'

Furthermore, you can also set handled status by context.setAsHandled() or context.setAsNotHandled():

context.setAsHandled();

context.isHandled; // true

context.setAsNotHandled();

context.isHandled; // false

This feature might found not very useful at this moment, but it's the key to the chatbot analytics, and we will soon introduce Chatbase and Dashbot integrations on top of it in the future release.

Packages to Integrate with NLU Services

In v1.2, we announced four npm packages to integrate with the great natural language understanding (NLU) services: Google Dialogflow, Microsoft LUIS, Microsoft QnA Maker and Rasa.

  • @bottender/dialogflow
  • @bottender/luis
  • @bottender/qna-maker
  • @bottender/rasa

To understand how those packages work, let's use Dialogflow as an example.

After installing the @bottender/dialogflow package, you can create an action using dialogflow function and put it in your bot:

const dialogflow = require('@bottender/dialogflow');

async function SayHello(context) {
await context.sendText('Hello!');
}

async function Unknown(context) {
await context.sendText('Sorry, I don’t know what you say.');
}

const Dialogflow = dialogflow({
projectId: process.env.GOOGLE_APPLICATION_PROJECT_ID,
actions: {
greeting: SayHello,
},
});

module.exports = async function App() {
return chain([
Dialogflow, //
Unknown,
]);
};

The bot in the above example says Hello! when the intent received from Dialogflow is greeting. Otherwise, it replies with a fallback sentence.

In addition, it automatically calls context.setIntent() or context.setAsNotHandled() methods that we mentioned earlier to label the intent and handled status under the hood.

Accessing Session Store

Bottender now supports accessing underlying session store configured by bottender.config.js:

const { getSessionStore } = require('bottender');

const sessionStore = getSessionStore();

You may want to get particular session data or clean up a specific session by manipulating the session store directly.

Accessing Messaging Clients

Bottender now supports accessing underlying messaging clients configured by bottender.config.js:

const { getClient } = require('bottender');

const messenger = getClient('messenger');
const line = getClient('line');

For example, to send a text message to the user by user id, you may call sendText method on Messenger client with some extra parameters:

const messenger = getClient('messenger');

messenger.sendText(USER_ID, 'Hello!', { tag: 'CONFIRMED_EVENT_UPDATE' });

And it could also be done in LINE by using pushText method:

const line = getClient('line');

line.pushText(USER_ID, 'Hello!');

What's Next?

We are always welcome any feedback and feature requests from the community; we believe that listening to the community makes perfect.

One of the most concerned topics in the period is TypeScript usage. Therefore, we will focus on polishing TypeScript types and better TypeScript support with Create Bottender App and Bottender core in the upcoming month.

WhatsApp connector is another notable feature we're currently working on. There are a lot of users ever request this feature.

Don't be shy! If you're using Bottender in your bot, send us a pull request to our users page to add your bot. Let us know how you use Bottender!