Microsoft Bot Framework, can it start a conversation

I am working with Microsoft Bot Framework on Azure and have a working bot. However, at the moment it waits for an empty status and just reacts. I would like to add / start a conversation with something like "hello, how can I help you?"

Here is my code:

"use strict";
var builder = require("botbuilder");
var botbuilder_azure = require("botbuilder-azure");
var path = require('path');

var useEmulator = (process.env.NODE_ENV == 'development');

var connector = useEmulator ? new builder.ChatConnector() : new botbuilder_azure.BotServiceConnector({
    appId: process.env['MicrosoftAppId'],
    appPassword: process.env['MicrosoftAppPassword'],
    stateEndpoint: process.env['BotStateEndpoint'],
    openIdMetadata: process.env['BotOpenIdMetadata']
});

var bot = new builder.UniversalBot(connector);
bot.localePath(path.join(__dirname, './locale'));

// Make sure you add code to validate these fields
var luisAppId = process.env.LuisAppId;
var luisAPIKey = process.env.LuisAPIKey;
var luisAPIHostName = process.env.LuisAPIHostName || 'westus.api.cognitive.microsoft.com';

const LuisModelUrl = 'https://' + luisAPIHostName + '/luis/v1/application?id=' + luisAppId + '&subscription-key=' + luisAPIKey;

// Main dialog with LUIS
var recognizer = new builder.LuisRecognizer(LuisModelUrl);
var intents = new builder.IntentDialog({ recognizers: [recognizer] })
/*
.matches('<yourIntent>')... See details at http://docs.botframework.com/builder/node/guides/understanding-natural-language/
*/

.matches('None', (session, args) => {
    session.send('Hi, this is the None handler. You said: \'%s\'.', session.message.text);
})

.matches('get_price', (session, args) => {
    session.send('Hi, you asked about the cost of a service: oil change: $10, brakes: $50, transmission: $200: \'%s\'.', session.message.text);
})

.matches('get_service', (session, args) => {
    session.send('Hi, you asked about car service options, here they are: oil change, brakes, and transmissions');
})

.matches('cant_service', (session, args) => {
    session.send('Sorry, we do not offer that service: \'%s\'.', session.message.text);
})

.matches('schedule_apt', (session, args) => {
    session.send('Hi, you asked about scheduling an appointment, please call 1-800-fix-cars to schedule');
})

.matches('greeting', (session, args) => {
    session.send('Hi you!');
})


.onDefault((session) => {
    session.send('Sorry, I did not understand \'%s\'.', session.message.text);
});

bot.dialog('/', intents);    

if (useEmulator) {
    var restify = require('restify');
    var server = restify.createServer();
    server.listen(3978, function() {
        console.log('test bot endpont at http://localhost:3978/api/messages');
    });
    server.post('/api/messages', connector.listen());    
} else {
    module.exports = { default: connector.listen() }
}

      

+3


source to share


1 answer


you can try the following code and modify it according to your needs. you can find this and many other useful snippets for the node SDK here

bot.on('conversationUpdate', function (message) {
    if (message.membersAdded) {
         message.membersAdded.forEach(function (identity) {
            if (identity.id == message.address.bot.id) {                
                var reply = new builder.Message()
                        .address(message.address)
                        .text("Welcome to my page");
                bot.send(reply);
            } else {
                var address = Object.create(message.address);
                address.user = identity;
                var reply = new builder.Message()
                        .address(address)
                        .text("Hello %s I\'m botty McBotface", identity.name);
                bot.send(reply);
                bot.loadSession(address)
                session.send(
                   "test" 
                )
            }
        });
    }
});  

      



Also unrelated, you have to update your luis endpoint to v2 endpoint like this:

westus.api.cognitive.microsoft.com/luis/v2.0/apps/ 

      

+3


source







All Articles