vendredi 15 juin 2018

Compare string with user input from skype chat

So I wanted to create a skype bot that replies to certain phrases sent to me. A particular phrase or text will have a different reply. The problem is that I am stuck with comparing the user input with the particular string. For some reason the string parameter that I fetch from the chat input is not a string variable as any form of string operation does not work on it although typeof shows its a string.

I am coding the bot using node.js and using the Bot Framework emulator to test it.

Following is the code sample:

var restify = require('restify');
var builder = require('botbuilder');

// Setup Restify Server
var server = restify.createServer();
server.listen(process.env.port || process.env.PORT || 3978, function () {
   console.log('%s listening to %s', server.name, server.url); 
});

// Create chat connector for communicating with the Bot Framework Service
var connector = new builder.ChatConnector({
    appId: process.env.MicrosoftAppId,
    appPassword: process.env.MicrosoftAppPassword
});

// Listen for messages from users 
server.post('/api/messages', connector.listen());

// Receive messages from the user and respond by echoing each message back (prefixed with 'You said:')
var bot = new builder.UniversalBot(connector, function (session) {
    var comp = "%s"
    var comp1 = "hi"
    //comp1 == comp && msg1 = "Hi, how may I help you."
    var msg1 = ""
    if (comp == "hi") msg1 = "Hi, how may I help you."

    session.send(msg1, session.message.text);
});

If I initialize a new string var inside the program i.e comp1 and use it as below to compare then it works, so this rules out that my if statement is wrong.

if (comp1 == "hi") msg1 = "Hi, how may I help you."

Aucun commentaire:

Enregistrer un commentaire