简体   繁体   中英

Couldn't test locally my Telegram Bot with ngrok

I'm trying to test my Telegram Bot using ngrok and the nuget package Telegram.Bot.Core... These are the steps I'm doing so far:
1) I start a web server with lampp (since I'm using Arch Linux)
2) Then I start ngrok with the following command: ngrok http 8443
3) Last step... I run my code example:

myBot.SetWebhookAsync("https://address.ngrok.io").Wait();

myBot.StartReceiving(Array.Empty<UpdateType>());
Console.WriteLine("Starting Receiving");
Console.ReadLine();
myBot.StopReceiving();

The problem is that localhost:8443 is unreachable and I don't know why.
I tryed adding "debugServer": 8443 in the configuration properties in launch.json but localhost:8443 is still unreachable.. what am I doing wrong?

For sharing your localhost and testing Telegram Bot using ngrok you should do bellow steps:

- Step 1

Edit Visual Studio application config file that is located in ../.vs/config/applicationhost.config (follow it from your project root folder).

Find bindings tag and add second binding tag to it ("localhost" just deleted):

<configuration>
...
    <sites>
    ...
        <site ...>
            <bindings>
                <binding protocol="http" bindingInformation="*:5000:localhost" />
                <binding protocol="http" bindingInformation="*:5000:" />
            </bindings>
        </site>
    ...
    </sites>
...
</configuration>

Note that don't do this step to binding tag that uses 8080 port.

- Step 2

Run Visual Studio as administrator and open your project.

- Step 3

Turn your firewall off.

- Step 4

Run ngrok and type " ngrok http 8443 " command and then enter.

- Step 5

Open one of your prefer browser and go to api.telegram.org/bot<Token>/setwebhook?url=<Domain> address for example.

In this URL is your bot token, and is your ngrok forwarding address that uses https.

(As an example: https://api.telegram.org/bot123456:ABC-DEF1234ghIkl-zyx57W2v1u123ew11/setwebhook?url=https://01e08160.ngrok.io/api/Update )

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM