Quickstart' fill-rule='evenodd'%3E %3Cpath d='M7.778 7.975a2.5 2.5 0 0 0 .347-3.837L6.017 2.03a2.498 2.498 0 0 0-3.542-.007 2.5 2.5 0 0 0 .006 3.543l1.153 1.15c.07-.29.154-.563.25-.773.036-.077.084-.16.14-.25L3.18 4.85a1.496 1.496 0 0 1 .002-2.12 1.496 1.496 0 0 1 2.12 0l2.124 2.123a1.496 1.496 0 0 1-.333 2.37c.16.246.42.504.685.752z'/%3E %3Cpath d='M5.657 4.557a2.5 2.5 0 0 0-.347 3.837l2.108 2.108a2.498 2.498 0 0 0 3.542.007 2.5 2.5 0 0 0-.006-3.543L9.802 5.815c-.07.29-.154.565-.25.774-.036.076-.084.16-.14.25l.842.84c.585.587.59 1.532 0 2.122-.587.585-1.532.59-2.12 0L6.008 7.68a1.496 1.496 0 0 1 .332-2.372c-.16-.245-.42-.503-.685-.75z'/%3E %3C/g%3E %3C/svg%3E)
In this guide, you’ll learn how to get started with Telnyx WebRTC using Telnyx Portal and API. Just follow these steps:
- 1Sign up for a Telnyx Account.
- 2Create a Credential Connection to configure how you connect your calls.
- 3Create an Outbound Voice Profile to configure your outbound call settings and assign it to your Credential Connection.
- 4Grab your API key
- 5Create a new On-demand Credential and generate a token
- 6Authenticate to Telnyx WebRTC platform and place a call
Sign Up for a Telnyx Mission Control Portal Account
Head to telnyx.com/sign-up to sign up for your free Telnyx account. It’ll give you access to our Mission Control Portal where you can buy phone numbers, set up and manage Call Control Applications, and more.
Create a Credential Connection for your Calls' fill-rule='evenodd'%3E %3Cpath d='M7.778 7.975a2.5 2.5 0 0 0 .347-3.837L6.017 2.03a2.498 2.498 0 0 0-3.542-.007 2.5 2.5 0 0 0 .006 3.543l1.153 1.15c.07-.29.154-.563.25-.773.036-.077.084-.16.14-.25L3.18 4.85a1.496 1.496 0 0 1 .002-2.12 1.496 1.496 0 0 1 2.12 0l2.124 2.123a1.496 1.496 0 0 1-.333 2.37c.16.246.42.504.685.752z'/%3E %3Cpath d='M5.657 4.557a2.5 2.5 0 0 0-.347 3.837l2.108 2.108a2.498 2.498 0 0 0 3.542.007 2.5 2.5 0 0 0-.006-3.543L9.802 5.815c-.07.29-.154.565-.25.774-.036.076-.084.16-.14.25l.842.84c.585.587.59 1.532 0 2.122-.587.585-1.532.59-2.12 0L6.008 7.68a1.496 1.496 0 0 1 .332-2.372c-.16-.245-.42-.503-.685-.75z'/%3E %3C/g%3E %3C/svg%3E)
A Credential Connection groups configuration for your calls, such as which codecs to use (tip: enable VP8 codec for video).
- 1Navigate to the SIP Connections page of the Mission Control Portal.
- 2Click the "+ Add SIP Connection" button near the top right corner of the page.
- 3Enter the name you wish to have for your SIP Connection.
- 4Select "Credentials" as the "Connection Type".
- 5A username and password will automatically be generated. You can ignore it for now.
- 6Click "Set Credentials".
- 7Click "Done".
Note - Credential Connections by default have the VP8 codec disabled. Edit the connection "Inbound" settings to enable it.
Create an Outbound Voice Profile
To be able to place calls, you must first create an Outbound Voice Profile and assign your Credential Connection to it.
Select "Outbound Voice Profiles" on the left-hand navigation menu, click "+Add New Profile" and set up your profile name. Add the Credential Connection you just created above and select your traffic type.
You can also do this programmatically via our RESTful API. Check out our documentation for Outbound Voice Profiles.
Grab your API Key
If you already have a Telnyx V2 API Authentication key, skip to Step 3.
- 1In the Telnyx Mission Control Portal
, in the left menu bar navigate to "Auth".
- 2Ensure, API V2 is selected in the horizontal menu bar.
- 3Click "Create API key"
- 4Copy the API key and save it somewhere safe.
Create On-demand Credential' fill-rule='evenodd'%3E %3Cpath d='M7.778 7.975a2.5 2.5 0 0 0 .347-3.837L6.017 2.03a2.498 2.498 0 0 0-3.542-.007 2.5 2.5 0 0 0 .006 3.543l1.153 1.15c.07-.29.154-.563.25-.773.036-.077.084-.16.14-.25L3.18 4.85a1.496 1.496 0 0 1 .002-2.12 1.496 1.496 0 0 1 2.12 0l2.124 2.123a1.496 1.496 0 0 1-.333 2.37c.16.246.42.504.685.752z'/%3E %3Cpath d='M5.657 4.557a2.5 2.5 0 0 0-.347 3.837l2.108 2.108a2.498 2.498 0 0 0 3.542.007 2.5 2.5 0 0 0-.006-3.543L9.802 5.815c-.07.29-.154.565-.25.774-.036.076-.084.16-.14.25l.842.84c.585.587.59 1.532 0 2.122-.587.585-1.532.59-2.12 0L6.008 7.68a1.496 1.496 0 0 1 .332-2.372c-.16-.245-.42-.503-.685-.75z'/%3E %3C/g%3E %3C/svg%3E)
Create the Credential
curl -X POST \
--header "Content-Type: application/json" \
--header "Authorization: Bearer YOUR_API_KEY" \
--data '{
"connection_id": "<your connection ID>"
}' \
https://api.telnyx.com/v2/telephony_credentials
Example Response
{
"data": {
"id": "68f28076-119e-440d-bb69-9a8d359857c2",
"name": "2020-08-05 13:42:22.991499Z",
"record_type": "credential",
"resource_id": "connection:1431843891430033126",
"sip_password": "570067b6e4d7495db417e150a81380d9",
"sip_username": "gencredbcXbCt2uEOaD6e2VN2Bs3b2HDlQVW2v3CJFTQ6Xes9",
"created_at": "2020-08-05T13:42:22.992Z",
"expires_at": null,
"updated_at": "2020-08-05T13:42:22.992Z",
"user_id": "14c31d6d-aa05-4598-bef8-5acd2197f0c1"
}
}
Notes:
- By default, on-demand credentials will not expire.
- The randomly generated
sip_username
will be used to receive SIP using <sip_username>@sip.telnyx.com as destination
Generate a token
curl -X POST \
--header "Content-Type: application/json" \
--header "Authorization: Bearer YOUR_API_KEY" \
--data '{}' \
https://api.telnyx.com/v2/telephony_credentials/<credential_id>/token
Example Response
eyJhbGciOiJIUzUxMiIsInR5cCI6IkpXVCJ9.eyJhdWQiOiJ0ZWxueXhfdGVsZXBob255IiwiZXhwIjoxNTk2NzIxMzg1LCJpYXQiOjE1OTY2MzQ5ODUsImlzcyI6InRlbG55eF90ZWxlcGhvbnkiLCJqdGkiOiJkYmNkZTkzNi04NjdmLTRjMzctYWI1ZS00MGYzY2Q3ODJjZGEiLCJuYmYiOjE1OTY2MzQ5ODQsInN1YiI6IjY4ZjI4MDc2LTExOWUtNDQwZC1iYjY5LTlhOGQzNTk4NTdjMiIsInRlbF90b2tlbiI6IlN4N0tPQU9DblcxUGxIcXVxSEdMT29mTVRiRHJtM1pJM3Bnb1dXX0hkNHNMbmVQUHZXZXh2WXpVQWFLY2pxQ0d2amhfbTQ0S3MwMXFpaEpOMXVMOG95d2Rxdm13ZUExTzZjRlR2UF9jT0J3Skp3bjdZYmJYV3diYW9RR3VabzFNazJIS2dVYjlxQndTVDJxSUZ6dzkwa29CIiwidHlwIjoiYWNjZXNzIn0.ogJujxfbCktNxZ5eeyslLzZylswNqZW4OwLKrkehlb6w-tpbgJ-Ywfgy4Eirmi_BaZ_ThPlgTua0G1jafqFGRw
Note:
- The response body is a JWT (JSON Web Token) that expires in 24h
- The token is associated with the Credential, and is rendered invalid if the credential expires or is deleted
Authenticate to WebRTC and place a call' fill-rule='evenodd'%3E %3Cpath d='M7.778 7.975a2.5 2.5 0 0 0 .347-3.837L6.017 2.03a2.498 2.498 0 0 0-3.542-.007 2.5 2.5 0 0 0 .006 3.543l1.153 1.15c.07-.29.154-.563.25-.773.036-.077.084-.16.14-.25L3.18 4.85a1.496 1.496 0 0 1 .002-2.12 1.496 1.496 0 0 1 2.12 0l2.124 2.123a1.496 1.496 0 0 1-.333 2.37c.16.246.42.504.685.752z'/%3E %3Cpath d='M5.657 4.557a2.5 2.5 0 0 0-.347 3.837l2.108 2.108a2.498 2.498 0 0 0 3.542.007 2.5 2.5 0 0 0-.006-3.543L9.802 5.815c-.07.29-.154.565-.25.774-.036.076-.084.16-.14.25l.842.84c.585.587.59 1.532 0 2.122-.587.585-1.532.59-2.12 0L6.008 7.68a1.496 1.496 0 0 1 .332-2.372c-.16-.245-.42-.503-.685-.75z'/%3E %3C/g%3E %3C/svg%3E)
Using Telnyx WebRTC test application
The Telnyx WebRTC test application is built using our Javascript WebRTC SDK, to showcase our WebRTC platform and make it easier to test your setup.
With the token generated above, you can register to WebRTC servers, providing a Caller ID Name and Caller ID Number:
When clicking on Connect
, a log message will be shown indicating the client has been registered. After this, you can place a test call to any number available in your Outbound Profile settings, or to a SIP destination.
Tips:
- If you create two different Credentials, you can open two browser instances and call one from the other
- If VP8 codec is enabled for both calling and called party a video call can be established
Follow-ups
Check out Telnyx WebRTC SDKs, available for both Javascript and React-Native: