Skip to main content

SIP

The sip resource connects phone and SIP calls to rooms. For inbound, provision numbers and bind them to a room with a routing rule. For outbound, place a call through a routing rule or gateway.

Sub-resources: phoneNumbers, routingRules, calls, trunks, inboundGateways, outboundGateways, webhooks.

Phone numbers

Provisioning numbers also creates their inbound and outbound gateways.

await client.sip.phoneNumbers.create({
name: "Support line",
phoneNumbers: ["+14155550100"],
inbound: { sipRegion: "us002" },
outbound: { address: "sip.telnyx.com:5061", sipRegion: "us002" },
});

Also list, get, detach, updateGateway, release.

Routing rules

Bind provisioned numbers to a destination room. rule is either a fixed room (direct) or a fresh room per call (individual).

await client.sip.routingRules.create({
name: "inbound → support",
type: "inbound",
phoneNumbers: ["+14155550100"],
rule: { type: "direct", roomId: "support-line" },
});

Also list, get, update, delete.

Calls

const call = await client.sip.calls.create({
routingRuleId: "rr_1",
callTo: "+14155550123",
callFrom: "+14155550100",
});

await client.sip.calls.transfer(call.id, { to: "+14155550199" });
await client.sip.calls.switchRoom(call.id, { roomId: "escalation" });
await client.sip.calls.end(call.id);

Also list and get.

Trunks and gateways

A trunk is a single directional gateway.

const outbound = await client.sip.trunks.createOutbound({
address: "sip.telnyx.com",
numbers: ["+14155550100"],
});

await client.sip.trunks.list();
await client.sip.trunks.delete(outbound);

For full control, inboundGateways and outboundGateways each expose create, list, get, update, and delete.

Webhooks

Subscribe to call-lifecycle events (call-started, call-answered, call-hangup, and more).

await client.sip.webhooks.create({
url: "https://example.com/hook",
events: ["call-started", "call-hangup"],
});

Also list, get, update, delete.

Got a Question? Ask us on discord