title: How to get Telegram webhook with ngrok working?
body: <p>I'm developing a Telegram bot and want to use <a href="https://ngrok.com" rel="nofollow noreferrer">ngrok</a> to receive messages from the <a href="https://core.telegram.org/bots/webhooks" rel="nofollow noreferrer">webhook</a>.</p>
  
  <p>Setting a webhook works. When I set my publicly reachable domain as URL, I actually get the expected messages. Now, when I know, that the code is working, I want to tunnel messages from the ngrok server to my local VM.</p>
  
  <pre><code>$ ngrok http telegrambot.sandbox.loc:80
  ngrok by @inconshreveable                                                                                                                    (Ctrl+C to quit)
  
  Session Status                online                                                                                                                         
  Session Expires               7 hours, 59 minutes                                                                                                            
  Version                       2.2.8                                                                                                                          
  Region                        United States (us)                                                                                                             
  Web Interface                 http://127.0.0.1:4040                                                                                                          
  Forwarding                    http://0955b8f3.ngrok.io -&gt; telegrambot.sandbox.loc:80                                                                         
  Forwarding                    https://0955b8f3.ngrok.io -&gt; telegrambot.sandbox.loc:80                                                                        
  
  Connections                   ttl     opn     rt1     rt5     p50     p90                                                                                    
                                0       0       0.00    0.00    0.00    0.00
  </code></pre>
  
  <p>Well. Now I set the webhook and get a response like</p>
  
  <pre><code>{
      "ok":true,
      "result":{
          "url":"https://a200f5f7.ngrok.io",
          "has_custom_certificate":false,
          "pending_update_count":0,
          "max_connections":40
      }
  }
  </code></pre>
  
  <p>ngrok's CLI output:</p>
  
  <pre><code>HTTP Requests                                                                                                                                                
  -------------                                                                                                                                                
  
  POST /                         502 Bad Gateway                                                                                                               
  POST /                         502 Bad Gateway                                                                                                               
  POST /                         502 Bad Gateway                                                                                                               
  POST /                         502 Bad Gateway 
  </code></pre>
  
  <p>I didn't get any messages rewarded. Then I added the host name to the <code>/etc/hosts</code>:</p>
  
  <pre><code>127.0.0.1       telegrambot.sandbox.loc
  </code></pre>
  
  <p>Now I'm getting</p>
  
  <pre><code>HTTP Requests                                                                                                                                                
  -------------                                                                                                                                                
  
  POST /                         405 Not Allowed                                                                                                               
  POST /                         405 Not Allowed                                                                                                               
  POST /                         405 Not Allowed                                                                                                               
  POST /                         405 Not Allowed                                                                                                               
  POST /                         405 Not Allowed                                                                                                               
  POST /                         405 Not Allowed                                                                                                               
  GET  /favicon.ico              404 Not Found                                                                                                                 
  GET  /                         200 OK           
  </code></pre>
  
  <p><strong>How to set up and use ngrok correctly and get messages from a Telegram bot forwarded to a local system?</strong></p>
  
  <hr>
  
  <p>Additional info:</p>
  
  <p>I also tried to get ngrok working on my publicly accessible server. The domain is SSL protected and I don't need this forwarding for the productive system. I just wanted to see, how/whether It would work.</p>
  
  <pre><code>ngrok http mybot.myserver.com:80
  </code></pre>
  
  <p>Output:</p>
  
  <pre><code>ngrok by @inconshreveable                                                                                                                                                                                                    (Ctrl+C to quit)
  
  Session Status                online
  Session Expires               7 hours, 56 minutes
  Version                       2.2.8
  Region                        United States (us)
  Web Interface                 http://127.0.0.1:4040
  Forwarding                    http://22cf6597.ngrok.io -&gt; mybot.myserver.com:80
  Forwarding                    https://22cf6597.ngrok.io -&gt; mybot.myserver.com:80
  
  Connections                   ttl     opn     rt1     rt5     p50     p90
                                0       0       0.00    0.00    0.00    0.00
  </code></pre>
  
  <p>The result (both, with and without the <code>/etc/hosts</code> entry) seems to be OK:</p>
  
  <pre><code>HTTP Requests
  -------------
  
  POST /                         200 OK
  POST /                         200 OK
  POST /                         200 OK
  POST /                         200 OK
  </code></pre>
  
  <p>But the defined URI seems still not to be triggered.</p>