Join Sahil Malik for an in-depth discussion in this video Make code changes for Teams, part of Microsoft Teams Bot Development.
- [Instructor] At this point, you should have a general familiarity with what it means to write a bot and generally speaking, the Microsoft Bot Framework. At this point, we need to take our bot and deploy it to Microsoft Teams. What I'd like you to do is go into exercise files and grab the ending code of the last chapter, and go ahead and set this code up on your machine. I have already done that. Setting this code up means unzipping it and running an NPM install.
You should have a folder called node modules at the end. Also note that I have ngrok downloaded and set up. This is a tool that we had used in the previous module and will continue to use that during this module. So before we continue, please make sure that you have this much set up on your machine. Let's go ahead and open this project in VS Code. So go ahead and open GitBot and VS Code. And the first code change I will make here is that instead of using botbuilder, I will instead use botbuilder-teams.
And ensure that you use the right version for it, also. So, I'll just take on the latest version available. And if you already have done NPM install, go ahead and RM RF delete the node modules folder. I don't have a node modules folder currently, so I'll just say NPM install. Now, after you delete the node modules folder, go ahead and do an NPM install anyway. Okay, now let's come back to my project, and let's start making some code changes.
Behind the scenes, NPM install will finish, so we'll ignore that for now. And as I mentioned that the Bot Framework basically allows you to connect to multiple channels, and Teams is just another channel. So all this code that allowed me to search for a user in Git and then search for that user and load their profile, I don't need to modify any of that code. But the change that I will make here, now, is that I will introduce a new variable here called const bot builderTeams and we're going to say require and this time I'm going to load botbuilder-teams.
Now whenever you load a node module specific to a channel, it includes the underlying, let's call it base class, but it's node module. So I don't need to reference botbuilder explicitly in here because botbuilder-teams will make sure that that is included. In fact you should not reference it because it might get out of sync and so on so forth. The next thing I need to do is that instead of using ChatConnector, I will instead use TeamsChatConnector.
Okay, so let's make a minor code change here. So I'm going to say builderTeams.TeamsChatConnector. And here I need to specify some settings to this. So the previous connector, there really wasn't any authentication accepted but the teams connector does require some authentication. The reason for that is, the teams connector is registered in Azure AD as just an app and we need to get those settings.
So obviously I'll go through the registration first, and we need to put those settings here. So right now I'll just create placeholders, and then I'll come back here and I will add those settings here in a moment. So the first setting I need to provide is appId, this will be a GUID, we'll get this in a moment. And the second setting that I will provide is the password which will be a long weird string that you'll see in a moment but Azure AD, or the bot registration process will provide that for us. That's it, I don't need to make any other code changes in my project and this is really the beauty of the bot framework, is that once you have written the bot, I can expose it with multiple channels very very easily.
So next I'm going to try and get these values using my Azure AD, or otherwise, bot registration. Why did I say otherwise? Let's watch how.
- 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