-2

我用 c# 编写了一个电报机器人并将其放入我的 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
    }
}
}

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

4

1 回答 1

0

您可以使用以下代码来初始化您的 Bot 和 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
于 2018-03-19T09:39:42.540 回答