Private Home Box — shared SDK and contract for channel plugins
Project description
hiro-channel-sdk
Shared SDK and contract for Hiro channel plugins.
Overview
Every channel plugin (Telegram, WhatsApp, mobile app, etc.) is a standalone Python
package that implements ChannelPlugin and communicates with the Hiro server over a local
WebSocket using JSON-RPC 2.0.
This package provides:
| Module | Purpose |
|---|---|
models.py |
UnifiedMessage, RpcRequest, RpcResponse, ChannelInfo |
base.py |
ChannelPlugin abstract base class |
rpc.py |
JSON-RPC 2.0 helpers (build / parse) |
transport.py |
PluginTransport — WS client that connects to the Hiro server |
Writing a channel plugin
from hiro_channel_sdk import ChannelPlugin, ChannelInfo, UnifiedMessage, PluginTransport
import asyncio
class MyChannel(ChannelPlugin):
@property
def info(self) -> ChannelInfo:
return ChannelInfo(name="mychannel", version="0.1.0")
async def on_configure(self, config):
self.api_key = config.get("api_key", "")
async def on_start(self):
# start polling / webhooks
asyncio.create_task(self._poll())
async def on_stop(self):
pass # cancel polling tasks here
async def send(self, message: UnifiedMessage) -> None:
# translate and send via third-party API
pass
async def _poll(self):
while True:
# receive message from third party...
msg = UnifiedMessage(
channel=self.info.name,
direction="inbound",
sender_id="user123",
body="Hello!",
)
await self.emit(msg)
await asyncio.sleep(1)
# Entry point
if __name__ == "__main__":
import typer
def main(hiro_ws: str = "ws://127.0.0.1:18081"):
plugin = MyChannel()
transport = PluginTransport(plugin, hiro_ws)
asyncio.run(transport.run())
typer.run(main)
JSON-RPC protocol
| Direction | Method | Params | Notes |
|---|---|---|---|
| plugin → Hiro | channel.register |
{name, version, description} |
First frame after connect |
| plugin → Hiro | channel.receive |
UnifiedMessage dict |
Inbound message from third party |
| plugin → Hiro | channel.event |
{event, data} |
Status, errors, receipts |
| Hiro → plugin | channel.send |
UnifiedMessage dict |
Send outbound message |
| Hiro → plugin | channel.configure |
{config: {...}} |
Push credentials |
| Hiro → plugin | channel.status |
— | Health probe |
| Hiro → plugin | channel.stop |
— | Graceful shutdown |
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
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file hiro_channel_sdk-0.1.0.tar.gz.
File metadata
- Download URL: hiro_channel_sdk-0.1.0.tar.gz
- Upload date:
- Size: 10.6 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: uv/0.10.6 {"installer":{"name":"uv","version":"0.10.6","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":null,"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
2a4fa63f257c7fec9a22492992b64da5861b26cc078a6923bd4a863b4ad3273c
|
|
| MD5 |
b0da1c26bf406a0e64e11f4e56931a5a
|
|
| BLAKE2b-256 |
2fdaea91623373d5659775c3164f54914ac2d42d4788c14c61ae6ab8c622aaba
|
File details
Details for the file hiro_channel_sdk-0.1.0-py3-none-any.whl.
File metadata
- Download URL: hiro_channel_sdk-0.1.0-py3-none-any.whl
- Upload date:
- Size: 12.0 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: uv/0.10.6 {"installer":{"name":"uv","version":"0.10.6","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":null,"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
6e2185ec52825626c35ddd6c8228f187c3c31e77d8e749abb42ad883d543c173
|
|
| MD5 |
95a6f9f16dc9e5d52d5321f0623a0743
|
|
| BLAKE2b-256 |
8af085c39abefc7953b17202bf88f80034c1bd2288718487e23fb901d74c234e
|