diff --git a/TGBotFramework/BotFramework.Tests/BotFramework.Tests.csproj b/TGBotFramework/BotFramework.Tests/BotFramework.Tests.csproj index 02bd0a3..4d39309 100644 --- a/TGBotFramework/BotFramework.Tests/BotFramework.Tests.csproj +++ b/TGBotFramework/BotFramework.Tests/BotFramework.Tests.csproj @@ -1,4 +1,4 @@ - + net6.0 @@ -7,7 +7,7 @@ - + diff --git a/TGBotFramework/BotFramework.Webhook/BotFramework.Webhook.csproj b/TGBotFramework/BotFramework.Webhook/BotFramework.Webhook.csproj new file mode 100644 index 0000000..661778f --- /dev/null +++ b/TGBotFramework/BotFramework.Webhook/BotFramework.Webhook.csproj @@ -0,0 +1,17 @@ + + + + netstandard2.1 + enable + latestMajor + + + + + + + + + + + diff --git a/TGBotFramework/BotFramework.Webhook/ServiceCollectionExtensions.cs b/TGBotFramework/BotFramework.Webhook/ServiceCollectionExtensions.cs new file mode 100644 index 0000000..3ddfcc9 --- /dev/null +++ b/TGBotFramework/BotFramework.Webhook/ServiceCollectionExtensions.cs @@ -0,0 +1,18 @@ +using BotFramework.Abstractions.UpdateProvider; +using Microsoft.Extensions.DependencyInjection; + +namespace BotFramework.Webhook; + +public static class ServiceCollectionExtensions +{ + public static void AddTelegramBotWebhookUpdateProvider(this IServiceCollection collection) + { + collection.AddSingleton(); + } + + public static void AddTelegramBotWebhook(this IServiceCollection collection) + { + collection.AddTelegramBotWebhookUpdateProvider(); + collection.AddTelegramBot(); + } +} diff --git a/TGBotFramework/BotFramework.Webhook/WebhookUpdateProvider.cs b/TGBotFramework/BotFramework.Webhook/WebhookUpdateProvider.cs new file mode 100644 index 0000000..002a816 --- /dev/null +++ b/TGBotFramework/BotFramework.Webhook/WebhookUpdateProvider.cs @@ -0,0 +1,85 @@ +using System; +using System.Net; +using System.Threading; +using System.Threading.Tasks; +using BotFramework.Abstractions.UpdateProvider; +using BotFramework.Config; +using Microsoft.Extensions.Options; +using Newtonsoft.Json; +using Telegram.Bot; +using Telegram.Bot.Types; +using WatsonWebserver.Core; + +namespace BotFramework.Webhook; + +public class WebhookUpdateProvider : IWebhookProvider +{ + private const string SecretTokenHeader = "X-Telegram-Bot-Api-Secret-Token"; + + private readonly ITelegramBotClient _client; + private readonly IUpdateTarget _updateTarget; + private readonly BotConfig _config; + + private readonly string? _secretToken; + + private readonly CancellationTokenSource _canRunTokenSource = new (); + + public WebhookUpdateProvider(ITelegramBotClient client, IUpdateTarget updateTarget, IOptions config) + { + _client = client; + _updateTarget = updateTarget; + _config = config.Value; + + _secretToken = _config.Webhook.SecretToken; + if (string.IsNullOrWhiteSpace(_secretToken)) + { + _secretToken = null; + } + } + + public async Task StartAsync(CancellationToken token) + { + token.ThrowIfCancellationRequested(); + var server = new WatsonWebserver.Webserver(GetWebserverSettings(), Route); + _ = server.StartAsync(_canRunTokenSource.Token); + + await _client.SetWebhookAsync(_config.Webhook.Url, secretToken: _secretToken, cancellationToken: token); + } + + public async Task StopAsync(CancellationToken token) + { + _canRunTokenSource.Cancel(); + await _client.DeleteWebhookAsync(cancellationToken: token); + } + + private async Task Route(HttpContextBase ctx) + { + var request = ctx.Request; + if (_secretToken != null && request.RetrieveHeaderValue(SecretTokenHeader) != _secretToken) + { + ctx.Response.StatusCode = (int)HttpStatusCode.Forbidden; + + await ctx.Response.Send("Missing or invalid secret_token"); + return; + } + + try + { + var obj = JsonConvert.DeserializeObject(request.DataAsString); + if (obj != null) + { + _updateTarget.Push(obj); + } + } catch(Exception e) + { + Console.WriteLine(e); + } + + await ctx.Response.Send(); + } + + private WebserverSettings GetWebserverSettings() + { + return new WebserverSettings(_config.Webhook.Host, _config.Webhook.Port); + } +} diff --git a/TGBotFramework/BotFramework/Abstractions/UpdateProvider/IUpdateProvider.cs b/TGBotFramework/BotFramework/Abstractions/UpdateProvider/IUpdateProvider.cs new file mode 100644 index 0000000..6a4ed5b --- /dev/null +++ b/TGBotFramework/BotFramework/Abstractions/UpdateProvider/IUpdateProvider.cs @@ -0,0 +1,10 @@ +using System.Threading; +using System.Threading.Tasks; + +namespace BotFramework.Abstractions.UpdateProvider; + +public interface IUpdateProvider +{ + Task StartAsync(CancellationToken token); + Task StopAsync(CancellationToken token); +} diff --git a/TGBotFramework/BotFramework/Abstractions/UpdateProvider/IUpdateTarget.cs b/TGBotFramework/BotFramework/Abstractions/UpdateProvider/IUpdateTarget.cs new file mode 100644 index 0000000..a893369 --- /dev/null +++ b/TGBotFramework/BotFramework/Abstractions/UpdateProvider/IUpdateTarget.cs @@ -0,0 +1,8 @@ +using Telegram.Bot.Types; + +namespace BotFramework.Abstractions.UpdateProvider; + +public interface IUpdateTarget +{ + public void Push(Update update); +} diff --git a/TGBotFramework/BotFramework/Abstractions/UpdateProvider/IWebhookProvider.cs b/TGBotFramework/BotFramework/Abstractions/UpdateProvider/IWebhookProvider.cs new file mode 100644 index 0000000..8d729bb --- /dev/null +++ b/TGBotFramework/BotFramework/Abstractions/UpdateProvider/IWebhookProvider.cs @@ -0,0 +1,6 @@ +namespace BotFramework.Abstractions.UpdateProvider; + +public interface IWebhookProvider: IUpdateProvider +{ + +} diff --git a/TGBotFramework/BotFramework/Bot.cs b/TGBotFramework/BotFramework/Bot.cs index 7ca6b23..bbefa30 100644 --- a/TGBotFramework/BotFramework/Bot.cs +++ b/TGBotFramework/BotFramework/Bot.cs @@ -1,45 +1,54 @@ using System; +using System.Collections.Concurrent; using System.Collections.Generic; using System.Linq; -using System.Net.Http; using System.Threading; using System.Threading.Tasks; using BotFramework.Abstractions; using BotFramework.Abstractions.Storage; +using BotFramework.Abstractions.UpdateProvider; using BotFramework.Config; using BotFramework.Middleware; using BotFramework.Setup; -using Microsoft.Extensions.Configuration; using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.Hosting; -using MihaZupan; +using Microsoft.Extensions.Options; using Telegram.Bot; -using Telegram.Bot.Polling; using Telegram.Bot.Types; namespace BotFramework { - public class Bot: IHostedService, IBotInstance + public class Bot: IHostedService, IBotInstance, IUpdateTarget { - private readonly BotConfig _config = new BotConfig(); - + private readonly BotConfig _botConfig; + private readonly IServiceProvider _serviceProvider; private readonly IServiceScopeFactory _scopeFactory; - + private IUpdateProvider _updateProvider; private readonly LinkedList _wares; + private EventHandlerFactory _factory; + private readonly CancellationTokenSource _receiveToken = new(); - private readonly IServiceProvider services; - - private TelegramBotClient client; - - private EventHandlerFactory factory; + public string UserName { get; private set; } - private CancellationTokenSource _receiveToken = new CancellationTokenSource(); + public ITelegramBotClient BotClient { get; } + private readonly ConcurrentQueue _updateQueue = new(); + private readonly ManualResetEvent _shouldProcess = new(false); + private readonly Thread _updateThread; - public Bot(IServiceProvider services, IServiceScopeFactory scopeFactory, Type startupType = null) + public Bot(IServiceProvider serviceProvider, + IOptions options, + IServiceScopeFactory scopeFactory, + ITelegramBotClient client, + Type startupType = null + ) { - this.services = services; + _serviceProvider = serviceProvider; _scopeFactory = scopeFactory; + BotClient = client; + _botConfig = options.Value; + + _updateThread = new Thread(UpdateThread) { Name = "Update handler thread" }; if(startupType != null) { @@ -47,51 +56,37 @@ public Bot(IServiceProvider services, IServiceScopeFactory scopeFactory, Type st } } - async Task IHostedService.StartAsync(CancellationToken cancellationToken) { await StartListen(cancellationToken); } + async Task IHostedService.StartAsync(CancellationToken cancellationToken) + { + if(_botConfig.Webhook.Enabled) + { + _updateProvider = _serviceProvider.GetService(); + } + + _updateProvider ??= _serviceProvider.GetService(); + // TODO: do smth if there are no registered provider? + + await _updateProvider.StartAsync(cancellationToken); + await StartListen(cancellationToken); + } async Task IHostedService.StopAsync(CancellationToken cancellationToken) { - await client.DeleteWebhookAsync(cancellationToken: cancellationToken); - await client.CloseAsync(cancellationToken); + await _updateProvider.StopAsync(cancellationToken); + _shouldProcess.Set(); _receiveToken.Cancel(); + _shouldProcess.Set(); + + while (_updateThread.IsAlive) { } } - public string UserName { get; private set; } - - public ITelegramBotClient BotClient => client; private async Task StartListen(CancellationToken cancellationToken) { - var configProvider = services.GetService(); - var section = configProvider.GetSection("BotConfig"); - section.Bind(_config); - try { - var apiUrl = _config.BotApiUrl; - if(string.IsNullOrWhiteSpace(apiUrl)) - { - apiUrl = null; - } - - var options = new TelegramBotClientOptions(_config.Token, apiUrl, _config.UseTestEnv); - - if(_config.UseSOCKS5) - { - var proxy = new HttpToSocks5Proxy(_config.SOCKS5Address, _config.SOCKS5Port, _config.SOCKS5User, - _config.SOCKS5Password); - var handler = new HttpClientHandler { Proxy = proxy }; - var httpClient = new HttpClient(handler, true); - - client = new TelegramBotClient(options, httpClient); - } - else - { - client = new TelegramBotClient(options); - } - - factory = new EventHandlerFactory(); - factory.Find(); + _factory = new EventHandlerFactory(); + _factory.Find(); var me = await GetMeSafeAsync(cancellationToken); UserName = me.Username; @@ -110,34 +105,29 @@ private async Task StartListen(CancellationToken cancellationToken) Console.WriteLine(e); } - if(_config.EnableWebHook) - { - if(_config.UseCertificate) - { - //TODO серт - // await client.SetWebhookAsync(_config.WebHookURL, new InputFileStream(new FileStream(_config.WebHookCertPath))) - } - else + _updateThread.Start(_receiveToken.Token); + } + + private void UpdateThread(object token) + { + var cancellationToken = (CancellationToken) token; + while (!cancellationToken.IsCancellationRequested) + { + _shouldProcess.WaitOne(); + + while(!_updateQueue.IsEmpty) { - //TODO подготовить и заспавнить контроллер - await client.SetWebhookAsync(_config.WebHookURL, cancellationToken: cancellationToken); + if(_updateQueue.TryDequeue(out var update)) + { + _ = HandleUpdateAsync(update); + } } - } - else - { - // v16.x - // client.StartReceiving(new DefaultUpdateHandler(HandleUpdateAsync, HandleErrorAsync), cancellationToken); - // v17.x - await client.DeleteWebhookAsync(false, cancellationToken); - - var receiverOptions = new ReceiverOptions { AllowedUpdates = { }, ThrowPendingUpdates = false }; - client.StartReceiving(HandleUpdateAsync, HandleErrorAsync, receiverOptions, _receiveToken.Token); + _shouldProcess.Reset(); } } - private async Task HandleUpdateAsync( - ITelegramBotClient botClient, Update update, CancellationToken cancellationToken) + private async Task HandleUpdateAsync(Update update) { try { @@ -154,7 +144,7 @@ await Task.Run(async () => var param = new HandlerParams(this, update, scope.ServiceProvider, UserName, userProvider); - var router = new Router(factory); + var router = new Router(_factory); router.__Setup(null, param); wares.Push(router); @@ -183,36 +173,33 @@ await Task.Run(async () => var runWare = wares.Pop(); await ((BaseMiddleware)runWare).__ProcessInternal(); - }, cancellationToken); + }); } catch(Exception exception) { Console.WriteLine(exception); // throw; } } - - private async Task HandleErrorAsync(ITelegramBotClient botClient, Exception exception, CancellationToken cancellationToken) - { - Console.WriteLine(exception); - await Task.Delay(5000, cancellationToken); //иначе будет долбиться и грузить проц на 100% - } - + private async Task GetMeSafeAsync(CancellationToken cancellationToken) { try { - var user = await BotClient.GetMeAsync(cancellationToken); - - return user; - } catch(Exception e) + return await BotClient.GetMeAsync(cancellationToken); + } catch (Exception e) { Console.WriteLine(e); - } await Task.Delay(5000, cancellationToken); return await GetMeSafeAsync(cancellationToken); } + + public void Push(Update update) + { + _updateQueue.Enqueue(update); + _shouldProcess.Set(); + } } } diff --git a/TGBotFramework/BotFramework/BotFramework.csproj b/TGBotFramework/BotFramework/BotFramework.csproj index fafed90..018638c 100644 --- a/TGBotFramework/BotFramework/BotFramework.csproj +++ b/TGBotFramework/BotFramework/BotFramework.csproj @@ -33,6 +33,7 @@ + all runtime; build; native; contentfiles; analyzers; buildtransitive diff --git a/TGBotFramework/BotFramework/Config/BotConfig.cs b/TGBotFramework/BotFramework/Config/BotConfig.cs index 5038632..76e2235 100644 --- a/TGBotFramework/BotFramework/Config/BotConfig.cs +++ b/TGBotFramework/BotFramework/Config/BotConfig.cs @@ -3,10 +3,7 @@ public class BotConfig { public string Token { get; set; } - public string WebHookURL { get; set; } - public bool UseCertificate { get; set; } - public string WebHookCertPath { get; set; } - public bool EnableWebHook { get; set; } + public WebhookConfig Webhook { get; set; } public string SOCKS5Address { get; set; } public int SOCKS5Port { get; set; } public string SOCKS5User { get; set; } diff --git a/TGBotFramework/BotFramework/Config/DefaultConfig.json b/TGBotFramework/BotFramework/Config/DefaultConfig.json index d6a3e93..bb73063 100644 --- a/TGBotFramework/BotFramework/Config/DefaultConfig.json +++ b/TGBotFramework/BotFramework/Config/DefaultConfig.json @@ -1,9 +1,8 @@ { "token": null, "webHookURL": null, - "useSertificate": false, - "webHookSertPath": null, - "enableWebHook": false, + "useCertificate": false, + "webHookСertPath": null, "sockS5Address": null, "sockS5Port": null, "sockS5User": null, diff --git a/TGBotFramework/BotFramework/Config/WebhookConfig.cs b/TGBotFramework/BotFramework/Config/WebhookConfig.cs new file mode 100644 index 0000000..29713af --- /dev/null +++ b/TGBotFramework/BotFramework/Config/WebhookConfig.cs @@ -0,0 +1,11 @@ +namespace BotFramework.Config; + +public class WebhookConfig +{ + public bool Enabled { get; set; } + public string Url { get; set; } + public string Certificate { get; set; } + public string SecretToken { get; set; } + public string Host { get; set; } + public int Port { get; set; } +} diff --git a/TGBotFramework/BotFramework/ServiceExtensions.cs b/TGBotFramework/BotFramework/ServiceExtensions.cs index aff3b80..1b14e07 100644 --- a/TGBotFramework/BotFramework/ServiceExtensions.cs +++ b/TGBotFramework/BotFramework/ServiceExtensions.cs @@ -1,12 +1,21 @@ using System; +using System.Linq; +using System.Net.Http; using BotFramework.Abstractions; using BotFramework.Abstractions.Storage; +using BotFramework.Abstractions.UpdateProvider; +using BotFramework.Config; using BotFramework.Middleware; using BotFramework.ParameterResolvers; using BotFramework.Session; using BotFramework.Setup; +using BotFramework.UpdateProvider; +using Microsoft.Extensions.Configuration; using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.Hosting; +using Microsoft.Extensions.Options; +using MihaZupan; +using Telegram.Bot; namespace BotFramework { @@ -14,10 +23,49 @@ public static class ServiceExtensions { public static void AddTelegramBot(this IServiceCollection collection) { + collection.AddSingleton(); + + collection.AddOptions() + .Configure((config, configuration) => configuration.GetSection("BotConfig").Bind(config)); + collection.AddDefaultParameterParsers(); + collection.AddHttpClient() + .AddTypedClient((client, provider) => + { + var botConfig = provider.GetService>().Value; + + var apiUrl = botConfig.BotApiUrl; + if (string.IsNullOrWhiteSpace(apiUrl)) + { + apiUrl = null; + } + + var options = + new TelegramBotClientOptions(botConfig.Token, apiUrl, botConfig.UseTestEnv); + + return new TelegramBotClient(options, client); + }) + .ConfigurePrimaryHttpMessageHandler(provider => + { + var botConfig = provider.GetService>().Value; + + if (!botConfig.UseSOCKS5) + { + return new HttpClientHandler(); + } + + var proxy = new HttpToSocks5Proxy(botConfig.SOCKS5Address, + botConfig.SOCKS5Port, + botConfig.SOCKS5User, + botConfig.SOCKS5Password); + + return new HttpClientHandler { Proxy = proxy }; + }); + collection.AddSingleton(); collection.AddTransient(x => (Bot)x.GetService()); + collection.AddSingleton(x => (Bot)x.GetService()); //won't break existent 0.5 users collection.AddTelegramBotInMemoryStorage(); @@ -25,22 +73,14 @@ public static void AddTelegramBot(this IServiceCollection collection) public static void AddTelegramBot(this IServiceCollection collection) where T: BotStartup, new() { - collection.AddDefaultParameterParsers(); - var startup = new T(); - var wares = startup.__SetupInternal(); - - foreach(var ware in wares) + foreach (var ware in startup.__SetupInternal()) { collection.AddScoped(typeof(IMiddleware),ware); } - collection.AddSingleton(x => new Bot(x, x.GetRequiredService(), typeof(T))); - collection.AddTransient(x => (Bot)x.GetService()); - - //won't break existent 0.5 users - collection.AddTelegramBotInMemoryStorage(); + collection.AddTelegramBot(); } public static IServiceCollection AddTelegramBotParameterParser( diff --git a/TGBotFramework/BotFramework/UpdateProvider/PollingUpdateProvider.cs b/TGBotFramework/BotFramework/UpdateProvider/PollingUpdateProvider.cs new file mode 100644 index 0000000..dd9ce0e --- /dev/null +++ b/TGBotFramework/BotFramework/UpdateProvider/PollingUpdateProvider.cs @@ -0,0 +1,54 @@ +using System; +using System.Threading; +using System.Threading.Tasks; +using BotFramework.Abstractions.UpdateProvider; +using Telegram.Bot; +using Telegram.Bot.Polling; +using Telegram.Bot.Types; + +namespace BotFramework.UpdateProvider; + +public class PollingUpdateProvider: IUpdateProvider +{ + private readonly IUpdateTarget _updateTarget; + private readonly ITelegramBotClient _client; + + private readonly CancellationTokenSource _canRunTokenSource = new(); + + public PollingUpdateProvider(ITelegramBotClient client, IUpdateTarget updateTarget) + { + _updateTarget = updateTarget; + _client = client; + } + + public async Task StartAsync(CancellationToken token) + { + await _client.DeleteWebhookAsync(cancellationToken: token); + token.ThrowIfCancellationRequested(); + _client.StartReceiving( + HandleUpdateAsync, + HandleErrorAsync, + new ReceiverOptions { ThrowPendingUpdates = false }, + _canRunTokenSource.Token + ); + } + + private Task HandleUpdateAsync(ITelegramBotClient botClient, Update update, CancellationToken cancellationToken) + { + _updateTarget.Push(update); + + return Task.CompletedTask; + } + + private async Task HandleErrorAsync(ITelegramBotClient botClient, Exception exception, CancellationToken cancellationToken) + { + Console.WriteLine(exception); + await Task.Delay(5000, cancellationToken); //иначе будет долбиться и грузить проц на 100% + } + + public Task StopAsync(CancellationToken token) + { + _canRunTokenSource.Cancel(); + return Task.CompletedTask; + } +} diff --git a/TGBotFramework/Examples/BotAsWorkerService/appsettings.example.json b/TGBotFramework/Examples/BotAsWorkerService/appsettings.example.json index 92bad33..d02a7ff 100644 --- a/TGBotFramework/Examples/BotAsWorkerService/appsettings.example.json +++ b/TGBotFramework/Examples/BotAsWorkerService/appsettings.example.json @@ -7,15 +7,16 @@ } }, "BotConfig": { - "token": "{bot token here}", - "webHookURL": null, - "useCertificate": false, - "webHookSertPath": null, - "enableWebHook": false, + "token": "{your bot token}", + "webhook": { + "url": "https://localhost:8080", + "host": "localhost", + "port": 8080 + }, "sockS5Address": "sock.address.here", "sockS5Port": 1080, "sockS5User": "sockUser", "sockS5Password": "sockPassword", "useSOCKS5": false } -} +} \ No newline at end of file diff --git a/TGBotFramework/Examples/MsgDumpBot/appsettings.example.json b/TGBotFramework/Examples/MsgDumpBot/appsettings.example.json index 92bad33..d02a7ff 100644 --- a/TGBotFramework/Examples/MsgDumpBot/appsettings.example.json +++ b/TGBotFramework/Examples/MsgDumpBot/appsettings.example.json @@ -7,15 +7,16 @@ } }, "BotConfig": { - "token": "{bot token here}", - "webHookURL": null, - "useCertificate": false, - "webHookSertPath": null, - "enableWebHook": false, + "token": "{your bot token}", + "webhook": { + "url": "https://localhost:8080", + "host": "localhost", + "port": 8080 + }, "sockS5Address": "sock.address.here", "sockS5Port": 1080, "sockS5User": "sockUser", "sockS5Password": "sockPassword", "useSOCKS5": false } -} +} \ No newline at end of file diff --git a/TGBotFramework/Examples/Webhooks/EventHandler.cs b/TGBotFramework/Examples/Webhooks/EventHandler.cs new file mode 100644 index 0000000..5e87dd3 --- /dev/null +++ b/TGBotFramework/Examples/Webhooks/EventHandler.cs @@ -0,0 +1,19 @@ +using BotFramework; +using BotFramework.Attributes; +using BotFramework.Utils; +using Newtonsoft.Json; + +namespace Webhooks; + +public class EventHandler : BotEventHandler +{ + [Command("dump")] + public async Task HandleDump() + { + var message = RawUpdate.Message!.ReplyToMessage ?? RawUpdate.Message; + var text = HtmlString.Empty + .CodeWithStyle("language-json", JsonConvert.SerializeObject(message, Formatting.Indented)); + + await Bot.SendHtmlStringAsync(Chat, text, replyTo: message.MessageId); + } +} diff --git a/TGBotFramework/Examples/Webhooks/Program.cs b/TGBotFramework/Examples/Webhooks/Program.cs new file mode 100644 index 0000000..419bdef --- /dev/null +++ b/TGBotFramework/Examples/Webhooks/Program.cs @@ -0,0 +1,12 @@ +// See https://aka.ms/new-console-template for more information + +using BotFramework.Webhook; +using Microsoft.Extensions.Hosting; + +Host.CreateDefaultBuilder(args) + .ConfigureServices((hostContext, services) => + { + services.AddTelegramBotWebhook(); + }) + .Build() + .Run(); \ No newline at end of file diff --git a/TGBotFramework/Examples/Webhooks/Webhooks.csproj b/TGBotFramework/Examples/Webhooks/Webhooks.csproj new file mode 100644 index 0000000..09bc6e3 --- /dev/null +++ b/TGBotFramework/Examples/Webhooks/Webhooks.csproj @@ -0,0 +1,28 @@ + + + + Exe + net6.0 + enable + enable + + + + + + + + + + + + + + PreserveNewest + + + PreserveNewest + + + + diff --git a/TGBotFramework/Examples/Webhooks/appsettings.example.json b/TGBotFramework/Examples/Webhooks/appsettings.example.json new file mode 100644 index 0000000..5382b60 --- /dev/null +++ b/TGBotFramework/Examples/Webhooks/appsettings.example.json @@ -0,0 +1,23 @@ +{ + "Logging": { + "LogLevel": { + "Default": "Information", + "Microsoft": "Warning", + "Microsoft.Hosting.Lifetime": "Information" + } + }, + "BotConfig": { + "token": "{your bot token}", + "webhook": { + "url": "https://localhost:8080", + "host": "localhost", + "port": 8080, + "secretToken": null + }, + "sockS5Address": "sock.address.here", + "sockS5Port": 1080, + "sockS5User": "sockUser", + "sockS5Password": "sockPassword", + "useSOCKS5": false + } +} \ No newline at end of file diff --git a/TGBotFramework/TGBotFramework.sln b/TGBotFramework/TGBotFramework.sln index dcdb1fc..cb1b7bc 100644 --- a/TGBotFramework/TGBotFramework.sln +++ b/TGBotFramework/TGBotFramework.sln @@ -21,11 +21,15 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "BotAsWorkerService", "Examp {C35DA4BB-802F-457D-84F5-CDE25C16CC36} = {C35DA4BB-802F-457D-84F5-CDE25C16CC36} EndProjectSection EndProject -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "MsgDumpBot", "Examples\MsgDumpBot\MsgDumpBot.csproj", "{61B6E441-97DA-479A-82C7-BE3905139C0C}" +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "MsgDumpBot", "Examples\MsgDumpBot\MsgDumpBot.csproj", "{61B6E441-97DA-479A-82C7-BE3905139C0C}" ProjectSection(ProjectDependencies) = postProject {C35DA4BB-802F-457D-84F5-CDE25C16CC36} = {C35DA4BB-802F-457D-84F5-CDE25C16CC36} EndProjectSection EndProject +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "BotFramework.Webhook", "BotFramework.Webhook\BotFramework.Webhook.csproj", "{622D7FDB-0DB3-4119-8531-8086EA6071F6}" +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Webhooks", "Examples\Webhooks\Webhooks.csproj", "{32A8CB0D-78C5-4B1C-A705-9F571BCFEF51}" +EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Any CPU = Debug|Any CPU @@ -57,6 +61,18 @@ Global {61B6E441-97DA-479A-82C7-BE3905139C0C}.Deploy|Any CPU.Build.0 = Debug|Any CPU {61B6E441-97DA-479A-82C7-BE3905139C0C}.Release|Any CPU.ActiveCfg = Release|Any CPU {61B6E441-97DA-479A-82C7-BE3905139C0C}.Release|Any CPU.Build.0 = Release|Any CPU + {622D7FDB-0DB3-4119-8531-8086EA6071F6}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {622D7FDB-0DB3-4119-8531-8086EA6071F6}.Debug|Any CPU.Build.0 = Debug|Any CPU + {622D7FDB-0DB3-4119-8531-8086EA6071F6}.Deploy|Any CPU.ActiveCfg = Debug|Any CPU + {622D7FDB-0DB3-4119-8531-8086EA6071F6}.Deploy|Any CPU.Build.0 = Debug|Any CPU + {622D7FDB-0DB3-4119-8531-8086EA6071F6}.Release|Any CPU.ActiveCfg = Release|Any CPU + {622D7FDB-0DB3-4119-8531-8086EA6071F6}.Release|Any CPU.Build.0 = Release|Any CPU + {32A8CB0D-78C5-4B1C-A705-9F571BCFEF51}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {32A8CB0D-78C5-4B1C-A705-9F571BCFEF51}.Debug|Any CPU.Build.0 = Debug|Any CPU + {32A8CB0D-78C5-4B1C-A705-9F571BCFEF51}.Deploy|Any CPU.ActiveCfg = Debug|Any CPU + {32A8CB0D-78C5-4B1C-A705-9F571BCFEF51}.Deploy|Any CPU.Build.0 = Debug|Any CPU + {32A8CB0D-78C5-4B1C-A705-9F571BCFEF51}.Release|Any CPU.ActiveCfg = Release|Any CPU + {32A8CB0D-78C5-4B1C-A705-9F571BCFEF51}.Release|Any CPU.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE @@ -65,6 +81,7 @@ Global {0374D7A0-B492-4497-A3EE-E85A131B71C8} = {E8A2CE81-FE3A-49D1-87C4-9E0E0AA10F07} {952B094B-E292-4253-9AA9-ECB18C4A5270} = {E59A7AC5-350D-424E-85D8-E83EE12DCD36} {61B6E441-97DA-479A-82C7-BE3905139C0C} = {E59A7AC5-350D-424E-85D8-E83EE12DCD36} + {32A8CB0D-78C5-4B1C-A705-9F571BCFEF51} = {E59A7AC5-350D-424E-85D8-E83EE12DCD36} EndGlobalSection GlobalSection(ExtensibilityGlobals) = postSolution SolutionGuid = {2C8255F6-EA14-464E-A7CB-947B231E0433}