BaleBotNet 2.1.0

dotnet add package BaleBotNet --version 2.1.0
                    
NuGet\Install-Package BaleBotNet -Version 2.1.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="BaleBotNet" Version="2.1.0" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="BaleBotNet" Version="2.1.0" />
                    
Directory.Packages.props
<PackageReference Include="BaleBotNet" />
                    
Project file
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add BaleBotNet --version 2.1.0
                    
#r "nuget: BaleBotNet, 2.1.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.
#addin nuget:?package=BaleBotNet&version=2.1.0
                    
Install BaleBotNet as a Cake Addin
#tool nuget:?package=BaleBotNet&version=2.1.0
                    
Install BaleBotNet as a Cake Tool

این را به فارسی بخوانید (Persian)

BaleBotNet

A .NET library for interacting with the Bale Messenger Bot API.

Subscribe us in Bale

BaleBotNet Nuget

Installation

To use BaleBotNet in your project, add the NuGet package:

dotnet add package BaleBotNet

Or, in the NuGet Package Manager Console:

Install-Package BaleBotNet

Usage in ASP.NET Core Projects

Step 1: Add BaleBotClient to the Service Container

In your Program.cs, use the AddBaleBotClient extension method to register the BaleBotClient:

var builder = WebApplication.CreateBuilder(args);

// Add BaleBotClient to the service container
builder.Services.AddBaleBotClient("YOUR_BOT_TOKEN");

var app = builder.Build();

Step 2: Map the Webhook

Use the MapBaleBotWebhook extension method to configure the webhook endpoint. You can handle different types of updates (e.g., messages, edited messages, callback queries, etc.).

Example 1: Handling Specific Update Types
app.MapBaleBotWebhook(
    appBaseUrl: "https://yourdomain.com",
    handleMessage: async (message) =>
    {
        Console.WriteLine($"Received message: {message.Text}");
    },
    handleEditedMessage: async (editedMessage) =>
    {
        Console.WriteLine($"Edited message: {editedMessage.Text}");
    },
    handleCallbackQuery: async (callbackQuery) =>
    {
        Console.WriteLine($"Callback query: {callbackQuery.Data}");
    },
    handlePreCheckoutQuery: async (preCheckoutQuery) =>
    {
        Console.WriteLine($"Pre-checkout query: {preCheckoutQuery.InvoicePayload}");
    }
);
Example 2: Handling All Updates in a Single Function
app.MapBaleBotWebhook(
    appBaseUrl: "https://yourdomain.com",
    handleUpdate: async (update) =>
    {
        switch (update)
        {
            case { Message: { } message }:
                Console.WriteLine($"Received message: {message.Text}");
                break;
            case { EditedMessage: { } editedMessage }:
                Console.WriteLine($"Edited message: {editedMessage.Text}");
                break;
            case { CallbackQuery: { } callbackQuery }:
                Console.WriteLine($"Callback query: {callbackQuery.Data}");
                break;
            case { PreCheckoutQuery: { } preCheckoutQuery }:
                Console.WriteLine($"Pre-checkout query: {preCheckoutQuery.InvoicePayload}");
                break;
            default:
                Console.WriteLine("Unknown update type.");
                break;
        }
    }
);

Step 3: Run the Application

Run your application, and the webhook will be automatically set up with a unique path. The bot will start receiving updates at the configured endpoint.

app.Run();

Work with Methods

var me = await bot.GetMe();

var message = await bot.SendMessage("123", $"Hi! I'm @{me.Username} !");

message = await bot.SendMessage(
    chatId: "123",
    text: "Hello, World! Reply with InlineKeyboardMarkup",
    replyToMessageId: firstMessageId,
    replyMarkup: new InlineKeyboardMarkup
    {
        InlineKeyboard =
        [
            [
                new() { Text = "Text1", CallbackData = "test1" },
                new() { Text = "Text2", CallbackData = "test2" }
            ]
        ]
    }
);
Console.WriteLine($"Message Sent: {message.MessageId}");

There are lot of Samples at Sample Project

Product Compatible and additional computed target framework versions.
.NET net8.0 is compatible.  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.  net9.0 is compatible.  net9.0-android was computed.  net9.0-browser was computed.  net9.0-ios was computed.  net9.0-maccatalyst was computed.  net9.0-macos was computed.  net9.0-tvos was computed.  net9.0-windows was computed.  net10.0 was computed.  net10.0-android was computed.  net10.0-browser was computed.  net10.0-ios was computed.  net10.0-maccatalyst was computed.  net10.0-macos was computed.  net10.0-tvos was computed.  net10.0-windows was computed. 
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
2.1.0 143 5/27/2025
2.0.0 132 5/19/2025