Git Product home page Git Product logo

v3nodebingsearchsdk-bot's Introduction

v3NodeBingSearchSDK-bot

This is v3 Node.js bot app that invokes Bing Search service via azure-cognitiveservices-websearch SDK.

Packages to install

The following are the npm packages that are installed.

    "azure-cognitiveservices-websearch": "^2.0.0",
    "botbuilder": "^3.15.0",
    "dotenv": "^6.2.0",
    "ms-rest-azure": "^2.6.0",
    "restify": "^7.6.0"

Code changes discussion

In order to invoke the Bing Search API, utilized the azure-cognitiveservices-websearch npm package. The request/ response management is more streamlined by this. The source code can be found here, and the repo here.

var websearchAPIClient = require('azure-cognitiveservices-websearch');
var msrestazure = require('ms-rest-azure');
..
..
        // pass Bing Search API key, and get a new object for type CognitiveServicesCredentials
        var credentials = new msrestazure.CognitiveServicesCredentials(process.env.BingSeachApiKey);

        // pass CognitiveServicesCredentials, get a new search client object
        var searchAPIClient = new websearchAPIClient(credentials);

        searchAPIClient.web.search(session.message.text)
            .then((result) => {
                var properties = ["news"]; //["images", "webPages", "news"];
                for (let index = 0; index < properties.length; index++) {
                    if (result[properties[index]]){
                        //console.log(result[properties[index]].value);
                        var botResults = result[properties[index]].value
                                                .map(item => item.name + ' :: ' + item.url);
                        session.endDialog(JSON.stringify(botResults));
                    } else {
                        console.log(`No ${properties[index]} data`);
                    }               
                }
            }).catch((err) => {
            console.log(err);
        }); 

How to run?

You can clone the repo. And, run command npm install in order to install the dependency packages. Then, in order to run the app, just say node app.js.

v3nodebingsearchsdk-bot's People

Contributors

purnachandrapanda avatar

Stargazers

 avatar

Watchers

James Cloos avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.