Using API Search Queries with Bot Framework (Node.js)
This is built on-top of BotBuilder/Node/Examples/demo-skype-app.js
The bot framework is a really cool sdk. If you’re not using it currently, I strongly suggest you take a look. Even if you’re not a node.js type of person. There’s also the C# sdk, because well of-course it’s Microsoft. However, it’s pretty cool that there exists a node.js version so.. thanks!
So I have an API, and the goal is to tell the bot something my URL can actually hit. I started with request.
var request = require('request'),
This worked well for me, but I had a problem updating SearchDetail for the longest, because of how the framework and node co-operate, in asynchronicity. The IDialog Waterfall, is a very powerful thing that lets you continue your session with the bot, to a results portion of the session. Which looks like:
Well turns out you can chain these together with next() inside one dialog. For, a really long time, it’s pretty crazy.
If you notice, I use
next() which is always third arugment =>
function (session, arg, next) to persist to next session. You don’t always have to do this. When you have a
builder.Prompts.text(session, '') Then you can persist to
function (session,results) and get the
I also use
session.userData._Name [Adding Dialogs and Memory] which works about the same to having a global variable _Name and calling that instead, but I wanted to make sure my search string was fresh :)
The main reason i’m chaining these together in the first place, is to knock out 2 birds with one stone. What I mean is, my
SearchDetail object doesn’t update until
function (session, results) before that, it’s blank. The URL is updated, but I need the data from it. Before I had been using multiple
bot.dialog()‘s that still continued to never update
SearchDetail, until after the bot restarted, this is currently the only way I have found to persist the data from the URL, without worrying about a delay. This also let’s me confirm that this is in fact the correct response, because mistakes will be made I’m sure.