Getting Started
Requirements
Bottender highly depends on async function syntax, so you must make sure your runtime meets the following requirements:
- node >= 7.6
Installing Bottender
To start using it, install bottender
globally from the npm registry:
npm install -g bottender
Or install it by yarn:
yarn global add bottender
Initialize
After installed, we can start to create a new bot with bottender init
command:
This will create a folder with a bottender.config.js
file within:
const { ConsoleBot } = require('bottender');
const bot = new ConsoleBot();
bot.onEvent(async (context) => {
await context.sendText('Hello World');
});
bot.createRuntime();
We can skip over this file and jump to see the result of the execution:
npm run dev
As you can see, we just got a bot that always replies "Hello World" in the console.
Teach Bot to Echo
Open the file and edit the following lines of code:
bot.onEvent(async context => {
- await context.sendText('Hello World');
+ if (context.event.isText) {
+ await context.sendText(context.event.text);
+ }
});
And the server will be restarted automatically.
That's it!
Next Steps
You just created your first bot with Bottender! To dive deeper into bot development, you may want to determine the intents behind what the user says. For more information on intent understanding, check out its documentation.