cha*_* go 3 javascript rest botkit
我在本地安装了botkit,并且工作正常.现在,我想将机器人与外部的restful api连接起来,例如:
人:你有多少客户连接?Bot:机器人在我的服务的其余api内部执行查询然后,回答Bot:连接了21个客户端.
有什么建议吗?
我们做了类似的操作,而且非常简单.使用某种排序或HTTP客户端对端点进行GET.我们使用request
npm.然后你只需要bot.reply
在回调中调用它.为了开始我正在使用的交互ambient
来听取机器人被邀请的任何频道,但你可以设置它,direct_message
如果这就是你如何滚动.
var request = require('request');
module.exports = function(controller) {
controller.hears(['How many clients'], 'ambient', function(bot, message) {
request('http://api.com/totalUsers', function (err, response, body) {
console.log('error: ', err); // Handle the error if one occurred
console.log('statusCode: ', response && response.statusCode); // Check 200 or such
console.log('This is the count of users: ', body.usersCount);
bot.reply(message, 'There are ' + body.usersCount + ' clients connected');
});
});
};
Run Code Online (Sandbox Code Playgroud)
归档时间: |
|
查看次数: |
1293 次 |
最近记录: |