Aiursoft.Kahla.SDK 8.0.10

There is a newer version of this package available.
See the version list below for details.
dotnet add package Aiursoft.Kahla.SDK --version 8.0.10                
NuGet\Install-Package Aiursoft.Kahla.SDK -Version 8.0.10                
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="Aiursoft.Kahla.SDK" Version="8.0.10" />                
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add Aiursoft.Kahla.SDK --version 8.0.10                
#r "nuget: Aiursoft.Kahla.SDK, 8.0.10"                
#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 Aiursoft.Kahla.SDK as a Cake Addin
#addin nuget:?package=Aiursoft.Kahla.SDK&version=8.0.10

// Install Aiursoft.Kahla.SDK as a Cake Tool
#tool nuget:?package=Aiursoft.Kahla.SDK&version=8.0.10                

Kahla.SDK

Kahla.SDK is a library for writting bots and extends for Kahla.

NuGet version (Kahla.SDK) Build status

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. .NET 8 SDK

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

demo

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!

demo

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 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. 
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
8.0.12 69 12/11/2024
8.0.11 79 12/7/2024
8.0.10 84 12/4/2024
8.0.9 76 11/30/2024
8.0.8 88 11/13/2024
8.0.7 92 11/12/2024
8.0.6 89 11/10/2024
8.0.5 86 10/29/2024
8.0.4 97 10/11/2024
8.0.3 92 10/9/2024
8.0.2 86 10/7/2024
8.0.1 101 9/24/2024