Create project

This commit is contained in:
Dmitri Shimanski
2025-03-19 11:12:13 +02:00
commit 1a8a999d5b
18 changed files with 659 additions and 0 deletions

View File

@@ -0,0 +1,14 @@
using Microsoft.Extensions.Hosting;
using Telegram.Net;
var webHost = Host.CreateDefaultBuilder()
.ConfigureServices(k =>
{
k.ConnectTelegram(new("YOUR-TOKEN")
{
errorHandler = async (client, exception, ctx) =>
{
await Console.Out.WriteLineAsync(exception.Message);
}
});
});

View File

@@ -0,0 +1,15 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net7.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Microsoft.Extensions.Hosting" Version="9.0.3" />
<ProjectReference Include="..\..\Telegram.Net\Telegram.Net.csproj" />
</ItemGroup>
</Project>

View File

@@ -0,0 +1,40 @@
using Telegram.Bot;
using Telegram.Bot.Types;
using Telegram.Net.Attributes;
using Telegram.Net.Interfaces;
namespace Telegram.Examples.UpdatePolling;
public class Update : IUpdatePollingSerivce
{
[Update]
public async Task UpdateExample(ITelegramBotClient client, Bot.Types.Update update, CancellationToken ctx)
{
if (update.Poll != null)
{
Console.WriteLine(update.Poll.IsClosed);
}
}
[Callback("act-")]
public async Task CallbackExample(ITelegramBotClient client, CallbackQuery query, CancellationToken ctx)
{
Console.WriteLine(query.Message!.Text);
}
[Command("/start")]
public async Task StartCommand(ITelegramBotClient client, Message message, CancellationToken ctx)
{
if (message.Text!.Contains(" ") && message.Text.Split(" ")[1] == "test")
await client.SendMessage(message.From!.Id, "Hello, I`m example bot. And this - command with subparam", cancellationToken: ctx);
else
await client.SendMessage(message.From!.Id, "Hello, I`m example bot.", cancellationToken: ctx);
}
[EditMessage]
public async Task EditMessageExmaple(ITelegramBotClient client, Message message, CancellationToken ctx)
{
Console.WriteLine($"new message text: {message.Text}");
}
}