Vinay Jayaram
Vinay Jayaram

Reputation: 1005

Azure bot framework: Show welcome message

I am trying to create a bot which gives me a Welcome message whenever I refresh or initiate the bot (NOTE: Without typing anything initially) using NodeJS.

I have used following code

var bot = new builder.UniversalBot(connector, [
    function (session) {
        builder.Prompts.text(session, 'Hi! What is your name?');
    }
]);

But this doesn't help me it gives me a message only when I type something

enter image description here

Upvotes: 2

Views: 1117

Answers (1)

Shaunak
Shaunak

Reputation: 18028

Looks like you need to use the conversationUpdate callback. Try the following snippet derived from skype example

bot.on('conversationUpdate', function(message) {
    // Send a hello message when bot is added
    if (message.membersAdded) {
        message.membersAdded.forEach(function(identity) {
            if (identity.id === message.address.bot.id) {
                var reply = new builder.Message().address(message.address).text("Hi! What is your name?");
                bot.send(reply);
            }
        });
    }
});

Upvotes: 2

Related Questions