From the course: Microsoft Teams Bot Development

Loading profiles

- [Lecturer] Now with my basic bot working and the GitHub client written, let's start using this GitHub client in my index.js file. Here, I'm going to start introducing dialogs. Okay, how do we do that? So, right where I have the connector, below this, I have the bot created, and I'm going to remove this dialog that I had earlier, and instead, I'm going to specify the dialog that I am interested in. So first I need to create that dialog. So here, let's go ahead and say const dialog new builder.IntentDialog, and at the bottom, I'm going to say bot.dialog and the default dialog shall be this dialog. Now, obviously we need to fill in details for what this dialog does. So, let's say that I said dialog.matches, and we're going to use a simple regex expression, so the user says search, then perform the following. As I mentioned that the dialog is just a sequence of these functions, so session args next. That's the parameters for the function, and also if session.message.text.toLowerCase. Now, this is where, you know if you want to make this more compelling, you would introduce things like Louis Et cetera, but I'm just doing simple string matching, and if this is, let's say search, so the user is searching for something, then I'll say builder.Prompts.text session, who are you looking for? And at this point, if the user had said search with a name in front, I could say parse that information automatically and I could say var query is equal to session.message.text.substring, so we are getting the search query from the seventh string, you know search plus space, and then we want to go to the next dialog, so I'll simply call next response query. So let's write the next dialog. The next dialog is going to actually execute the search for me. So I'm going to say function session result next, just like before, and I'm going to say var query is equal to result.response, so that's the query string, and if the user did not specify a query, then we want to simply tell the user that, hey we are ending the dialog, so this clears the dialog data, also, the session.dialog data. So I'm going to say request canceled, but what if the user did specify some search data? And here, I would say, githubClient.executeSearch, now I didn't import GitHub client, let me go ahead and do that. So at the very top, I'm going to say, const GitHub client equals require, and I'll simply import it from the file that I had written earlier, the module. Now, let's get back down here, and now it should start showing me some IntelliSense, so I'm going to say githubClient.executeSearch, whatever query string we passed in, and hopefully, this should return me some profiles, and now it's a matter of showing those profiles to the user. So, the next we'll do is, you know, show the profiles, or maybe there are too many profiles, we want to say, hey, way too many results, and then perhaps, you know, I introduce another dialog after that, so let's see that next.

Contents