【问题标题】:Telegram bot in asp.net Application_Startasp.net Application_Start 中的 Telegram 机器人
【发布时间】:2018-03-18 12:44:13
【问题描述】:

我用 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
    }
}
}

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

【问题讨论】:

  • 你为什么不使用webHooks
  • به زبون مادری بهتره یه بازنگری بکنی
  • @PurTahan 因为我没有 SSL
  • @PurTahan بیشتر برای تمرین و آشنایی باپیام رسان ها دارم انجام میدم . حالا میزنیم اگه فیلتر نشد چه بهتر :-)
  • 可以使用自签名ssl证书

标签: c# asp.net bots telegram application-start


【解决方案1】:

您可以使用以下代码来初始化您的 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

【讨论】:

  • 如果对您有帮助,请将其标记为解决方案
  • 非常感谢。我应该在我的 Global.asax 中使用它吗?
  • 是的,你知道的每一件事
  • 更新你的技能,如果你想继续用 asp.net 编程,使用更新的方法,比如 Asp.Net WebPages Razor。
猜你喜欢
  • 2016-01-20
  • 2022-11-01
  • 2018-08-11
  • 2021-11-07
  • 1970-01-01
  • 2018-09-17
  • 1970-01-01
  • 1970-01-01
  • 2016-03-09
相关资源
最近更新 更多