Aiursoft.Kahla.SDK
8.0.7
See the version list below for details.
dotnet add package Aiursoft.Kahla.SDK --version 8.0.7
NuGet\Install-Package Aiursoft.Kahla.SDK -Version 8.0.7
<PackageReference Include="Aiursoft.Kahla.SDK" Version="8.0.7" />
paket add Aiursoft.Kahla.SDK --version 8.0.7
#r "nuget: Aiursoft.Kahla.SDK, 8.0.7"
// Install Aiursoft.Kahla.SDK as a Cake Addin #addin nuget:?package=Aiursoft.Kahla.SDK&version=8.0.7 // Install Aiursoft.Kahla.SDK as a Cake Tool #tool nuget:?package=Aiursoft.Kahla.SDK&version=8.0.7
Kahla.SDK
Kahla.SDK is a library for writting bots and extends for Kahla.
Tutorial - How to create a bot with Kahla.SDK
This will introduce how to write a bot for Kahla. Before starting, make sure you have .NET Core SDK
installed.
Download:
1. Create a new console .NET Core app
Open your terminal and type the following command to create a new console app.
mkdir MyBot
cd MyBot
dotnet new console
2. Add dependency for Kahla.SDK
Execute the following command to add Kahla.SDK as a dependency.
dotnet add package Kahla.SDK
3. Create your bot
Create a new file, and name it FirstBot.cs
. In this C# class, extend the class BotBase
. Override the default OnMessage
method.
using Kahla.SDK.Abstract;
using Kahla.SDK.Events;
using System.Threading.Tasks;
namespace MyBot
{
public class FirstBot : BotBase
{
public async override Task OnMessage(string inputMessage, NewMessageEvent eventContext)
{
if (eventContext.Message.SenderId == Profile.Id)
{
return; // Ignore messages sent by itself.
}
// Echo all messages.
await SendMessage(inputMessage, eventContext.ConversationId);
}
}
}
4. Create your bot start up logic
Modify your Program.cs
to start your bot.
using Kahla.SDK.Abstract;
using System.Threading.Tasks;
namespace MyBot
{
class Program
{
public static async Task Main(string[] args)
{
await new BotBuilder()
.Build<FirstBot>()
.Run();
}
}
}
5. Start your bot
Execute the following command to start your bot.
dotnet run
You need to sign in an Aiursoft account which identies your bot. If you don't have one, register here.
After your bot is started, just talk to it with another account!
That's all! Happy coding!
6. Additional info
For dependency injection and advanced start up, Kahla.Bot supports custom start up configure.
Modify your Program.cs
like this to use advanced start up:
using Kahla.Bot.Bots;
using Kahla.SDK.Abstract;
using System.Linq;
using System.Threading.Tasks;
namespace MyBot
{
public class Program
{
public async static Task Main(string[] args)
{
await CreateBotBuilder()
.Build<FirstBot>()
.Run();
}
public static BotBuilder CreateBotBuilder()
{
return new BotBuilder()
.UseStartUp<StartUp>();
}
}
}
And create a new class named: StartUp
:
using Kahla.SDK.Abstract;
using Microsoft.Extensions.DependencyInjection;
using Newtonsoft.Json;
using Newtonsoft.Json.Serialization;
namespace MyBot
{
public class StartUp : IStartUp
{
public void ConfigureServices(IServiceCollection services)
{
// Add your own services.
services.AddTransient<YourTransientService>();
services.AddScoped<YourScopedService>();
services.AddSingleton<YourSingletonService>();
}
public void Configure()
{
// This will execute after services are configured. You can edit some global settings here.
JsonConvert.DefaultSettings = () => new JsonSerializerSettings()
{
DateTimeZoneHandling = DateTimeZoneHandling.Utc,
DateFormatHandling = DateFormatHandling.IsoDateFormat,
ContractResolver = new CamelCasePropertyNamesContractResolver(),
};
}
}
}
For more bot demo, please search bot.kahla.app
in Kahla. Or view more demos;
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. |
-
net8.0
- Aiursoft.AiurProtocol (>= 8.0.13)
- Aiursoft.ArrayDb.Partitions (>= 1.0.15)
- Microsoft.AspNetCore.Mvc.NewtonsoftJson (>= 8.0.10)
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.