Skip to content

javlonfattoev/JFA.Telegram

Repository files navigation

JFA.Telegram

Telegram bot with commands

Example project

Install package from nuget.org

NuGet\Install-Package JFA.Telegram -Version <VERSION>

Create MessageContext

public class MessageContext : MessageContextBase<User>
{
    public string? Username { get; set; }
    public int MessageId { get; set; }
}

Add lifetime attribute to service implementations, JFA.DependencyInjection

[Scoped]
public class TelegramBotService : ITelegramBotService
{...}

Create command handler

[Command(EStep.InMainMenu)]
public class ProfileCommand : CommandHandlerBase<MessageContext>
{
    public ProfileCommand(XarajatDbContext context, TelegramBotService telegramBotService)
    {
    }

    [Method("/profile")]
    public async Task SendProfile(MessageContext context)
    {
        await TelegramBotService.SendMessage(context.User!.ChatId, context.User!.Name!);
    }

    [Method("/start")]
    public async Task SendMenu(MessageContext context)
    {
        await TelegramBotService.SendMessage(context.User!.ChatId, "Menu");
    }
}

About

Telegram commands

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages