Join Sahil Malik for an in-depth discussion in this video Bot prompting the user to make a choice, part of Microsoft Teams Bot Development.
- [Instructor] At this point, you have asked the user what we want to search for. We have found a way to get their query string, pass it to our githubClient and now hopefully if the rest call github succeeds, we should have profiles for the matching users populated in the profiles variable. The question is how do we show these to the user? Well, let's find out. So first let's see how many results did we get. Var totalCount equals profiles dot total count, right? I don't get in tally sense here.
But you can just do a simple get request and look at the json structure. So I'll be making the json structure here. So there is a property there called total count, great. So if total count is zero, then session.... Now we just want to end the dialog here, saying hey, sorry no results founds. But if in case there are some results, then what do we do? Now remember this is like a chart based framework.
So imagine for a second that you were blind and reading this through a screen reader. Would you like to really listen to a hundred profiles? No. So what you want to do is you want to put some check here. You want to say, if total count is greater than let's say ten, then I'm going to say session dot endDialog. We basically want to say there are too many results. I'm going to say more than ten results were found, please provide a more restrictive query.
Great, well now that we have say less than ten results, so we really don't have any excuses here. We have to show them to the user. So here is what I want to do. I want to show the user the list of the profiles that matched as user names. But I want to give the user yet another possibility at this point. Remember I had a second method in my github client. Let's go back there for a second. There is a method that I wrote called load profile.
So I want to give the user the option of loading the profile of a particular user. So the user can now say load user number two or three, whatever right? So I can say session dot dialogData dot property is null. I'm going to say var usernames is profiles are items are map. So let's just quickly run through this function. Let's run through the items over there.
And I will simply return item dot login ID. So the result of this will be that usernames will be an array with all the matching usernames. Okay, then I say builder dot prompts dot choice. So they've given us methods for most of these common scenarios. So I will say session, what user do you want to load? And I simply give the array of users that was passed in.
So the result of this will be that the user at this point, if they have matching results, they will see results like one, two, three, four, five and say what user do you want to load. So the next question will be obviously that we need to introduce another dialog here. Let me collapse this. Let me collapse that. So here we need to add another dialog, which will deal with the user saying that I want to load user number five, or whatever.
Let's see that next.
- What are bots?
- Creating bots
- Testing using ngrok
- Deploying bots to Microsoft Teams
- Testing bots
- Bots as Azure AD applications
- Updating bot registration in Azure
- Building the bot package