A python library for various chat services
Project description
bokkichat
master | develop |
---|---|
Bokkichat is a python library that offers unified interfaces for interacting with different chat services.
As an example, it could be used to write a bot for both Whatsapp and Telegram without many service-specific alterations.
A project that extends this idea is kudubot.
Implemented Connection Types
Currently the following connection types are supported out of the box:
- CLI
- Telegram (Bot)
Installation
Installing bokkichat is as simple as running pip install bokkichat
, or
python setup.py install
when installing from source.
Usage
First, you'll need to initialize the correct Settings object, which can then be used to initialize the Connection.
from bokkichat.settings.impl.TelegramBotSettings import TelegramBotSettings
from bokkichat.connection.impl.TelegramBotConnection import TelegramBotConnection
settings = TelegramBotSettings("APIKEY")
connection = TelegramBotConnection(settings)
Afterwards, you can send, receive and loop using the Connection object.
Some examples:
# Sending a message
from bokkichat.settings.impl.TelegramBotSettings import TelegramBotSettings
from bokkichat.connection.impl.TelegramBotConnection import TelegramBotConnection
from bokkichat.entities.message.TextMessage import TextMessage
from bokkichat.entities.Address import Address
settings = TelegramBotSettings("APIKEY")
connection = TelegramBotConnection(settings)
receiver = Address("12345678")
msg = TextMessage(connection.address, receiver, "BODY", "TITLE")
connection.send(msg)
# Echo every received message
from bokkichat.settings.impl.TelegramBotSettings import TelegramBotSettings
from bokkichat.connection.impl.TelegramBotConnection import TelegramBotConnection
from bokkichat.connection.Connection import Connection
from bokkichat.entities.message.Message import Message
settings = TelegramBotSettings("APIKEY")
connection = TelegramBotConnection(settings)
def echo(con: Connection, msg: Message):
reply = msg.make_reply()
con.send(reply)
connection.loop(echo)
Implementing your own connection type
If the connection type you want to use is not implemented by bokkichat itself, you can always implement it yourself. To do so, you will need to implement two classes.
First off, you'll need to implement a subclass of the Settings
class
and implement its abstract methods. Take a look at the implementation of
various Settings classes
here
for some inspiration.
The Settings class defines the authentication information required for the bot to function.
Afterwards, a subclass of the Connection
class must be implemented.
Again, implement the abstract methods and let yourself be inspired by
previous implementations
The Connection class defines how to communicate with the service itself.
These two classes define everything that's needed for a bokkichat connection.
Further Information
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
File details
Details for the file bokkichat-0.4.2.tar.gz
.
File metadata
- Download URL: bokkichat-0.4.2.tar.gz
- Upload date:
- Size: 9.4 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/1.13.0 pkginfo/1.5.0.1 requests/2.22.0 setuptools/41.2.0 requests-toolbelt/0.9.1 tqdm/4.35.0 CPython/3.6.8
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | c3f48745b58bee8c881e978b1e572321a79aac096256b9ffa41f218f7c575351 |
|
MD5 | c8b3e90f2ee21200ae2b8a5f892a68df |
|
BLAKE2b-256 | 95f814c806acf7ad71b26cb100d5ef7940d5d32587258aab199cc6558db74be1 |
File details
Details for the file bokkichat-0.4.2-py3-none-any.whl
.
File metadata
- Download URL: bokkichat-0.4.2-py3-none-any.whl
- Upload date:
- Size: 36.6 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/1.13.0 pkginfo/1.5.0.1 requests/2.22.0 setuptools/41.2.0 requests-toolbelt/0.9.1 tqdm/4.35.0 CPython/3.6.8
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 5e4c68799de5597371e20bd4673260b84c519224d42bdd9fc3a44dbb30a40059 |
|
MD5 | d0b34e1183bb58f717f08e03ede2d3ae |
|
BLAKE2b-256 | ed95d868f95219069a87c9467b8b3a7f4cd0943f748e40d319170c41f9864f7b |