Metadata-Version: 2.4
Name: octadezx
Version: 0.2.0
Summary: Server SDK for the OctaDezx public API and headless Agent API
Author-email: OctaDezx <kevin@octadezx.com>
License-Expression: MIT
Project-URL: Homepage, https://octadezx.com/developers
Project-URL: Platform, https://octadezx.com/
Project-URL: Documentation, https://octadezx.com/developers/server-sdks
Project-URL: API reference, https://octadezx.com/developers/api-reference
Project-URL: Agent API, https://octadezx.com/developers/agent-api
Project-URL: Messenger SDK, https://octadezx.com/developers/messenger-sdk
Project-URL: MCP Server, https://octadezx.com/ai-agent-mcp-server
Project-URL: Self-Filling CRM, https://octadezx.com/crm
Project-URL: AI Appointment Booking, https://octadezx.com/ai-appointment-scheduling
Project-URL: Pricing, https://octadezx.com/pricing
Keywords: octadezx,customer support,ai agent,chatbot,api,sdk
Classifier: Development Status :: 4 - Beta
Classifier: Intended Audience :: Developers
Classifier: Operating System :: OS Independent
Classifier: Programming Language :: Python :: 3
Classifier: Programming Language :: Python :: 3 :: Only
Classifier: Topic :: Communications :: Chat
Classifier: Topic :: Software Development :: Libraries :: Python Modules
Classifier: Typing :: Typed
Requires-Python: >=3.9
Description-Content-Type: text/markdown
License-File: LICENSE
Provides-Extra: test
Requires-Dist: pytest>=7; extra == "test"
Dynamic: license-file

# octadezx (Python SDK)

Official Python server SDK for the [OctaDezx AI Customer Support Platform](https://octadezx.com) public API and [headless Agent API](https://octadezx.com/developers/agent-api): synchronous and `asyncio` clients, Server-Sent Events (SSE) streaming, messenger identity verification (`user_hash`), signed webhook verification, and owner-approved action request verification (`verify_action_request`). Zero external dependencies (pure Python 3.9+ standard library).

## Installation

```bash
pip install octadezx
```

## Quick Links & Documentation

- **OctaDezx Platform Overview:** [https://octadezx.com](https://octadezx.com)
- **Developer Hub & OpenAPI 3.1 Spec:** [https://octadezx.com/developers](https://octadezx.com/developers)
- **Python & Node.js Server SDK Guide:** [https://octadezx.com/developers/server-sdks](https://octadezx.com/developers/server-sdks)
- **Headless Agent API & SSE Streaming:** [https://octadezx.com/developers/agent-api](https://octadezx.com/developers/agent-api)
- **REST API Reference:** [https://octadezx.com/developers/api-reference](https://octadezx.com/developers/api-reference)
- **Signed Webhooks Guide:** [https://octadezx.com/developers/webhooks](https://octadezx.com/developers/webhooks)
- **Identity Verification (`user_hash`):** [https://octadezx.com/developers/identity-verification](https://octadezx.com/developers/identity-verification)
- **Native MCP Server (`octadezx.com/mcp`):** [https://octadezx.com/ai-agent-mcp-server](https://octadezx.com/ai-agent-mcp-server)
- **Self-Filling AI CRM:** [https://octadezx.com/crm](https://octadezx.com/crm)
- **AI Appointment Booking Bot & Scheduling:** [https://octadezx.com/ai-appointment-scheduling](https://octadezx.com/ai-appointment-scheduling)
- **Pricing & 3-Day Free Trial:** [https://octadezx.com/pricing](https://octadezx.com/pricing)

## Features

- **Headless Agent API (`client.agent`)**: Start conversations, send customer turns, stream token-by-token replies over SSE, and inspect conversation history.
- **Deterministic Brand Safety**: Every written reply is checked by deterministic code against the business's verified knowledge graph before delivery.
- **Identity Verification**: Compute HMAC-SHA256 `user_hash` tokens on your server for authenticated users in `@octadezx/messenger` (Web / React) and `@octadezx/messenger-react-native`.
- **Webhook Verification**: Constant-time HMAC-SHA256 signature verification with replay protection over raw request bytes.
- **Action Verification**: `verify_action_request` checks the signature of an owner-approved action request and validates its body.

## Owner-approved actions

When the AI agent runs an action you registered (Dashboard > Settings > Actions), OctaDezx sends a signed `POST` to your endpoint. Verify it with `verify_action_request` before you do anything. It checks HMAC-SHA256 over `<timestamp>.<raw body>` with a five minute replay window (several comma-separated `sha256=` values are accepted during secret rotation), then parses and validates the body. Pass the exact raw bytes, not re-serialized JSON.

```python
import os
from octadezx import verify_action_request, ActionVerificationError

try:
    request = verify_action_request(raw_body, headers, os.environ["OCTADEZX_ACTION_SECRET"], allow_test=True)
except ActionVerificationError:
    ...  # respond 401
else:
    # Scope everything to request["user"]["id"]; request["args"] is untrusted customer input.
    if request["test"]:
        response = {"ok": True, "message": "Sample answer, nothing was changed"}
    else:
        ...  # do the work
        response = {"ok": True, "data": {}, "message": "Done"}
```

Answer with HTTP 2xx, `Content-Type: application/json` and a JSON object whose `ok` is exactly `True`. Anything else counts as a failure and the customer is told nothing was changed.

**The `allow_test` rule.** Dashboard "Send test" requests carry `"test": true`, with a user id and arguments a teammate typed. A test must never change anything. For a write action, `verify_action_request` raises `ActionVerificationError` on a test request unless you pass `allow_test=True`, so answering one is a deliberate choice: when you pass it, check `request["test"]` and return a sample answer without applying the change. Read actions are not blocked. See [Actions](https://octadezx.com/developers/actions).

## Running Tests

```bash
python -m unittest discover -s tests
```
