Texa DeskDevelopers

Server

Python

pip install texa. A sync and an async client for the Texa API, the action handler and the webhook check.

Shell
pip install texa

Python 3.10+. The package is texa on PyPI.

Use it

Python
from texa import Client, webhooks

texa = Client()                                   # reads TEXA_API_KEY; or Client(key="texa_test_...")
convo = texa.open_conversation(channel="web", customer_ref="user-1842",
                               idempotency_key="open-user-1842")
out = texa.send_message(convo["conversation_id"], "Where is my transfer?",
                        message_id="msg-551")
events = texa.run_actions(convo["conversation_id"], out, {
    "get_transfer_status": lambda inputs: {"status": "paid_out"},
})
replies = [e["text"] for e in events if e["type"] == "reply"]

AsyncClient has the same methods, awaited; its action handlers may be async:

Python
from texa import AsyncClient

texa = AsyncClient()
convo = await texa.open_conversation(channel="web", customer_ref="user-1842")
...
await texa.aclose()                               # when your app shuts down

Webhooks

Python
# in your webhook endpoint, with the raw body (FastAPI shown)
@app.post("/texa/webhooks")
async def texa_webhook(request: Request):
    event = webhooks.parse(WEBHOOK_SECRET, request.headers, await request.body())
    ...                                           # raises if the signature is wrong or old

Widget sessions

Python
@app.post("/texa/session")
def texa_session(user = Depends(signed_in_or_401)):
    return texa.widget_session(f"user-{user.id}", first_name=user.first_name,
                               name=user.full_name, email=user.email)

Errors

A failed request raises texa.TexaError, with status, type, code, message, field and request_id (quote it to support), and retry_after on a 429. See errors.

Methods

me, usage, widget_session, open_conversation, list_conversations, get_conversation, send_message, action_result, human_message, handover, handback, close, assist, voice_session, transcript, export, quality, get_customer, merge_customer, forget_customer, upload_media, get_media, media_content, get_agent, get_kill_switch, list_actions, get_action, list_documents, add_document, events, events_page, support_report, quality_report, put_fixture, list_fixtures, delete_fixture, run_actions. Each matches a route in the reference.