Microsoft Bot Platform: Send a Connection Message

I am new to the Microsoft Bot platform. Now I am testing my code on an emulator. I want to send a Hello message as soon as you connect. Below is my code.

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: "-- APP ID --", appPassword: "-- APP PASS --" }); var bot = new builder.UniversalBot(connector); server.post('/api/message/',connector.listen()); bot.dialog('/', function (session) { session.send("Hello"); session.beginDialog('/createSubscription'); }); 

A welcome message is sent above the code when the user initiates a conversation. I want to send this message as soon as the user connects.

+7
botframework
source share
1 answer

Connect to the conversationUpdate event and check when the bot is added. After that, you can simply send a message or start a new dialog box (as in the code below, extracted from the ContosoFlowers Node.js sample , although there are many others that do the same).

 // Send welcome when conversation with bot is started, by initiating the root dialog bot.on('conversationUpdate', function (message) { if (message.membersAdded) { message.membersAdded.forEach(function (identity) { if (identity.id === message.address.bot.id) { bot.beginDialog(message.address, '/'); } }); } }); 
+13
source share

All Articles