From the course: Microsoft Teams Bot Development

Bot loading the user profile

From the course: Microsoft Teams Bot Development

Bot loading the user profile

- [Instructor] So at this point, I have two dialogues. One that asks the user to search, and another that asks the user to pick a matching profile. The third dialogue that we'll have here is going to ask the user to pick a matching user. Well, let's see how that looks like. It's going to be the same function, session, result, next. It's the same function signature and here, I'm going to start writing the code where we have a matching username. So the user provided me with a username, so he picked, let's say, user number five. So I'll say result.response.entity. And now for the matching username, I will say githubClient.loadProfile, remember this is a function readout, so loadProfile, and I will say it for the username. So for this username we're loading the profile, function(profile) So now it's a matter of showing the user the profile. Now you could just say your session prompt, but that's not going to look very nice. Can we send something a little more compelling? Yeah, you can send something called as a card. So I will say var card, new builder.ThumbnailCard card.title(profile.login) so that's the username, Card.images, so luckily the github API returns me the profile picture for the matching username. So I'll say builder.CardImage.create (session,profile.avatar_url) And if the profile has a name, I can say card.subtitle would be the profile name. And similarly, I can fill in more details for the card, like the text, the company profile. And what happens when the user clicks on that card? Well, then we just load the user's profile, and at the very end, we say var message new builder.Message for the session. And we put an attachment on it. And the attachment is an array, and we will simply send the card as the attachment. And the only thing left to do now is to actually send this message. Session.send(message) And this is how we can write our simple bot that first asks the user for a search string, next it loaded the list of matching users, and then for the matching user, it got the user's profile and is showing the user that profile as a clickable card. Now let's go ahead and run this bot.

Contents