{"id":19003061,"url":"https://github.com/shah0150/ai_bot","last_synced_at":"2026-03-12T21:02:27.043Z","repository":{"id":124232081,"uuid":"93203525","full_name":"shah0150/ai_bot","owner":"shah0150","description":null,"archived":false,"fork":false,"pushed_at":"2017-06-02T21:07:21.000Z","size":11,"stargazers_count":3,"open_issues_count":0,"forks_count":2,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-07-08T10:50:51.874Z","etag":null,"topics":["artificial-intelligence","google-api","google-cloud","machine-learning","microsoft-bot-framework","microsoft-cognitive-services"],"latest_commit_sha":null,"homepage":null,"language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/shah0150.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null}},"created_at":"2017-06-02T21:00:11.000Z","updated_at":"2018-12-17T16:01:06.000Z","dependencies_parsed_at":null,"dependency_job_id":"b03e25eb-2680-449f-94a5-f2f19130e8fb","html_url":"https://github.com/shah0150/ai_bot","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/shah0150/ai_bot","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/shah0150%2Fai_bot","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/shah0150%2Fai_bot/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/shah0150%2Fai_bot/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/shah0150%2Fai_bot/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/shah0150","download_url":"https://codeload.github.com/shah0150/ai_bot/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/shah0150%2Fai_bot/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":30444290,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-03-12T20:23:30.529Z","status":"ssl_error","status_checked_at":"2026-03-12T20:23:14.027Z","response_time":114,"last_error":"SSL_read: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["artificial-intelligence","google-api","google-cloud","machine-learning","microsoft-bot-framework","microsoft-cognitive-services"],"created_at":"2024-11-08T18:17:51.516Z","updated_at":"2026-03-12T21:02:22.035Z","avatar_url":"https://github.com/shah0150.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# API AI Bot using Microsoft Bot Framework\n\nUnless you have been living in a cave with no internet access, you must have heard about how chatbots are the next biggest thing and how they will completely replace apps. The jury is still out on whether that’s true.\n\nBut we can’t ignore the fact that all major companies have been betting on this new field. Facebook, Microsoft, Google, Amazon are all in on the craze.\n\nMicrosoft’s offering ‘Microsoft Bot Framework’ is the most interesting offering according to me. It lets you easily build bots for multiple platforms like\n\n* Facebook Messenger\n* Slack\n* Telegram\n* WeChat\n* Kik\n* SMS (twilio)\n* Email\n* Skype\n* Skype Teams\n\nYou can write code either in node.js or C#. The best thing however about the framework is how easy it makes to maintain and store data through multiple databags like SessionData, UserData and ConversationData.\n\nNatural Language Processing is a very critical piece for building amazing chatbots. Microsoft Bot Framework lets you easily do this by providing built-in support for luis.ai (part of microsoft cognitive services offering for language processing). However not everyone might want to use LUIS as it requires you to have an azure subscription (starting dec 31).\n\nSo I used a small npm module api-ai-recognizer to use api.ai instead of LUIS with microsoft bot framework. In this tutorial we will see how you can build a simple weather bot using api.ai and Microsoft Bot Framework.\n\n\n## Tutorial \n\nWe will be using node.js for building the bot and then deploy it to Microsoft Bot Framework Service. You can then deploy it to a channel of your choice.\n\n## Set up Environment\n\nMake sure you have node.js and npm installed.\n\nThe first thing we have to do is create a directory so lets go ahead and create a directory in Desktop called weather-bot. Now cd into the directory.\n\n```\nmkdrir weather-bot\n```\n```\ncd weather-bot\n```\nInitialize npm so we can download the required packages. Run the following command and accept all the defualt options.\n\n```\nnpm init\n```\n\nVerify that npm has been initialized by checking if a file called package.json has been created. Once you have verified that lets install the required packages.\n\nTo start off we only need two packages\n\n* botbuilder — For using microsoft bot builder \n* api-ai-recognizer — For using api.ai for NLP\n\nLet’s go ahead and install both packages by running the following command\n\n```\nnpm install --save botbuilder api-ai-recognizer\n```\n# Create a basic echo bot\n\nSo in this step we will create a very basic bot that will just echo what we say. It’s pretty dumb but it’s a start and in the next steps we will build on top of it.\n\nOnce the npm packages have installed, create a file called index.js in the root directory and paste in the following code\n\n```JavaScript\nvar builder = require('botbuilder');\nvar connector = new builder.ConsoleConnector().listen();\nvar bot = new builder.UniversalBot(connector);\nbot.dialog('/', function (session) {\n    session.send(\"You said %s\", session.message.text);\n});\n```\nYou can test the bot by starting the node server and directly chatting on the console.\n\n```\nnode index.js\n```\nType in Hi and you shall get the response of You said Hi\n\n# Create natural understanding model\n\nIn this step we will be building a natural language processing model on api.ai so that our bot will be able to understand human language queries like\n\nWhat’s the weather in Ottawa tomorrow?\n\nThe first thing is to head to api.ai and create an account.\n\nNext create an agent called weather-bot by filling in the required details\n\n[[image]]\n\nThe next step is to create an intent. An intent is basically a way to figure out what the intended action is for a given natural language text.\n\nSo let’s create a intent called whatIsWeather to classify all queries where a user wants to find out the weather. (It’s not neccessary to name your intents without spaces. It’s just a convention I like to follow.)\n\nGive the following example: \n\n* What is the weather?\n* What’s weather like now?\n* How is the climate?\n* How’s the weather?\n\nIn a real application you would provide more examples but for the purposes of this demo these should do good.\n\nYou can give it a response if you want but we won’t really be using it in this demo.\n\nOnce you have created the intent you can save it and check if it’s working by using the try it now chat section on the right side of the website. You should be able to see that the intent gets recognized.\n\n# Connect api.ai with Microsoft Bot Framework \n\nThis is the step where the magic happens. But before we connect api.ai to our code we need to grab the client token. To do this just click on the agent dropdown and select view all agents.\n\nSelect the weather-bot agent from the list of agents and you should be able to find your client access token there\n\n![Token API.AI](http://shah0150.edumedia.ca/Azure/token.png )\n\nNow change index.js as the following code to make the connection\n\n```JavaScript\nvar builder = require('botbuilder');\nvar apiairecognizer = require('api-ai-recognizer');\nvar connector = new builder.ConsoleConnector().listen();\nvar bot = new builder.UniversalBot(connector);\nvar recognizer = new apiairecognizer( \u003c api.ai token \u003e );\nvar intents = new builder.IntentDialog({\n    recognizers: [recognizer]\n});\nbot.dialog('/', function (session) {\n    session.send(\"You said %s\", session.message.text);\n});\n```\nNote: Don’t forget to put in your client token\n\nThis code basically creates an intent recognizer which will try to recognize any incoming text based on our api.ai model.\n\nNow lets use it. Replace your previous bot.dialog code with the one below\n\n```JavaScript\nbot.dialog('/', intents);\nintents.onDefault(function (session) {\n    session.send(\"Sorry...can you please rephrase?\");\n});\n```\nBasically what we are doing above is pass all the messages to the api.ai intent recognizer and then setting up a default handler. This is where you put your infamous “Sorry..I couldn’t understand” type of messages.\n\nOnce having added this code, try to run it. It should give the default response to anything you say, because we only specified the default case.\n\nLet’s add the handler to recognize the whatIsWeather intent we created earlier.\n\n```JavaScript\nbot.dialog('/', intents);\nintents.matches('whatIsWeather', function (session) {\n    session.send(\"It's 27 degrees celsius\");\n});\nintents.onDefault(function (session) {\n    session.send(\"Sorry...can you please rephrase?\");\n});\n\n```\n\nWe have hardcoded the response right now but we will hook it up to an API later.\n\nIf we run the app now, it should be able to recognize the statements which are similar to the ones we trained the intent with before.\n\n```\nnode index.js\n```\n```\nwhats the weather \nIt's 27 degrees celsius \n```\n```\nHi \nSorry...can you please rephrase?\n```\nEven though the bot just says 27 degrees all the time we have made some progress. We have a functional bot.\n\n# Get Weather Data from API\n\nIn this step we will be getting the real weather data from the APIXU current weather api.\n\nThe API will require one parameter, the city name whose current weather data we will need.\n\nWe will get these parameter out of the user’s query and if he doesn’t provide it, we will explicitly ask the user to provide a city name.\n\nThese parameters in NLP terms are called entities and we will have to train our api.ai models to understand and extract these entities. So lets do that.\n\nClick on entities in the left menu and select create new entity and create a new entity called cities and put in some example city names.\n\nIn a real world scenario you would be using pre-built entities which have already been trained with a lot of examples. But we will make do with this for the purposes of this bot. Don’t forget to click on the save button once you are done adding examples.\n\nNow lets train api.ai to understand the cities entity. Go back to intents and click on whatIsWeather intent. Let’s add a few examples which have city name in the sentence.\n\nSomething like\n\n```\nWhat's the weather in Ottawa?\n\n```\nThe entity should be auto detected. Make sure its your entity and not a prebuilt entities. Prebuilt entity names have the format sys.name. Add a few examples and then save the intent.\n\n![API AI](http://shah0150.edumedia.ca/Azure/API_AI.png)\n\nNow lets add some code to pull out the entity information from the phrase. It will be very similar to the fulfillments code.\n\n```JavaScript\nintents.matches('whatIsWeather', function (session, args) {\n    var city = builder.EntityRecognizer.findEntity(args.entities, 'cities');\n    if (city) {\n        var city_name = city.entity;\n        session.send(\"It's 27 degrees celsius in \" + city_name);\n    } else {\n        session.send(\"It's 27 degrees celsius\");\n    }\n});\n```\nWe however have to still handle the case where city is not given. We can do this by issuing a prompt to user asking him for a city name. Here’s the code to do that\n\n```JavaScript\nintents.matches('whatIsWeather', [function (session, args) {\n    var city = builder.EntityRecognizer.findEntity(args.entities, 'cities');\n    if (city) {\n        var city_name = city.entity;\n        session.send(\"It's 27 degrees celsius in \" + city_name);\n    } else {\n        builder.Prompts.text(session, 'Which city do you want the weather for?');\n    }\n}, function (session, results) {\n    session.send(\"It's 27 degrees celsius in \" + results.response);\n}]);\n\n```\nOkay there is a lot going on in there. So let me break it down. Microsoft bot framework lets you chain functions for handlers by passing in an array of functions. You can use this to run functions one after other collecting data and using it in the next function. You use prompts to ask for data. You can read more about this in the official documentation.\n\nNow you can save the app and restart and it should prompt for city if you don’t provide it.\n\n``` \nnode index.js\n```\n\n```\nwhat is the weather?\n\nWhich city do you want the weather for?\n\nToronto \n\nIt's 27 degrees celsius in Toronto\n\n```\n\nNow that we have this working, lets hook it up to the api and get real weather data.\n\nSo firstly create an account for yourself on [APIXU](https://www.apixu.com/ \"APIXU\"). Once you do that you will get a API Access Key and you can play around the API by clicking on getting started. Put in a few city names and get a feel of how it works.\n\nKeep your api access key handy we will be needing it to make the api calls. We will be using the request module on npm to make the calls, so lets start by installing it.\n\n```\nnpm install --save request\n```\nOnce we have request installed lets require it by adding in the following lines at the top of index.js\n\n```JavaScript\nvar request = require('request');\n```\nNow that we have access to request module lets put in code to get weather data from API\n\n```JavaScript\nintents.matches('whatIsWeather', [function (session, args) {\n    var city = builder.EntityRecognizer.findEntity(args.entities, 'cities');\n    if (city) {\n        var city_name = city.entity;\n        var url = \"http://api.apixu.com/v1/current.json?key=\"\u003cYour API Key\u003e\"\u0026q=\" + city_name;\n        request(url, function (error, response, body) {\n            body = JSON.parse(body);\n            temp = body.current.temp_c;\n            session.send(\"It's \" + temp + \" degrees celsius in \" + city_name);\n        });\n    } else {\n        builder.Prompts.text(session, 'Which city do you want the weather for?');\n    }\n}, function (session, results) {\n    var city_name = results.response;\n    var url = \"http://api.apixu.com/v1/current.json?key=\"\u003cYour API key\u003e\"\u0026q=\" + city_name;\n    request(url, function (error, response, body) {\n        body = JSON.parse(body);\n        temp = body.current.temp_c;\n        session.send(\"It's \" + temp + \" degrees celsius in \" + city_name);\n    });\n}]);\n```\nOnce you save and restart your app, it should be working as expected.\n\n```\nnode index.js\n```\n```\nWhat's the weather in Ottawa?\n\nIt's 12 degrees celsius in Ottawa\n```\n![Bot Output](http://shah0150.edumedia.ca/Azure/bot_output)\n\nYou have your AI Bot ready to get deployed in real world\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fshah0150%2Fai_bot","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fshah0150%2Fai_bot","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fshah0150%2Fai_bot/lists"}