-
Telegram.BotBuilder.CalendarPicker is a library that allows you to pick a date from your telegram bot.
-
Based on
CalendarPicker
but modified forTelegram.BotBuilder
and fixed some bugs and errors. -
Works with new version of TelegramAPI
Telegram.Bot
18.0.0-alpha.3
-
Based on dotnet standard 2.1
And of course, I made this library for my own use, I believe that it can be useful when you are going to develop complex Telegram bots. I am always open to your changes, commits and wishes :)
Add Telegram.BotBuilder.CalendarPicker to your project:
Package Manager
PM> NuGet\Install-Package Telegram.BotBuilder.CalendarPicker -Version 1.0.0
.NET CLI
>dotnet add package Telegram.BotBuilder.CalendarPicker
or something else
Next you should create your handler inherited from ICalendarHandler to handle picked date form telegram bot. For example:
public class CalendarTestHandler : ICalendarHandler
{
public async Task HandlePickedDateAsync(
ITelegramBotClient context,
Message message,
DateTime pickedDate,
CancellationToken cancellationToken
)
{
await context.SendTextMessageAsync(
message.Chat,
$"PickedDate: {pickedDate:d}",
cancellationToken: cancellationToken
);
}
}
After that you can add a calendar picker with a handler
// add calendar with handler
builder.Services.AddCalendarPicker<CalendarTestHandler>("nameOfYourBot", "tokenOfBot");
AddCalendarPicker<> supports various features, including:
- locale, if you need a locale;
- datePickerTitle, for a title of datepicker message;
- initialDate, to select a specific start date;
Next you can bind using LongPolling with adding command string:
// bind calendar as LongPolling
await app.UseCalendarPickerLongPolling("calendar");
Or as Webhook with adding command string and uri of your webhook:
// or as Webhook
await app.UseCalendarPickerWebhook("calendar", new Uri("https://example.com/calendarbot/webhook"));
You can find all these examples and work with them in the webapi project