├── TelegrammAspMvcDotNetCoreBot ├── Views │ ├── _ViewStart.cshtml │ ├── _ViewImports.cshtml │ ├── Home │ │ └── Index.cshtml │ └── Shared │ │ ├── Error.cshtml │ │ ├── _ValidationScriptsPartial.cshtml │ │ └── _Layout.cshtml ├── appsettings.json ├── appsettings.Development.json ├── Models │ ├── ErrorViewModel.cs │ ├── AppSettings.cs │ ├── Commands │ │ ├── Command.cs │ │ └── StartCommand.cs │ └── Bot.cs ├── TelegrammAspMvcDotNetCoreBot.csproj ├── Controllers │ ├── HomeController.cs │ └── MessageController.cs ├── Properties │ └── launchSettings.json ├── Program.cs └── Startup.cs ├── README.md ├── TelegrammAspMvcDotNetCoreBot.sln ├── .gitattributes └── .gitignore /TelegrammAspMvcDotNetCoreBot/Views/_ViewStart.cshtml: -------------------------------------------------------------------------------- 1 | @{ 2 | Layout = "_Layout"; 3 | } 4 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # TelegramAspMvcDotNetCoreBotExample 2 | A simpe example of telegramm bot on MVC ASP.NET Core 2.1 3 | -------------------------------------------------------------------------------- /TelegrammAspMvcDotNetCoreBot/appsettings.json: -------------------------------------------------------------------------------- 1 | { 2 | "Logging": { 3 | "IncludeScopes": false, 4 | "LogLevel": { 5 | "Default": "Warning" 6 | } 7 | } 8 | } 9 | -------------------------------------------------------------------------------- /TelegrammAspMvcDotNetCoreBot/Views/_ViewImports.cshtml: -------------------------------------------------------------------------------- 1 | @using TelegrammAspMvcDotNetCoreBot 2 | @using TelegrammAspMvcDotNetCoreBot.Models 3 | @addTagHelper *, Microsoft.AspNetCore.Mvc.TagHelpers 4 | -------------------------------------------------------------------------------- /TelegrammAspMvcDotNetCoreBot/appsettings.Development.json: -------------------------------------------------------------------------------- 1 | { 2 | "Logging": { 3 | "IncludeScopes": false, 4 | "LogLevel": { 5 | "Default": "Debug", 6 | "System": "Information", 7 | "Microsoft": "Information" 8 | } 9 | } 10 | } 11 | -------------------------------------------------------------------------------- /TelegrammAspMvcDotNetCoreBot/Models/ErrorViewModel.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | namespace TelegrammAspMvcDotNetCoreBot.Models 4 | { 5 | public class ErrorViewModel 6 | { 7 | public string RequestId { get; set; } 8 | 9 | public bool ShowRequestId => !string.IsNullOrEmpty(RequestId); 10 | } 11 | } -------------------------------------------------------------------------------- /TelegrammAspMvcDotNetCoreBot/Views/Home/Index.cshtml: -------------------------------------------------------------------------------- 1 | @{ 2 | Layout = null; 3 | } 4 | 5 | 6 |
7 |
12 | Request ID: @Model.RequestId
13 |
18 | Swapping to Development environment will display more detailed information about the error that occurred. 19 |
20 |21 | Development environment should not be enabled in deployed applications, as it can result in sensitive information from exceptions being displayed to end users. For local debugging, development environment can be enabled by setting the ASPNETCORE_ENVIRONMENT environment variable to Development, and restarting the application. 22 |
23 | -------------------------------------------------------------------------------- /TelegrammAspMvcDotNetCoreBot/Models/Commands/StartCommand.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Threading.Tasks; 5 | using Telegram.Bot; 6 | using Telegram.Bot.Types; 7 | 8 | namespace TelegrammAspMvcDotNetCoreBot.Models.Commands 9 | { 10 | public class StartCommand : Command 11 | { 12 | public override string Name => @"/start"; 13 | 14 | public override bool Contains(Message message) 15 | { 16 | if (message.Type != Telegram.Bot.Types.Enums.MessageType.TextMessage) 17 | return false; 18 | 19 | return message.Text.Contains(this.Name); 20 | } 21 | 22 | public override async Task Execute(Message message, TelegramBotClient botClient) 23 | { 24 | var chatId = message.Chat.Id; 25 | await botClient.SendTextMessageAsync(chatId, "Hallo I'm ASP.NET Core Bot", parseMode: Telegram.Bot.Types.Enums.ParseMode.Markdown); 26 | } 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /TelegrammAspMvcDotNetCoreBot/Models/Bot.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Threading.Tasks; 5 | using Telegram.Bot; 6 | using TelegrammAspMvcDotNetCoreBot.Models.Commands; 7 | 8 | namespace TelegrammAspMvcDotNetCoreBot.Models 9 | { 10 | public class Bot 11 | { 12 | private static TelegramBotClient botClient; 13 | private static List