Skip to main content

bloonio_chat_relay_client

Python SDK for bloonio_chat_relay. Lets a tenant backend integrate the bloonio chat PaaS via the same tenant_id + tenant_secret model that bloonio_auth_relay_client uses for auth.

Install

pip install bloonio-chat-relay-client[fastapi]   # for FastAPI tenants
pip install bloonio-chat-relay-client[django]    # for Django tenants
pip install bloonio-chat-relay-client            # framework-agnostic core only

Two-minute integration (FastAPI)

# .env
BLOONIO_CHAT_BASE_URL=https://chat-relay.example.com
BLOONIO_CHAT_TENANT_ID=<uuid>
BLOONIO_CHAT_TENANT_SECRET=sk_...
BLOONIO_CHAT_CALLBACK_BASE_URL=https://your-backend.example.com
# main.py
from fastapi import FastAPI
from bloonio_chat_relay_client.adapters.fastapi import BloonioChatAdapter

app = FastAPI()
BloonioChatAdapter.from_env(app)   # mounts /api/v1/chat-callbacks/* + wires the client
# anywhere
from bloonio_chat_relay_client import get_chat_client

chat = get_chat_client()
convo = chat.create_conversation(
    visitor_user_id="user-123",
    visitor_display_name="Marie",
    locale="fr",
    metadata={"order_id": "ORD-9981"},
)
chat.send_message(convo.id, role="visitor", content="Where is my order?")

# For in-app SDKs (web/Flutter) — mint a short-lived signed token your
# client SDK uses to authenticate its WebSocket to chat-relay.
token = chat.mint_visitor_token(
    visitor_user_id="user-123",
    visitor_email_hash="sha256:...",
    ttl_seconds=3600,
)

Public surface

from bloonio_chat_relay_client import (
    ChatRelayClient,         # sync
    AsyncChatRelayClient,    # async
    ChatRelaySettings,
    ChatRelayError,
    # Domain types (Pydantic)
    Conversation,
    Message,
    Ticket,
    KnowledgeDocument,
    WebhookEvent,
    # Enums
    MessageRole,
    ConversationStatus,
    TicketStatus,
    TicketPriority,
    WebhookEventType,
)

Webhook callbacks

The adapter mounts nine HMAC#1-verified endpoints under /api/v1/chat-callbacks/*:

Path Event Phase
POST /api/v1/chat-callbacks/conversation-started New conversation opened 8
POST /api/v1/chat-callbacks/message-received Visitor sent a message 8
POST /api/v1/chat-callbacks/ticket-created Ticket auto-created via escalation 8
POST /api/v1/chat-callbacks/ticket-assigned Ticket claimed by a human agent 8
POST /api/v1/chat-callbacks/ticket-resolved Ticket marked resolved 8
POST /api/v1/chat-callbacks/escalation-triggered Bot escalated to human handoff 8
POST /api/v1/chat-callbacks/agent-assigned Operator claimed a conversation (visitor handoff in progress) 10a
POST /api/v1/chat-callbacks/agent-released Operator released the conversation back to inbox 10a
POST /api/v1/chat-callbacks/agent-resolved Operator marked the conversation resolved 10a

Provide handlers in BloonioChatAdapter.from_env(app, handlers={...}) to react to events on your side. Handlers are optional — events without a registered handler are accepted (HMAC#1 verified), logged at debug, and return {"received": True}.

Agent-takeover event payloads (phase 10a)

The three agent_* events share the same body shape:

{
  "conversation_id": "<chat_api ObjectId>",
  "tenant_id": "<UUID v7>",
  "status": "ASSIGNED" | "WAITING" | "RESOLVED",
  "operator_id": "<UUID v7>",
  "operator_display_name": "Sarah Chen",   // only on agent_assigned
  "visitor_session_id": "vs_<base64url>",
  "escalation_reason": "user_requested" | "restricted_topic" | "low_confidence" | "user_request" | "direct" | null,
  "claim_count": 1,
  "claimed_at":  "2026-05-22T12:34:56Z",
  "released_at": null,
  "resolved_at": null
}

Use these to update your CRM, send push notifications, or trigger analytics — apps_api's ChatIntegrationService.handle_agent_assigned(...) is the canonical reference handler (phase 10d).

Django

The same nine endpoints as Django urlpatterns — include them under the prefix you registered with the relay:

# urls.py
from django.urls import include, path
from bloonio_chat_relay_client import WebhookEventType
from bloonio_chat_relay_client.adapters.django import build_callback_urlpatterns

def on_message(ev):             # sync or async — both work
    ...

urlpatterns = [
    path(
        "api/v1/chat-callbacks/",
        include(build_callback_urlpatterns(handlers={WebhookEventType.MESSAGE_RECEIVED: on_message})),
    ),
]

settings=None reads BLOONIO_CHAT_* env vars. Semantics mirror the FastAPI router: 401 on missing/bad HMAC#1 headers, 400 on a bad payload or a body whose event_type doesn't match the path, handler exceptions logged but still 200. Outbound calls need no adapter — build ChatRelayClient(ChatRelaySettings()) anywhere.

Relationship to bloonio_auth_relay_client

This SDK is the chat analog of bloonio_auth_relay_client. The HMAC scheme is identical (header names, signature format, replay-protection window), so a backend that already integrates the auth SDK can reuse operator muscle memory. Only the domain types and the wrapped methods differ. See bloonio_chat_api/docs/12_PAAS_CONVERSION_PLAN.md §4.2 / §7.1.

License

Proprietary — Bloonio internal.

Download files

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

Source Distribution

bloonio_chat_relay_client-0.2.0.tar.gz (21.1 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

bloonio_chat_relay_client-0.2.0-py3-none-any.whl (22.3 kB view details)

Uploaded Python 3

File details

Details for the file bloonio_chat_relay_client-0.2.0.tar.gz.

File metadata

File hashes

Hashes for bloonio_chat_relay_client-0.2.0.tar.gz
Algorithm Hash digest
SHA256 14bc74f0757861c9355eaa88b8f5e81796ebd79d8a6df7763105274749fa5225
MD5 3e7f8b7a9d2a177552c0b1ef2ff71b3e
BLAKE2b-256 2283441c4a9295080b9410ace6ab0838aa68e421493b7d4bd8999e53d338fbee

See more details on using hashes here.

File details

Details for the file bloonio_chat_relay_client-0.2.0-py3-none-any.whl.

File metadata

File hashes

Hashes for bloonio_chat_relay_client-0.2.0-py3-none-any.whl
Algorithm Hash digest
SHA256 82fdbd5d8c9ead463e750cc6e6eb8768c2ee076e211aeb06ac230830b1d0fa67
MD5 afa44a968b7fbd4bbe0fbda3e1e38d33
BLAKE2b-256 43939ff5ebebf40410451989fcf993b842be2a2ffa7875bed5d013a5a1203188

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page