-
Notifications
You must be signed in to change notification settings - Fork 2
API References
Vu Bao Nhu edited this page Feb 18, 2021
·
3 revisions
You can create a new instance of BotScript with a simple setup.
const bot = new BotScript();
bot.parse('+ hello bot\n - Hello human!');
bot.handleAsync('Hello bot').then((reply) => {
console.log(reply.speechResponse); // Hello human!
});
You may await initialization to ensure that bot is ready!
const bot = new BotScript();
bot.parse('/include: https://raw.githubusercontent.com/yeuai/botscript/master/examples/hello.bot');
// await bot.init() to ensure the one ready.
bot.init().then(async () => {
const reply = await bot.handleAsync('hello bot');
console.log(reply.speechResponse); // Hello, human!
});
Parse and import script documents according to BotScript Document Specification.
- More details checkout github hompage: README.md
Example:
const bot = new BotScript();
bot.parse(`
// declaration: plugin usage
> addTimeNow
// declaration: command
@ geoip https://api.ipify.org/?format=json
# declaration: a story with conditional command
+ what is my ip
* true @> geoip
- Here is your ip: $ip
# declaration: an other story
+ what time is it
- it is $time
`);
Parse and import script documents from URL which returns BotScript Document Specification.
Example:
const bot = new BotScript();
await bot.parseUrl('https://raw.githubusercontent.com/yeuai/botscript/master/examples/hello.bot');
Ensure all directives and internal process are initialized.
Example:
const bot = new BotScript();
await bot.init(); // Wait for bot ready!
Handle human request message, returns a reply or emit events corresponding matched.
Example:
const reply = await bot.handleAsync('hello');
console.log(reply.speechResponse); // Hello, human!
Notify the bot is ready!
Example:
bot.on('ready', () => {
bot.logger.info('Bot is ready!')
})
Notify the bot is ready!
Notify the bot is preparing to parse content of scripts.
bot.on('command', (err: Error, req: Request, ctx: Context, command.name: string, result: any) => void)
A command executed
Captures all events from bot handling.