Copy-paste snippets for handling calls that arrive from the phone network. The one idea to hold onto: an inbound call is the same object as an outbound one. The SIP gateway answers the carrier for you and publishes the caller’s audio onto the very same tracks:
voice/<sid>/uplink     caller → cloud   (what the caller is saying)
voice/<sid>/downlink   cloud → caller   (what is played back)
So every primitive below — attach an agent, open an audio bridge, transfer, hangup — works on an inbound sid unchanged. For the full answer sequence and routing model, read Inbound calls. Each snippet assumes a Voice client:
import { Voice } from "@telequick/sdk/voice";

const v = new Voice({
  baseUrl: "https://engine.telequick.dev",
  apiKey:  process.env.TELEQUICK_CREDENTIALS!,
  orgId:   "org_abc",
});

Route a number to an AI agent

The common case: point a number (or trunk) at a server-side agent and you are done — the gateway answers, attaches the runtime, and wires both audio legs. Your process never touches the media. Set the trunk’s inbound rule to HANDLE_AI on a native core; for TypeScript apps, do this in the console at agent.telequick.dev instead.
from telequick.method_id import InboundRule

# `client` is the native-core control client, connected to your engine RPC endpoint.
await client.set_inbound_routing(
    trunk_id="trunk_main",
    rule=InboundRule.HANDLE_AI,
    ai_quic_url="agent://support-frontline",   # the agent to bridge to
)
set_inbound_routing is a low-level RPC on the native SDK cores (Python, Go, Rust). The browser/TypeScript SDK doesn’t carry it — configure inbound routing in the console (or your provisioning pipeline), then handle the resulting call with the high-level Voice client. See Build a voice agent.

Attach an agent to a live inbound call

Already have the sid (from a webhook or your event stream)? Bind an agent to it mid-call — e.g. after your own IVR gathers intent. The engine wires the bridge for you.
await v.agents.attach(sid, "billing-bot");
Turn-taking, barge-in, and tool calls are all handled server-side — tune them in Turn detection and Tool calling.

Route to a human or a skill queue

To send callers to people, point the number at a skill queue or an IVR program (VDN) instead of an agent — configuration, no media code. The gateway answers, runs your IVR steps, and the ACD picks the next eligible agent on a browser softphone or a real SIP deskphone.

PBX / ACD

Skills, VDNs, IVR vectors, and the agent picker behind human routing.

AI → human handoff

Answer with AI to qualify the caller, then warm-transfer to a person.

Bridge caller audio into your own code

When you want your own service to drive the call, set the inbound rule to NOTIFY_AND_HANGUP. The gateway tells your app about each incoming call, you answer it, then subscribe uplink (hear the caller) and publish downlink (talk back) through an audio bridge on that sid.
from telequick.method_id import InboundRule

await client.set_inbound_routing(
    trunk_id="trunk_main",
    rule=InboundRule.NOTIFY_AND_HANGUP,
    webhook_url="https://ops.example.com/hooks/inbound",
)

# When an incoming call arrives on your event stream:
async def on_call_event(ev):
    if ev.type == "CHANNEL_CREATE":
        await client.answer_incoming_call(ev.call_sid)  # accept the leg
        # From here, open an audio bridge on ev.call_sid and read/write frames.
The attach bridge is written from the server’s point of view: you subscribe uplink and publish downlink — the same handle an outbound call gives you. Configure a webhook_url to receive incoming-call events; see Webhooks.

Pick a codec to skip transcoding

For a PSTN-direct call, ask for G.711 and the bridge passes the caller’s audio through untranscoded. Ask for pcm16 when a realtime model wants raw audio.
// µ-law passthrough on a North-American PSTN leg — no transcode
const rec = await v.audioBridge.attach(sid, {
  codec: "g711_ulaw",
  onUplink: (frame, tsUs) => recorder.write(frame),
});

Play a greeting back to the caller

Push encoded frames onto downlink as your TTS produces them (see Speak back to the caller).
myTts.onChunk((frame) => bridge.publishDownlink(frame));

Transfer an inbound caller

The same sid continues across a transfer, so any recording or analytics keyed on it stay intact (see Transfer to a human).
const call = await v.calls.get({ sid });
await call.transfer({ to: "+15557654321" });   // forward to a PSTN number (SIP REFER)
// or re-attach the live audio to another agent in place:
await call.transfer({ agent: "senior-agent" });

Hang up and clean up

End the call, then release the bridge to tear down both tracks.
await call.hangup();
await bridge.close();
Keep the bridge reference alive for the call’s lifetime — letting it be garbage-collected drops both tracks. Always bridge.close() before call.hangup() so the tracks tear down cleanly.

Inbound calls

The full guide: how the gateway answers and where routing decisions live.

Stream to your ASR

Feed caller uplink into your own recognizer.

Place an outbound call

The mirror of this page — originate from code.

Audio bridge API

Full signatures for attach, publishDownlink, and onUplink.