如何在IIS上运行电报机器人

时间:2017-10-26 10:04:00

标签: c# iis telegram-bot

您好我使用此FrameworkProject创建我的电报机器人

但是这个例子是控制台应用程序,我需要在IIS上使用Lanch我的项目

如何在IIS上传我的项目?

1 个答案:

答案 0 :(得分:1)

你应该创建MVC项目 并在Global.asax

中写下您的所有代码

然后在IIS上安装项目

为埃弗尔工作

using Menu;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Threading.Tasks;
using System.Web;
using System.Web.Mvc;
using System.Web.Optimization;
using System.Web.Routing;
using Telegram.Bot;
using Telegram.Bot.Args;
using Telegram.Bot.Types;
using Telegram.Bot.Types.Enums;
using Telegram.Bot.Types.InlineKeyboardButtons;
using Telegram.Bot.Types.ReplyMarkups;


namespace TelegramMVC
{
    public class MvcApplication : System.Web.HttpApplication
    {

        Telegram.Bot.TelegramBotClient Bot = new TelegramBotClient("my_api_key");

        protected void Application_Start()
        {
            AreaRegistration.RegisterAllAreas();
            FilterConfig.RegisterGlobalFilters(GlobalFilters.Filters);
            RouteConfig.RegisterRoutes(RouteTable.Routes);
            BundleConfig.RegisterBundles(BundleTable.Bundles);

            Bot.OnMessage += Bot_OnMessage;
            Bot.StartReceiving();
        }

        private void Bot_OnMessage(object sender, MessageEventArgs messageEventArgs)
        {
            var message = messageEventArgs.Message;

            if (message == null || message.Type != MessageType.TextMessage) return;

            if (message.Text.Contains("/start")) 
            {
                string Str = "Start Recived";
                Bot.SendTextMessageAsync(message.Chat.Id, Str, replyMarkup: MainMenu.ShowMenu(message));

            }
            else if (message.Text.Contains("/Stop"))
            {
                string Str = "Stop Recived";
                Bot.SendTextMessageAsync(message.Chat.Id, Str, replyMarkup: FollowerMenu.ShowFollowerMenu(message));
            }

        }

    }
}