Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save nwhitmont/d9910fcf7ab4048ee37bd5c789cfc375 to your computer and use it in GitHub Desktop.
Save nwhitmont/d9910fcf7ab4048ee37bd5c789cfc375 to your computer and use it in GitHub Desktop.
// Welcome message for Node.js bot
bot.on('conversationUpdate', function (message) {
if (message.membersAdded) {
message.membersAdded.forEach(function (identity) {
if (identity.id == message.address.bot.id) {
// Bot is joining conversation
// - For WebChat channel you'll get this on page load.
var reply = new builder.Message()
.address(message.address)
.text("Welcome to my page");
bot.send(reply);
} else {
// User is joining conversation
// - For WebChat channel this will be sent when user sends first message.
// - When a user joins a conversation the address.user field is often for
// essentially a system account so to ensure we're targeting the right
// user we can tweek the address object to reference the joining user.
// - If we wanted to send a private message to teh joining user we could
// delete the address.conversation field from the cloned address.
var address = Object.create(message.address);
address.user = identity;
var reply = new builder.Message()
.address(address)
.text("Hello %s", identity.name);
bot.send(reply);
}
});
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment