BaleBotNet 2.1.0
dotnet add package BaleBotNet --version 2.1.0
NuGet\Install-Package BaleBotNet -Version 2.1.0
<PackageReference Include="BaleBotNet" Version="2.1.0" />
<PackageVersion Include="BaleBotNet" Version="2.1.0" />
<PackageReference Include="BaleBotNet" />
paket add BaleBotNet --version 2.1.0
#r "nuget: BaleBotNet, 2.1.0"
#addin nuget:?package=BaleBotNet&version=2.1.0
#tool nuget:?package=BaleBotNet&version=2.1.0
این را به فارسی بخوانید (Persian)
BaleBotNet
A .NET library for interacting with the Bale Messenger Bot API.
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 | Versions 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. |
-
net8.0
-
net9.0
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.