简体   繁体   English

无法使用ngrok在本地测试我的Telegram Bot

[英]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: 我正在尝试使用ngrok和nuget包Telegram.Bot.Core来测试我的Telegram Bot。这些是我目前正在执行的步骤:
1) I start a web server with lampp (since I'm using Arch Linux) 1)我使用lampp启动Web服务器(因为我使用的是Arch Linux)
2) Then I start ngrok with the following command: ngrok http 8443 2)然后,我使用以下命令启动ngrok:ngrok http 8443
3) Last step... I run my code example: 3)最后一步...我运行我的代码示例:

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. 问题是localhost:8443无法访问,我不知道为什么。
I tryed adding "debugServer": 8443 in the configuration properties in launch.json but localhost:8443 is still unreachable.. what am I doing wrong? 我尝试在launch.json的配置属性中添加“ debugServer”:8443,但是localhost:8443仍然无法访问..我在做什么错?

For sharing your localhost and testing Telegram Bot using ngrok you should do bellow steps: 为了共享本地主机并使用ngrok测试Telegram Bot,您应该执行以下步骤:

- Step 1 - 第1步

Edit Visual Studio application config file that is located in ../.vs/config/applicationhost.config (follow it from your project root folder). 编辑位于../.vs/config/applicationhost.config Visual Studio应用程序配置文件(从项目根文件夹开始)。

Find bindings tag and add second binding tag to it ("localhost" just deleted): 查找绑定标记并向其添加第二个绑定标记(“刚删除的“ localhost”):

<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. 请注意,不要将此步骤绑定到使用8080端口的标签。

- Step 2 - 第2步

Run Visual Studio as administrator and open your project. 以管理员身份运行Visual Studio并打开您的项目。

- Step 3 -步骤3

Turn your firewall off. 关闭防火墙。

- Step 4 - 第四步

Run ngrok and type " ngrok http 8443 " command and then enter. 运行ngrok并键入“ ngrok http 8443 ”命令,然后输入。

- Step 5 -步骤5

Open one of your prefer browser and go to api.telegram.org/bot<Token>/setwebhook?url=<Domain> address for example. 例如,打开您喜欢的浏览器之一,然后转到api.telegram.org/bot<Token>/setwebhook?url=<Domain>地址。

In this URL is your bot token, and is your ngrok forwarding address that uses https. 该URL中是您的机器人令牌,也是您使用https的ngrok转发地址。

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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