Search code examples
botframeworkazure-bot-serviceazure-qna-maker

Save question when no answer is available for that question (new question) in QnA Maker Knowledge Base


I am trying to save the new questions asked by the user to my QnA maker bot into an Azure database so that I can add the answers to those questions to my knowledge base.

Currently, I am asking the users to write their question in a feedback form when they don't get a response from my bot. This is taking make time also the user is annoyed by writing. I want my bot to collect these questions and store it a database.

So, please guide how to achieve this, any links or suggestions appreciated.


Solution

  • I was able to achieve something similar using a SharePoint list.

    https://stackoverflow.com/a/56612401/9611859

    If you want to add a no answer to a SharePoint List, I managed to get it working using the csom-node package and Bot Framework v4 / NodeJS. Granted, it's not the most elegant solution, but it works.

    Bot.JS

    const csomapi = require('../node_modules/csom-node');
    settings = require('../settings').settings;
    
    // Set CSOM settings
    csomapi.setLoaderOptions({url: settings.siteurl});
    

    Bit further down the page...

    // If no answers were returned from QnA Maker, reply with help.
                } else {
                    await context.sendActivity("Er sorry, I don't seem to have an answer.");
                    console.log(context.activity.text);
                    var response = context.activity.text;
                    var authCtx = new AuthenticationContext(settings.siteurl);
                    authCtx.acquireTokenForApp(settings.clientId, settings.clientSecret, function (err, data) {
    
                        var ctx = new SP.ClientContext("/sites/yoursite");  //set root web
                        authCtx.setAuthenticationCookie(ctx);  //authenticate
                            var web = ctx.get_web();
                            var list = web.get_lists().getByTitle('YourList');
                            var creationInfo = new SP.ListItemCreationInformation();
                            var listItem = list.addItem(creationInfo);
                            listItem.set_item('Title', response);
                            listItem.update();
                            ctx.load(listItem);
                            ctx.executeQueryAsync();
                    });
                }