Botkit 聊天机器人搭建积木 项目简介
Botkit 是一个用于构建聊天机器人、应用和定制集成的工具,旨在简化设计和运行在消息传递平台中底层交互的细节,为开发者提供构建任意类型的机器人的必要工具,也被称为“搭建积木”。一些机器人像人一样说话,其他人则默默地在后台工作,还有另外一些机器人的界面很像现代的移动应用。 Botkit 提供了一个易于理解的接口,用于发送和接收消息,以便开发者可以专注于构建新颖的应用程序和体验,而不是处理 API 端点。Botkit Code Basicsvar Botkit = require('botkit');
var controller = Botkit.slackbot({
clientId: process.env.clientId,
clientSecret: process.env.clientSecret,
studio_token: process.env.studio_token,
});
controller.setupWebserver(process.env.port,function(err,webserver) {
controller.createWebhookEndpoints(controller.webserver);
controller.createOauthEndpoints(controller.webserver);
});
controller.hears('hello','direct_mention,direct_message', function(bot, message) {
bot.reply(message,'Howdy!');
});
controller.hears('tacos','direct_mention,direct_message', function(bot, message) {
bot.startConversation(message, function(err, convo) {
convo.say('Oh boy, taco time!');
convo.ask('What type of taco do you want?', function(answer, convo) {
var taco_type = answer.text;
// do something with this answer!
// storeTacoType(convo.context.user, taco_type);
convo.say('YUMMMM!!!'); // add another reply
convo.next(); // continue with conversation
});
});
});
var controller = Botkit.slackbot({
clientId: process.env.clientId,
clientSecret: process.env.clientSecret,
studio_token: process.env.studio_token,
});
controller.setupWebserver(process.env.port,function(err,webserver) {
controller.createWebhookEndpoints(controller.webserver);
controller.createOauthEndpoints(controller.webserver);
});
controller.hears('hello','direct_mention,direct_message', function(bot, message) {
bot.reply(message,'Howdy!');
});
controller.hears('tacos','direct_mention,direct_message', function(bot, message) {
bot.startConversation(message, function(err, convo) {
convo.say('Oh boy, taco time!');
convo.ask('What type of taco do you want?', function(answer, convo) {
var taco_type = answer.text;
// do something with this answer!
// storeTacoType(convo.context.user, taco_type);
convo.say('YUMMMM!!!'); // add another reply
convo.next(); // continue with conversation
});
});
});