mirror of
https://github.com/yawaflua/Telegram.Net.git
synced 2025-12-10 04:29:28 +02:00
Create project
This commit is contained in:
14
Examples/Telegram.Examples/Program.cs
Normal file
14
Examples/Telegram.Examples/Program.cs
Normal 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);
|
||||
}
|
||||
});
|
||||
});
|
||||
15
Examples/Telegram.Examples/Telegram.Examples.csproj
Normal file
15
Examples/Telegram.Examples/Telegram.Examples.csproj
Normal 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>
|
||||
40
Examples/Telegram.Examples/UpdatePolling/Update.cs
Normal file
40
Examples/Telegram.Examples/UpdatePolling/Update.cs
Normal 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}");
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user