Skip to content

Latest commit

 

History

History
72 lines (51 loc) · 3.12 KB

File metadata and controls

72 lines (51 loc) · 3.12 KB

Telegram.BotBuilder.CalendarPicker

Nuget Nuget GitHub license

Telegram CalendarPicker Logo

  • Telegram.BotBuilder.CalendarPicker is a library that allows you to pick a date from your telegram bot.

  • Based on CalendarPicker but modified for Telegram.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 :)

How do I get started?

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