read_handle

View as MarkdownOpen in Claude

Return the conversation id inside a handle. The signature is verified first and the expiry second, both before the id is trusted for anything.

Parameters

handle
strRequired

A handle this gateway issued, as returned by mint_handle() or the X-Chat-Handle response header.

Returns

str — the conversation id.

Raises

GatewayRejection, carrying the status the browser should see:

400 malformed handle
GatewayRejection

The handle is not two base64url parts, or its payload does not decode.

403 invalid handle
GatewayRejection

The signature does not match, so this gateway did not issue it.

403 expired handle
GatewayRejection

The handle is past its handle_ttl.

An expired handle is normal rather than exceptional. Every long-lived conversation reaches it eventually, so treat it as “start a new conversation” instead of something to show the visitor.

Example

1from signalwire.ai_chat import ChatGateway, GatewayRejection
2
3gateway = ChatGateway(config_url="https://bayview-taxi.example.com/swml")
4
5
6def conversation_for(handle: str) -> str | None:
7 try:
8 return gateway.read_handle(handle)
9 except GatewayRejection as rejection:
10 if rejection.status == 403:
11 return None # expired or forged; start fresh
12 raise