# frejun-tech/teler-openai-sip-trunking architecture

> Architecture diagram of the GitHub repository frejun-tech/teler-openai-sip-trunking, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-09-26). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/frejun-tech/teler-openai-sip-trunking
- Repository: https://github.com/frejun-tech/teler-openai-sip-trunking

## Overview

This is a compact FastAPI reference integration for inbound Teler-to-OpenAI voice calls. A caller reaches OpenAI through Teler’s SIP trunk; OpenAI notifies the server, which verifies and deduplicates the webhook, acknowledges it, then accepts the call in a background task. The server configures a control WebSocket for greetings, transcription, and optional human transfer; call audio stays directly between Teler and OpenAI. Components are concentrated in main.py, so several nodes represent distinct responsibilities within that file.

Main entry points: [`main.py`](https://github.com/frejun-tech/teler-openai-sip-trunking/blob/master/main.py) (Control WebSocket)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_ingress["Webhook ingress"]
  node_webhook["Webhook endpoint<br/>[main.py]"]
  node_verification["Verify and dedupe<br/>[main.py]"]
  node_health["Health endpoint<br/>[main.py]"]
end

subgraph group_control["Call control"]
  node_call_handler["Call handler<br/>[main.py]"]
  node_accept["Accept call<br/>[main.py]"]
  node_settings["Agent settings<br/>[main.py]"]
end

subgraph group_session["Live session"]
  node_socket["Control WebSocket<br/>[main.py]"]
  node_session_config["Session setup<br/>[main.py]"]
  node_event_handling["Event handling<br/>[main.py]"]
  node_transfer["Human transfer<br/>[main.py]"]
end

node_caller(("Caller"))
node_teler["Teler SIP trunk"]
node_openai["OpenAI Realtime"]

node_caller -->|"dials"| node_teler
node_teler -->|"forwards SIP"| node_openai
node_teler -->|"carries audio"| node_openai
node_openai -->|"incoming event"| node_webhook
node_webhook -->|"verifies and dedupes"| node_verification
node_verification -->|"acknowledges"| node_openai
node_verification -->|"dispatches background"| node_call_handler
node_call_handler -->|"calls"| node_accept
node_accept -->|"reads"| node_settings
node_accept -->|"accepts call"| node_openai
node_call_handler -->|"opens after acceptance"| node_socket
node_socket -->|"sends session setup"| node_session_config
node_session_config -->|"reads"| node_settings
node_socket -->|"sends greeting and settings"| node_openai
node_openai -->|"streams events"| node_socket
node_socket -->|"dispatches events"| node_event_handling
node_event_handling -->|"dispatches tool call"| node_transfer
node_transfer -->|"requests REFER"| node_openai

click node_webhook "https://github.com/frejun-tech/teler-openai-sip-trunking/blob/master/main.py"
click node_verification "https://github.com/frejun-tech/teler-openai-sip-trunking/blob/master/main.py"
click node_call_handler "https://github.com/frejun-tech/teler-openai-sip-trunking/blob/master/main.py"
click node_accept "https://github.com/frejun-tech/teler-openai-sip-trunking/blob/master/main.py"
click node_settings "https://github.com/frejun-tech/teler-openai-sip-trunking/blob/master/main.py"
click node_socket "https://github.com/frejun-tech/teler-openai-sip-trunking/blob/master/main.py"
click node_session_config "https://github.com/frejun-tech/teler-openai-sip-trunking/blob/master/main.py"
click node_event_handling "https://github.com/frejun-tech/teler-openai-sip-trunking/blob/master/main.py"
click node_transfer "https://github.com/frejun-tech/teler-openai-sip-trunking/blob/master/main.py"
click node_health "https://github.com/frejun-tech/teler-openai-sip-trunking/blob/master/main.py"

classDef toneNeutral fill:#f8fafc,stroke:#334155,stroke-width:1.5px,color:#0f172a
classDef toneBlue fill:#dbeafe,stroke:#2563eb,stroke-width:1.5px,color:#172554
classDef toneAmber fill:#fef3c7,stroke:#d97706,stroke-width:1.5px,color:#78350f
classDef toneMint fill:#dcfce7,stroke:#16a34a,stroke-width:1.5px,color:#14532d
classDef toneRose fill:#ffe4e6,stroke:#e11d48,stroke-width:1.5px,color:#881337
classDef toneIndigo fill:#e0e7ff,stroke:#4f46e5,stroke-width:1.5px,color:#312e81
classDef toneTeal fill:#ccfbf1,stroke:#0f766e,stroke-width:1.5px,color:#134e4a
class node_webhook,node_verification,node_health toneBlue
class node_call_handler,node_accept,node_settings toneAmber
class node_socket,node_session_config,node_event_handling,node_transfer toneMint
class node_caller,node_teler,node_openai toneIndigo
```

## Components

### Webhook ingress

- [Webhook endpoint](https://github.com/frejun-tech/teler-openai-sip-trunking/blob/master/main.py): `main.py`
- [Verify and dedupe](https://github.com/frejun-tech/teler-openai-sip-trunking/blob/master/main.py): `main.py`
- [Health endpoint](https://github.com/frejun-tech/teler-openai-sip-trunking/blob/master/main.py): `main.py`

### Call control

- [Call handler](https://github.com/frejun-tech/teler-openai-sip-trunking/blob/master/main.py): `main.py`
- [Accept call](https://github.com/frejun-tech/teler-openai-sip-trunking/blob/master/main.py): `main.py`
- [Agent settings](https://github.com/frejun-tech/teler-openai-sip-trunking/blob/master/main.py): `main.py`

### Live session

- [Control WebSocket](https://github.com/frejun-tech/teler-openai-sip-trunking/blob/master/main.py): `main.py`
- [Session setup](https://github.com/frejun-tech/teler-openai-sip-trunking/blob/master/main.py): `main.py`
- [Event handling](https://github.com/frejun-tech/teler-openai-sip-trunking/blob/master/main.py): `main.py`
- [Human transfer](https://github.com/frejun-tech/teler-openai-sip-trunking/blob/master/main.py): `main.py`

### Other components

- **Caller**
- **Teler SIP trunk**
- **OpenAI Realtime**

## Connections

- Caller → Teler SIP trunk: dials
- Teler SIP trunk → OpenAI Realtime: forwards SIP
- Teler SIP trunk → OpenAI Realtime: carries audio
- OpenAI Realtime → Webhook endpoint: incoming event
- Webhook endpoint → Verify and dedupe: verifies and dedupes
- Verify and dedupe → OpenAI Realtime: acknowledges
- Verify and dedupe → Call handler: dispatches background
- Call handler → Accept call: calls
- Accept call → Agent settings: reads
- Accept call → OpenAI Realtime: accepts call
- Call handler → Control WebSocket: opens after acceptance
- Control WebSocket → Session setup: sends session setup
- Session setup → Agent settings: reads
- Control WebSocket → OpenAI Realtime: sends greeting and settings
- OpenAI Realtime → Control WebSocket: streams events
- Control WebSocket → Event handling: dispatches events
- Event handling → Human transfer: dispatches tool call
- Human transfer → OpenAI Realtime: requests REFER
