mirror of
https://github.com/yawaflua/Telegram.Net.git
synced 2025-12-10 04:29:28 +02:00
Fix error with broken dependencies.
This commit is contained in:
@@ -1,4 +1,5 @@
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
using Microsoft.Extensions.Configuration;
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
using Microsoft.Extensions.Hosting;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using Telegram.Net;
|
||||
@@ -7,12 +8,11 @@ var webHost = Host.CreateDefaultBuilder()
|
||||
.ConfigureLogging(l => l.ClearProviders().AddConsole())
|
||||
.ConfigureServices(k =>
|
||||
{
|
||||
k.ConnectTelegram(new("TOKEN")
|
||||
{
|
||||
errorHandler = async (client, exception, ctx) =>
|
||||
{
|
||||
Console.WriteLine(exception);
|
||||
}
|
||||
});
|
||||
var _conf = new ConfigurationBuilder()
|
||||
.AddJsonFile("appsettings.json")
|
||||
.AddEnvironmentVariables()
|
||||
.Build();
|
||||
k.AddSingleton(_conf);
|
||||
k.ConnectTelegram(new(_conf.GetValue<string>("telegram_test_token")));
|
||||
});
|
||||
webHost.Build().Run();
|
||||
@@ -11,6 +11,9 @@
|
||||
<ItemGroup>
|
||||
<PackageReference Include="Microsoft.Extensions.Hosting" Version="9.0.3" />
|
||||
<ProjectReference Include="..\..\Telegram.Net\Telegram.Net.csproj" />
|
||||
|
||||
<None CopyToOutputDirectory="Always" Include="appsettings.json"></None>
|
||||
</ItemGroup>
|
||||
|
||||
|
||||
</Project>
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
using Telegram.Bot;
|
||||
using Microsoft.Extensions.Configuration;
|
||||
using Telegram.Bot;
|
||||
using Telegram.Bot.Types;
|
||||
using Telegram.Net.Attributes;
|
||||
using Telegram.Net.Interfaces;
|
||||
@@ -7,6 +8,11 @@ namespace Telegram.Examples.UpdatePolling;
|
||||
|
||||
public class Update : IUpdatePollingService
|
||||
{
|
||||
private static IConfiguration _conf;
|
||||
public Update(IConfiguration conf)
|
||||
{
|
||||
_conf = conf;
|
||||
}
|
||||
[Update]
|
||||
public async Task UpdateExample(ITelegramBotClient client, Bot.Types.Update update, CancellationToken ctx)
|
||||
{
|
||||
@@ -31,6 +37,12 @@ public class Update : IUpdatePollingService
|
||||
await client.SendMessage(message.From!.Id, "Hello, I`m example bot.", cancellationToken: ctx);
|
||||
}
|
||||
|
||||
[Command("/test_conf")]
|
||||
public async Task TestConfigurationBuilder(ITelegramBotClient client, Message message, CancellationToken cts)
|
||||
{
|
||||
await client.SendMessage(message.Chat.Id, _conf.GetValue<string>("ExampleMessage") ?? throw new Exception("Not found"));
|
||||
}
|
||||
|
||||
[EditMessage]
|
||||
public async Task EditMessageExmaple(ITelegramBotClient client, Message message, CancellationToken ctx)
|
||||
{
|
||||
|
||||
4
Examples/Telegram.Examples/appsettings.json
Normal file
4
Examples/Telegram.Examples/appsettings.json
Normal file
@@ -0,0 +1,4 @@
|
||||
{
|
||||
"ExampleMessage": "Test!",
|
||||
"telegram_test_token": "PROVIDE_TOKEN"
|
||||
}
|
||||
Reference in New Issue
Block a user