Skip to content

Instantly share code, notes, and snippets.



Last active Jun 19, 2018
What would you like to do?
LUIS Wiki Sample
var restify = require('restify');
var builder = require('botbuilder');
var request = require('request');
var querystring = require('querystring');
// Setup restify
var server = restify.createServer();
server.listen(3990, function () {
console.log('%s listening at %s',, server.url);
var connector = new builder.ChatConnector();
// Define REST endpoint for Bot Framework'/api/messages', connector.listen());
// Creates our bot.
var bot = new builder.UniversalBot(connector, (session, args) => {
session.send("I'm sorry, I'm afraid I don't understand %s.", session.message.text);
* LUIS Recogniser Setup
* Sets up a recogniser that uses LUIS to deduce intents.
var luisEndpoint = "LUIS_ENDPOINT"; // Endpoint on the Publish page, without the trailing &q=.
var luisRecogniser = new builder.LuisRecognizer(luisEndpoint);
bot.recognizer(luisRecogniser); // Assigns the LUIS recogniser to the bot
// Dialogs for each intent that our bot responds to
// Describe intent - uses the Wikipedia Summary API to pull information about the search term.
bot.dialog("WikiSearchDialog", (session, args) => {
var intent = args.intent; // Extract predicted intent information
var subject = builder.EntityRecognizer.findAllEntities(intent.entities, "SearchObject"); // Get all entities matching SearchObject
var subjectValue = ( => {return entity.entity}).join(" ")).replace("?", ""); // Join them into one string, ignoring ?
if(subjectValue == "") {
//No entities were found.
session.send("Sorry, I couldn't find a search object in your message :(");
subjectValue = querystring.escape(subjectValue);
// Query the Wikipedia summary API:!/Page_content/get_page_summary_title
var wikiGetEndpoint = "" + subjectValue;
request(wikiGetEndpoint, (err, resp, body) => {
var resultObject = JSON.parse(body);
if(resultObject.title == "Not found.") { // No Wikipedia page or redirect exists.
session.send("Oops, I can't find that.");
} else {
session.send("Here's what I found:");
session.send(resultObject.extract); // Get summary
if(resultObject.thumbnail) {
//If the Wikipedia summary came with a thumbnail, send it.
session.send("I also found this picture:");
contentType: "image/jpg",
contentUrl: resultObject.thumbnail.source
matches: "Describe"
// Default dialog for the None intent - cases when we don't want our bot to do a search.
bot.dialog("DefaultDialog", (session, args) => {
session.send("Hello! I'm WikiBot. Try asking me a question like: \"what is football?\"");
matches: "None"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment