BotFrameworkのMembersAdded
を使うと、Slackのチャンネルに新しく入ってきた人に挨拶できるみたいなので、少しやってみました(^O^)v
※MembersAdded
のドキュメントはこちら
var restify = require('restify');
var builder = require('botbuilder');
var server = restify.createServer();
server.listen(process.env.port || process.env.PORT || 3978, function () {
console.log('%s listening to %s', server.name, server.url);
});
var connector = new builder.ChatConnector({
appId: 'ID',
appPassword: 'PASSWORD'
});
var bot = new builder.UniversalBot(connector);
server.post('/api/messages', connector.listen());
// ここで入ってきた事を取得して、挨拶
bot.on('conversationUpdate', function (message) {
if (message.membersAdded) {
var membersAdded = message.membersAdded
.map((m) => {
var isSelf = m.id === message.address.bot.id;
return (isSelf ? message.address.bot.name : m.name);
})
.join(', ');
var reply = new builder.Message()
.address(message.address)
.text('いらっしゃいませー ' + membersAdded + ' さん');
bot.send(reply);
}
});
退出時はmembersRemoved
を使うと、取れるみたいです。
if (message.membersRemoved) {
var membersRemoved = message.membersRemoved
.map((m) => {
var isSelf = m.id === message.address.bot.id;
return (isSelf ? message.address.bot.name : m.name);
})
.join(', ');
var reply = new builder.Message()
.address(message.address)
.text('ばいばーい' + membersRemoved);
bot.send(reply);
}