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.

Phone numbers

Provisioning numbers also creates their inbound and outbound gateways. For a full walkthrough of acquiring and configuring numbers, see Handling Inbound Calls.

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

Phone numbers also support list, get, detach, updateGateway, and release.

Routing rules

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

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

Routing rules also support list, get, update, and delete.

Calls

Place, transfer, switch rooms, and end calls. For managing live calls in depth, see Handling 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);

Calls also support list and get.

Trunks

A trunk is a SIP connection: inbound receives calls for a set of numbers, and outbound places calls to a SIP host. Each sub-resource has full create, list, get, update, and delete.

For end-to-end setup, see Handling Inbound Calls and Making Outbound Calls.

const inbound = await client.sip.trunks.inbound.create({
name: "Support inbound",
numbers: ["+14155550100"],
});

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

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

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"],
});

Webhooks also support list, get, update, and delete.

The call object

Returned by sip.calls.create, get, list, transfer, switchRoom, and end.

FieldTypeDescription
idstringUnique call id.
typestringDirection (inbound or outbound).
statusstringCall lifecycle status (ringing, answered, ended, …).
fromstringSource number.
tostringDestination number.
roomIdstringDestination room id.
sessionIdstringAssociated session id.
startstringCall start time (ISO-8601).
endstringCall end time, null while ongoing.

The trunk object

Returned by the sip.trunks.inbound.* and sip.trunks.outbound.* methods. address and transport are set for outbound trunks only.

FieldTypeDescription
idstringUnique trunk id.
namestringDisplay name.
numbersstring[]E.164 numbers handled by this trunk.
addressstringSIP host (outbound only), e.g. sip.telnyx.com:5061.
transportstringSIP transport (udp, tcp, tls), outbound only.
mediaEncryptionstringMedia encryption setting.
recordbooleanWhether calls on this trunk are recorded.
geoRegionstringSIP region (auto, us002, in002, …).

The routing rule object

Returned by sip.routingRules.create, list, get, and update.

FieldTypeDescription
idstringUnique rule id.
namestringDisplay name.
typestringDirection (inbound or outbound).
numbersstring[]Provisioned numbers bound to this rule.
roomobjectDestination room config (type, prefix, id, pin).
agentIdstringDispatched agent id, if the rule targets an agent.
recordingbooleanWhether matching calls are recorded.
createdAtstringCreation timestamp (ISO-8601).

The phone number object

sip.phoneNumbers.list and get return the number wrapped with its inbound and outbound trunks (each a trunk object, or null). The number itself carries:

FieldTypeDescription
phoneNumberIdstringUnique number id (pass to release).
e164stringThe number in E.164 format.
countryCodestringCountry code.
providerstringUnderlying telephony provider.
statusstringProvisioning status.
namestringDisplay name.

The webhook object

Returned by sip.webhooks.create, list, get, and update.

FieldTypeDescription
idstringUnique webhook id.
urlstringDelivery endpoint URL.
eventsstring[]Subscribed events (call-started, call-answered, call-hangup, …).
createdAtstringCreation timestamp (ISO-8601).
updatedAtstringLast update timestamp (ISO-8601).

Got a Question? Ask us on discord