Telegram.BotFramework 0.9.0

dotnet add package Telegram.BotFramework --version 0.9.0
NuGet\Install-Package Telegram.BotFramework -Version 0.9.0
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="Telegram.BotFramework" Version="0.9.0" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add Telegram.BotFramework --version 0.9.0
#r "nuget: Telegram.BotFramework, 0.9.0"
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
// Install Telegram.BotFramework as a Cake Addin
#addin nuget:?package=Telegram.BotFramework&version=0.9.0

// Install Telegram.BotFramework as a Cake Tool
#tool nuget:?package=Telegram.BotFramework&version=0.9.0

Telegram.Bot.Framework

This Framework is an early beta which will be developed the next few weeks / months. It's based on Telegram.Bot.

The goal is to achieve a simple and lightweight framework to build chat bots with reusable code.

ICommand

An ICommand is a simple command without parameters. Each class wich derives from ICommand can be called by different commands through the CommandAttribute.

Example 1 - No parameters

[Command("/start")] //The CommandAttribute defines the command to call the Command from Telegram-Chat
[Command("/start2")] //You can define several commands
class StartCommand : ICommand
{
    public async Task<bool> CanInvoke(ITelegramBotClient client, Update update, object args) //CanInvoke gives the ability to check whether the command can be actually called
    {
        return true;
    }

    public async Task<bool> Invoke(ITelegramBotClient client, Update update, object args)
    {
        return await data.Client.SendTextMessageAsync(data.Update.Message.Chat.Id, "Hello World!");
        return true;
    }
}

Example 2 - With parameters

//You can simply define the paramater with {} and define the parameter container
//If you send the message "/start 5", the bot will answer with "Hello World 5!"
[Command("/start {id}", ArgumentType = typeof(StartCommandParameter))]
//The default command can be in the same class
//If you send the message "/start", the bot will answer with "Hello World!"
[Command("/start")]
class StartCommand : ICommand, ICommand<StartCommandParameter>
{
    public async Task<bool> CanInvoke(ITelegramBotClient client, Update update, object args) //CanInvoke gives the ability to check whether the command can be actually called
    {
        return true;
    }

    public async Task<bool> Invoke(ITelegramBotClient client, Update update, object args)
    {
        await data.Client.SendTextMessageAsync(data.Update.Message.Chat.Id, "Hello World!");
        return true;
    }
    public async Task<bool> CanInvoke(ITelegramBotClient client, Update update, StartCommandParameter args)
    {
        return true;
    }

    public async Task<bool> Invoke(ITelegramBotClient client, Update update, StartCommandParameter args) //If the id were an integer, args.Id is set
    {
        await data.Client.SendTextMessageAsync(data.Update.Message.Chat.Id, "Hello World "+ args.Id +"!");
        return true;
    }
}
class StartCommandParameter
{
    public int Id { get; set; }
}

##Initialize and start using the bot

    static void Main(string[] args)
    {
        var client = new Telegram.Bot.TelegramBotClient("your_token"); //initialize the client
        _helper = new Telegram.Bot.Framework.TelegramBotClientHelper(client); //inititalize the client helper
        _helper.CommandManager.RegisterCommand(new StartCommand()); //register the StartCommand from Example 1 or 2
        client.StartReceiving(); //Start receiving commands

        while (true)
            Console.ReadKey();
    }
Product Compatible and additional computed target framework versions.
.NET net5.0 was computed.  net5.0-windows was computed.  net6.0 was computed.  net6.0-android was computed.  net6.0-ios was computed.  net6.0-maccatalyst was computed.  net6.0-macos was computed.  net6.0-tvos was computed.  net6.0-windows was computed.  net7.0 was computed.  net7.0-android was computed.  net7.0-ios was computed.  net7.0-maccatalyst was computed.  net7.0-macos was computed.  net7.0-tvos was computed.  net7.0-windows was computed.  net8.0 was computed.  net8.0-android was computed.  net8.0-browser was computed.  net8.0-ios was computed.  net8.0-maccatalyst was computed.  net8.0-macos was computed.  net8.0-tvos was computed.  net8.0-windows was computed. 
.NET Core netcoreapp3.1 is compatible. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last updated
0.9.0 397 11/10/2020

First release