电报机器人在 asp.net Application_Start



我用 c# 编写了一个 telegrom 机器人,并将其放入我的 asp.net Web 应用程序中。 但不起作用

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.SessionState;
using Telegram.Bot;
namespace MyFirstBot
{
public class Global : System.Web.HttpApplication
{
    TelegramBotClient bot = new TelegramBotClient("My Token");
    TweetTestEntities context = new TweetTestEntities();
    protected void Application_Start(object sender, EventArgs e)
    {
        bot.OnMessage += Bot_OnMessage;
        bot.StartReceiving();
    }
    private void Bot_OnMessage(object sender, Telegram.Bot.Args.MessageEventArgs e)
    {
        //Some Code
    }
}
}

我的应用程序在主机上没有问题

您可以使用以下代码来初始化机器人和 WebHook

Public Shared Sub init()
    Client = New TelegramBotClient(tocken)
    Dim ms As New MemoryStream(Encoding.ASCII.GetBytes(<Your Self-Signed SSL Key>))
    Dim cert As New FileToSend("SSL.pem", ms)
    Client.SetWebhookAsync("https://Your/WebHook", cert)
    With Client.GetMeAsync.Result
        BotID = .Id
        BotUserName = .Username
        Try
            BotPhotoID = Client.GetUserProfilePhotosAsync(.Id).Result.Photos.First.First.FileId
        Catch ex As Exception
        End Try
    End With
End Sub

相关内容

  • 没有找到相关文章

最新更新