title: Test a bot functionality in Teams using ngrok
body: <p>I'm developing a bot using the Bot Framework and Azure for Microsoft Teams and I'll to develop and test my code directly in MS Teams using ngrok. In the settings of the bot I've set the message endpoint to the URL I get from ngrok and added <code>/api/messages</code>.</p>
  
  <p>But every time I want to send a message from Teams, I get a 401 unauthorized response.</p>
  
  <p><a href="https://i.stack.imgur.com/tXGTX.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/tXGTX.png" alt=""></a></p>
  
  <p>How could I authorize ngrok to send messages?</p>
  
  <p><strong>Update:</strong> Form an answer of @Hilton Giesenow I've checked the <code>appSettings.json</code> file and everything is correct there. He said also that there is a small change that the problem is in the <code>HttpAdapter</code>. So here is my code:</p>
  
  <pre><code>public class AdapterWithErrorHandler : BotFrameworkHttpAdapter
  {
      public AdapterWithErrorHandler(IConfiguration configuration, ILogger&lt;BotFrameworkHttpAdapter&gt; logger) : base(configuration, logger)
      {
          OnTurnError = OnTurnErrorHandler;
      }
  
      private async Task OnTurnErrorHandler(ITurnContext turnContext, Exception exception)
      {
          string replyText = "An error occured while sending a message. If this error stays, please contact the service desk.";
  
          await turnContext.SendActivityAsync(MessageFactory.Text(replyText, replyText));
      }
  }
  </code></pre>
  
  <p>Code in startup file in the <code>ConfigureServices</code> method:</p>
  
  <pre><code>services.AddSingleton&lt;IBotFrameworkHttpAdapter, AdapterWithErrorHandler&gt;();
  services.AddTransient&lt;ILogger&lt;BotFrameworkHttpAdapter&gt;, BotFrameworkHttpAdapterLogger&gt;();
  </code></pre>