From the course: Microsoft Teams Bot Development

Testing using ngrok

- [Instructor] Now with my bot written up I can simply say npm start just like before And connect to localhost 3978 just like before. And test this bot out. Try that out on your own. However, I will use this opportunity to introduce you to an invaluable tool called ngrok. See, the challenge is, that, when we're working with the Bot Framework, especially when we start working with Teams or integrate it with LEWIS, et cetera, there are services in Azure that need to talk to your bot. Even in dev mode. So you need to expose your bot on an Internet-facing URL. So what I'm going to do is that I'm going to use a tool called ngrok. That's R-O-K, not R-O-C-K. Click on the Download button here and download ngrok for your OS. It'll download a zip file. I've already downloaded it. And I've placed it in my C:\Developer folder. And it's called ngrok.exe. What ngrok dopes is actually quite impressive. So when I run this and issue this command here it will simply expose my port 80. And I can obviously chose a different port. I'm going to choose 3978. So it'll expose my port 80 or 3978, my bot, on an Internet-facing URL. Yes, even https. And it does so by using a lot of tricks, duplex proxies and outbound duplex connections, TCP connections or a bunch of other techniques. We don't need to really worry about all of that. It is possible, for an administrator, to block ngrok. And if they do that, yeah, then you may have to use some other technique like Azure Websites, et cetera. But ngrok is so much easier. And we will make use of ngrok when we start writing bots for Teams. So here's what I'm going to do. I'm going to fire up my bot, npm start. Now my localhost port 3978 is listening. So, I'll start ngrok, http, port 3978. And now this URL, nope. You're watching a recording. But imagine if this was real life and real time. At this point, if you were to open your browser, and you may be sitting in the other corner of the world, and you were to visit this link, you'd be hitting this machine right here. My dev machine. Isn't that impressive? Anyway, let's go ahead and copy/paste this URL. And I'm going to launch the Bot Framework Emulator just like before. And I'm going to connect, not to localhost, but instead to that ngrok URL. Now before I hit CONNECT, let me also place my terminal on the left-hand side here so we can see in parallel what's going on. And the Bot Framework Emulator on the right-hand side. And now I'm going to click on CONNECT. Hey, look. The request went over the Internet and it connected to my bot. You can see that the bot is also answering. So that's great. Now I can say, search. It says, "Who are you looking for?" And you can see that these results are being shown now. Yeah, that's our bot. The one that we just wrote. Now, one other reason I like ngrok is that I can see if any traffic is coming in to me. So sometimes when you register a channel or Teams, especially now that they're going in a transition to Azure, sometimes those requests don't come through. It takes some time for the requests to start coming through. From here, at least I can checkbox that off, that indeed my bot is getting a request from the Internet. So that's great. So it says who am I looking for? I will say sahil malik. It executes a search and says, "Which user do you want to load?" I know I am the first one here, so I'll type 1, and it loads my profile. That's my picture, my site. I can click on this card. And it launches into my github repo. There's some bunch of code that I write for fun. Feel free to check it out. But, yes, our bot is completely functional at this point and we just tested it using ngrok over the Internet.

Contents