Skip to main content

A simple Tinode chatbot framework.

Project description

Karuha

License PyPI Python Version

A simple Tinode chatbot framework.

The name of the library Karuha comes from the character Karuha Ramukone (カルハ・ラムコネ) in the game 星空鉄道とシロの旅.

Karuha

カルハ・ラムコネと申します。カルハちゃんって呼んでいいわよ

Installation

From pip:

pip install KaruhaBot

From source code:

git clone https://github.com/Ovizro/Karuha.git
cd Karuha
make install

Quick Start

Before starting, you need to make sure you have the Tinode service running locally with its gRPC port set to the default value of 16060. If your service is not local or the default port has been changed, you need to add additional server configuration items in the following code.

Create a new file config.json and write the following content:

{
    "server": {
        "host": "localhost:16060",
        "listen": "0.0.0.0:40051"
    },
    "bots": [
        {
            "name": "chatbot",
            "schema": "basic",
            "secret": "{chatbot_login_name}:{chatebot_login_passwd}"
        }
    ]
}

Replace {chatbot_login_name} and {chatebot_login_passwd} with the chatbot’s login account name and password in the Tinode server.

Start the chatbot using the following command:

python -m Karuha ./config.json

You can now see the messages others have sent to the chatbot from the command line.Yeah, that's it, no more.

Go Further?

Well, you can actually go a step further and send messages to users.

Currently, if you want to reply to a message, you currently need to add a handler for the event yourself. This is not a simple process. Fortunately, we are about to introduce a command module to improve this.

Because this is a relatively low-level API, I will only give an example to show how karuha is currently used in python:

import karuha
from karuha import Bot, MessageEvent, PublishEvent


bot = Bot(
    "chatbot",
    "basic",
    "chatbot:123456"
)


@karuha.on(MessageEvent)
async def reply(event: MessageEvent) -> None:
    if event.text == "Hello!":
        PublishEvent.new(
            event.bot,
            event.topic,
            "Hello world!"
        )


if __name__ == "__main__":
    karuha.load_config()
    karuha.add_bot(bot)
    karuha.run()

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

KaruhaBot-0.1.0b2.tar.gz (22.1 kB view details)

Uploaded Source

Built Distribution

KaruhaBot-0.1.0b2-py3-none-any.whl (26.8 kB view details)

Uploaded Python 3

File details

Details for the file KaruhaBot-0.1.0b2.tar.gz.

File metadata

  • Download URL: KaruhaBot-0.1.0b2.tar.gz
  • Upload date:
  • Size: 22.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.9.18

File hashes

Hashes for KaruhaBot-0.1.0b2.tar.gz
Algorithm Hash digest
SHA256 bf046518acd75657882ce33430df5490a37ed673a20f3745bce59473d8e3acb7
MD5 b7a2c2a6728d36dfd3012a1ae9fb9b63
BLAKE2b-256 d7536c43fd462099a260f5fa08c75a03f33c578de0c6dc5a2479f76b74dbfc29

See more details on using hashes here.

File details

Details for the file KaruhaBot-0.1.0b2-py3-none-any.whl.

File metadata

  • Download URL: KaruhaBot-0.1.0b2-py3-none-any.whl
  • Upload date:
  • Size: 26.8 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.9.18

File hashes

Hashes for KaruhaBot-0.1.0b2-py3-none-any.whl
Algorithm Hash digest
SHA256 d0bfc9dc65f2a2687b67ccc61503b9961cde14e6d341e636a1c8c095273e3a31
MD5 d39d180b38a76bd9f07c8553e575a370
BLAKE2b-256 4cbe4261e56c230391cce5bfbb5aca018c914ce011531d36951d3a6b7de7c604

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page