From the course: Microsoft Teams Bot Development

Get channels Bot

- [Instructor] Now, so far the examples I've shown you are all working in a one-to-one chat basis and they are really easy to test, even in dev mode. When working with Microsoft Teams Bots, there are a lot of things you can do. You can, for instance, mention the user, like notify them, send an Office 365 card, or text their team info, start a new reply chain, mention a channel, talk to a notification feed. I won't be able to show you every single one of those code examples, but I will leave you with enough information so you'll be able to dig through that yourself. One thing I would like to show you next is being able to write some functionality that not just works in a one-on-one chat like this Teams Bot is talking to me right now, but also inside a team, in a group chat. So let's see that next. So just like before, let's go ahead and start my Node project. And what I'm going to do is that I'm going to come back to my code here and I'm going to continue making changes right inside there. So what I want to do is that I want to add another function or another listening thing that the bot can react to. Let's do that next. Now the code example I'd like to use next is something that requires me to test this bot in a channel, in a multi-user chat. So we're going to be talking inside of a team, and one team can have multiple channels. So one of the things that the bot framework allows me to do is get a list of channels. So just like I have this dialog match for aboutme, this time around, I will look for a string called getchannels. And just like before, let's go ahead and create our function and now here, I need to use a method called connector.fetchChannelList. How easy is that? That's asking me for some information, so lets go ahead and provide it that information. So fetchChannelList, and here the service URL, just like before will be session.message.address.serviceUrl. Now the team ID, how do I get this? Well that session.message.sourceEvent.team.id. Now you notice that it didn't show up in IntelliSense? That's okay. That's why I have this console.log because what you do is that you run it in console.log, and depending upon where you're coming from, whether you're in a team or in a one-on-one chat, the structure of the session object will change a little bit. So IntelliSense may not show you all the details because the underlying JavaScript objects can't tell VS Code what's in there, but it's there. If you're coming from a teams chat, then yes, the team.id will be present. If you're coming on a one-on-one chat, then it will be missing of course. Okay, and then I should have my results. I'll say err, result, and here, again, just like before, if there is an error, so let me just copy paste the code from the other bot. So if there is an error, go ahead and end the dialogue, but let's go ahead and put another message on top, send ('Here are the matching channels'). Great. Now let's go ahead and test it. Well, the challenge with testing this is that so far, I have been testing all of my bots in a one-on-one chat. Something like GetChannels doesn't make sense in a one-on-one chat. You're getting channels for the current team you're in because that is where we're picking the team.id from, this right here. So this team.id will be null in a one-on-one chat. So this code simply bomb. So I need to test inside of a team right here. So you go to Team, and I've got two channels here, and I want to be able to mention the bot from here, and be able to say, "Dear Bot, get channels." I can't do that directly. I have to deploy this bot. Now if this bot was in the Office app store and available for my tenant, then yeah, I could just simply add it and use it. But let's say it's not in the Office tenant. Then we're still developing it. So how do I go about testing this bot in dev mode in our team? The answer is you have to package it and sideload the bot. Let's see that next.

Contents