如何解决电报中的错误设置webhook

时间:2020-08-27 09:46:18

标签: c# bots telegram

我在Telegram中有一个机器人,并试图在Plesk Host中运行它(在端口443上具有SSL)

当我在Visual Studio中运行机器人页面时,该机器人运行良好。 将项目发布/上传到plesk主机并打开机器人页面后,该机器人也运行良好

但是在设置了Webhook之后,该机器人无法运行。 在webhookInfo中1.6分钟后,我得到以下信息:

{
   "ok":true,
   "result":{
      "url":"https://MYDOMAIN:443/Robot.aspx",
      "has_custom_certificate":false,
      "pending_update_count":1,
      "last_error_date":1598521211,
      "last_error_message":"Read timeout expired",
      "max_connections":40
   }
}

我的源代码:

public class Robot : Page
{
    private const string Token = "1257942485:AAFMeYMX187lEeN8XHCEtSyCVoXXXX";
    private HttpToSocks5Proxy proxy = new HttpToSocks5Proxy(
        socks5Hostname: "so5tel.XXXX.org",
        socks5Port: 6500,
        username: "XXXX",
        password: "XXXX"
    );
    private static ITelegramBotClient _botClient;
    protected void Page_Load(object sender, EventArgs e)
    {
        proxy.ResolveHostnamesLocally = true;
        RegisterAsyncTask(new PageAsyncTask(RunBot));
        ExecuteRegisteredAsyncTasks();
    }
    private async Task RunBot()
    {
        _botClient = new TelegramBotClient(Token, proxy);
        _botClient.OnMessage += Bot_OnMsgAsync;
        _botClient.OnReceiveError += _botClient_OnReceiveError;
        _botClient.StartReceiving();
    }
    async void Bot_OnMsgAsync(object sender, MessageEventArgs e)
    {
        await _botClient.SendTextMessageAsync(e.Message.Chat.Id, e.Message.Text).ConfigureAwait(false);
    }
    private void _botClient_OnReceiveError(object sender, ReceiveErrorEventArgs e)
    {
        using (StreamWriter we = new StreamWriter(Server.MapPath("file.txt"), true))
        {
            we.WriteLine(e.ApiRequestException.Message + DateTime.Now);
        }
    }
}

在file.txt中,我得到以下信息:

Conflict: can't use getUpdates method while webhook is active; use deleteWebhook to delete the webhook first

我该如何解决?

0 个答案:

没有答案