Debugging your Teams Bot using Ngrok

   Words by Paul McQuillan

   on 15/02/2021 08:00:00

When we are developing a Bot for Teams using .Net Core, we can publish the code for our Bot into Azure to see our work in action.

But its difficult to attach a debugger when our process is running in Azure.

So if we want to debug our Bot whilst developing to trace its execution or monitor unit tests – what do we do?

Well, we can use a utility titled Ngrok to temporarily give the Bot running on our Local Machine a public facing WAN Address that Azure can communicate with – but as the code is still running on our Local Machine, we can trace its execution in our Visual Studio Debugger even as different public processes in Teams and Azure communicate (and so wait for) our Bot running locally.

The following will get this up and going for us:

Get Ngrok

Download Ngrok from


This downloads an EXE file which is our command line way of running Ngrok.

Start our Ngrok Forwarding URL

Run Ngrok as Admin and enter the following command to open localhost port 3978 publicly:

Ngrok http -host-header=rewrite 3978

NOTE: The Port here for 3978 should match the output that Visual Studio is running – which may vary from machine to machine.

This will start the mirroring of localhost to a public address – the console output showing the detail of this in action:


Point our Web App Bot to our Ngrok Forwarding URL

Our next step is to point our Azure Bot Channel to the newly created public facing address.

NOTE: This will break our Bot whilst it is pointing to our local address and not the real bot address!  So this should only be done in a Dev Instance of the Bot, or by creating a 2nd Messaging Endpoint to work with.

We can do this by opening our Web App Bot definition in Azure.

Within here, we then navigate into Configuration and look at the Messaging Endpoint setting.

This will typically be an Azure URL based on our Bot App’s Name – such as:


We can swap out this URL and replace it with our Ngrok URL. (making sure to use the https address)

Once applied – now any call to the Bot will be ramped through Ngrok to our locally running of the code, and so captured by the debugger in Visual Studio:


This allows us to trace the execution and compare our workings to the eventual outcome of our code in Teams.


So we can see the same outcome here, but having traced the working through the debugger.

Is this the best way?

This gives us a great way of debugging our Bot and has some advantages when it comes to debugging messages from other sources – say if we are posting to our Bot from Power Automate or Dynamics.

But it comes with some disadvantages.

If we turn off Ngrok then our Bot ceases to function, as it will be looking for a Endpoint Messaging URL that no longer exists.

Similarly it can only really work for one developer at a time – as the entire instance of the Bot is rerouted to a single workstation. (so again, never use it for a Bot that's running for anything other than Development!)

We can work around some of these disadvantages by creating a new Bot Channel Registration and then connecting this Registration to our Local Messaging Endpoint rather than affecting the Bot in Azure.

Share this Article

Search Articles

Filter Articles

CRM Tech DocMan

Recent Articles

HOW TO: Integrate SQL Users into Dataverse Teams HOW TO: Prepare to go LIVE on Linked-In! Creating a Homepage Canvas App HOW TO: Virtual Entities in Dynamics 365 Release Wave 2 New Feature: The Columns Button HOW TO: Search a date field in Microsoft Dynamics The Relevance Search COMING SOON to Power Apps Portals HOW TO: Manage Your Dynamics 365 Database Size (Video Included) Dynamics 365 Marketing vs ClickDimensions It’s time to pause, reflect and acknowledge a new era of inclusivity and collaboration. Part 2 - How to get the most from a Technology Expert – Asset Management Hub Property & Asset Management Hub Part 1 – Balancing CRM and Asset Management Scopes - Asset Management Hub Creating a Multi-Lingual PowerApps Portal How to Set Up a Microsoft Teams Site Using DocDrive365 Microsoft Teams - Adding a Microsoft Teams URL to a Dynamics Appointment Dynamics 365 Marketing – Customer Voice Survey Not Appearing In Emails? Using SQL Management Studio to connect to the Dynamics DB Calling a Power Platform AI Builder Model via oData How to use DocDrive365 to integrate permissions between Business Units in Dynamics with Sites in SharePoint Getting started with the Power Platform AI Builder. Power Apps Portal Information Hub DocDrive365 Security: Day One - Getting Started with Dynamics to SharePoint Permissions Part 5 - Power Apps Portals: How To Connect Azure B2C With Linked-In Part 4 – Power Apps Portals: Styling Azure B2C for Power Apps Portals
Contact Us

Want expert advice or a demo?

Get in touch now and see how we can help your business grow.

  • Name
  • Email Address
  • Phone Number

Understanding Your Challenges

Our strong understanding of CRM and emerging technologies within the Microsoft environment means we deliver the right solutions for you.

Proven Real-World Solutions

As a leader in the field of Dynamics solutions, our pedigree developing and delivering real-world solutions is unsurpassed.

Long Term Support

We provide support beyond our design, implementation and 'go-live' delivery using Sprints and continual updates to our AppSource apps.

CRMCS | Design by Thinktank Marketing | Citrus-Lime Limited

To improve your experience today and in the future, this site uses cookies. Read our full Privacy Policy & Cookie information here I Understand