Is there a way to query registrations to SIP domain with the API or a serverless function? - twilio

Is there a way to query the current or recent registrations to a SIP domain with the API, or from within a serverless function?
I can do this in the console with voice - manage - SIP domains - registered SIP endpoints. I would like to be able to do this programmatically.

Yes, that's possible with the following snippet:
// Download the helper library from https://www.twilio.com/docs/node/install
// Find your Account SID and Auth Token at twilio.com/console
// and set the environment variables. See http://twil.io/secure
const accountSid = process.env.TWILIO_ACCOUNT_SID;
const authToken = process.env.TWILIO_AUTH_TOKEN;
const client = require('twilio')(accountSid, authToken);
client.sip.domains.list({limit: 20})
.then(domains => domains.forEach(d => console.log(d.sid)));
You can find other languages in the documentation.

No, it is not possible to use the REST API to determine if there is a specific SIP endpoint that is currently connected to a SIP domain. I had the same question and Twilio technical support said this is only available from within the console. The code provided by #IObert will list the SIP domains (i.e. xxxx.sip.twilio.com), not an active SIP endpoint (i.e. +15555555555#xxxx.sip.twilio.com)

Related

Twilio Client identification for App to App Voip call

I am implementing an app to app voice call using Twilio VoIP.
Going through the documentation, I am able to make calls between phone numbers using Twilio.
To make calls between two devices without using phone numbers, Twilio document suggested to use the client identifier.
How to create the client identifier ? Does Twilio stores the client identifier ?
I tried calls between two phone numbers via Twiliio. Next, I am trying make app to app call using Twilio but I am not clear how Twilio identifies the two devices/clients
To create a client identifier, you need an Access Token. For example, to create an Access Token for the Voice SDK in Python:
import os
from twilio.jwt.access_token import AccessToken
from twilio.jwt.access_token.grants import VoiceGrant
# required for all twilio access tokens
# To set up environmental variables, see http://twil.io/secure
account_sid = os.environ['TWILIO_ACCOUNT_SID']
api_key = os.environ['TWILIO_API_KEY']
api_secret = os.environ['TWILIO_API_KEY_SECRET']
# required for Voice grant
outgoing_application_sid = 'APxxxxxxxxxxxxx'
identity = 'user'
# Create access token with credentials
token = AccessToken(account_sid, api_key, api_secret, identity=identity)
# Create a Voice grant and add to token
voice_grant = VoiceGrant(
outgoing_application_sid=outgoing_application_sid,
incoming_allow=True, # Optional: add to allow incoming calls
)
token.add_grant(voice_grant)
# Return token info as JSON
print(token.to_jwt())
In this example, the identity will be associated to the Access Token.
Then, when you make the Voice call, the To or From parameter should be in the form client:name_of_identity.

Twilio sip call is not working from tryit.jssip.net

I am using Twilio to make sip outgoing calls. I have created a sip domain, registered credential lists. Then i registered in Zoiper using the sip credentials and made an outbound call. It was working successfully.
Similarly i tried using tryit.jssip.net. But there it was asking for a WebSocket uri. What is that WebSocket uri for twilio ?
Is there something to do more in twilio to register sip endpoint in tryit.jssip.net
Sharing the screenshots here.
This is the jssip configuration. I entered sip uri and password. Websocket url is by default wss://tryit.jssip.net:10443. I didn't change it.
Then it got registered and i tried calling from that number. At that time the call got failed with a message Incompatible UDP
Twilio developer evangelist here.
Twilio doesn't publicly support SIP over websockets which JSSIP is asking for here. That is why you can't find the websocket URL to use.
If you are looking to use Twilio from a web browser, I suggest you take a look at Twilio Client.

Trigger text message based on external webhook

Can I trigger a Twilio SMS from a webhook generated externally? In the documentation, I see most of the language about sending a SMS when a call comes in to a Twilio number but my question is related to triggering a Twilio event from an external event like a document upload in a cloud storage system.
Yes, absolutely!
Whenever you receive the webhook (from any service you use) on your server, you just need to use Twilio's REST api to send the sms. In the docs you can find several examples.
For example, let's say that you set up your cloud storage system with a webhook to invoke https://my-super-cool-domain.com/webhooks/document-uploaded. This url will be handled by some code in the language that you choose, i.e. asp.net mvc (c#). You could have the following code in the action that handles that url:
// Find your Account Sid and Token at twilio.com/console
const string accountSid = "ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX";
const string authToken = "your_auth_token";
TwilioClient.Init(accountSid, authToken);
var message = MessageResource.Create(
body: "A new document has been uploaded to your cloud storage",
from: new Twilio.Types.PhoneNumber("your_twilio_phone"),
to: new Twilio.Types.PhoneNumber("recipient_phone")
);
Note: This uses .net client library, there are libraries for a bunch of languages, and if there isn't in the language that you use, you could just do the http requests, after all, it's a REST api.

Twilio SIP Trunking and Sip Domain

I am currently using Twilio for my cloud communication platform. A client of ours wants to SIP over to us, with headers, so we can continue the call on our end using Twiml.
I have tried setting up a SIP Domain and it works if I use a soft phone for an end point, but this isn't what I am trying to accomplish. I have also tried setting up a SIP Elastic Trunk and have that trunk connect to our SIP domain which in return call the Voice URL on the SIP domain.
I currently have setup a simple application to test this process. I have a Twilio number that calls a webhook, in the webhook (my app) I call the sip to the Twilio SIP trunk, but it fails. I am expecting to call the SIP domain and the Voice URL. I keep getting the error that the You tried to Dial a SIP Endpoint that is not currently registered with the corresponding SIP Domain. Please check your TwiML or REST API. (reference: TWilio Error Documentation.
Can anyone help me with this, please? I am currently using Twiml with PHP.
-- Update --
I am also following this documentation to a tee. I have a SIP Domain setup in my Twilio account, but it is requiring a registered user at an endpoint. In this documentation, it says when a sip call comes into the sip domain it will call the webhook, which it is not doing. Twilio SIP Domains
Twilio developer evangelist here.
I believe you're right to be confused about the SIP domain documentation. But the error message clears it up when it says:
Make sure the username matches a username in the Credential List used to authenticate the SIP Endpoint with the SIP Domain.
So your username does need to be an existing one, the SIP domain is not acting as a wildcard catch all for SIP addresses.
I will work to make sure the documentation is clearer.
Given that you are already receiving a webhook from an incoming call, why are you trying to get a second webhook from the SIP request? Could you not use the first webhook to direct the call the way you need?
In general, if you try to call a SIP endpoint via a SIP server/proxy, that SIP server/proxy needs to know how to reach that endpoint (routing). From the error text I derive that that isn't possible at the moment. Also, sometimes SIP servers only allow outbound calls from registered endpoints.
There are a number of things you can do:
Bypass the SIP server and call the endpoint directly (probably not what you want)
Configure a static path in the SIP server to the endpoint
Have the endpoint(s) register at the SIP server, so the SIP server knows who calls and how to reach the target.
Have you tried the possible solutions in the Error documentation?
Make sure the username (in the Request-URI) matches a username in the Credential List used to authenticate the SIP Endpoint with the SIP Domain
Prior to dialing, you can verify that your SIP Endpoint has successfully registered in the Console "Registered SIP Endpoints" tab found on the SIP Domains page.

Does Kamailio provide API for other program to creating sip account

I am developing a IOS VoIP app using SIP protocol stack. I am going to use Kamailio as the sip server.
But a sip address (sip account) is required for each VoIP client to make a VoIP call, which means I should manually register a sip account and configure it with the client. Now I want to make this easier. What I want to do is that when the user register to my user account server using the App, My user account server can call some API (maybe provided by Kamailio) to create a sip account associate with this user, and pass it back to the client, the client then configures itself using this sip account automatically.
However, I does not find any API from Kamailio to do such a thing.
does Kamailio provides such API, or other open source sip server allow me to do so?
I google that Kamailio can add a user using 'kamctl add' command, can I call similar function from my user account server using RPC. if so, which RPC function of Kamailio can I call? Thanks in advance!
If you use auth_db for user authentication with mysql backend (db_mysql module), like in default configuration file for kamailio, then the simplest way is to connect to kamailio database and add records to subscriber table.
Here is an example of adding user '101#test.com' with password 'test123' using the realm for authentication 'test.com' (realm is the same as domain):
INSERT INTO subscriber (username, domain, password, ha1, ha1b) VALUES
'101', 'test.com', 'test123',
MD5('101:test.com:test123'), MD5('101#test.com:test.com:test123')
);
The special values here are for ha1 and ha1b columns, which have to be:
ha1 = md5(username:realm:password)
ha1b = md5(username#domain:realm:password)
You can setup kamailio to use ANY sql query from ANY db.
Also you can use http auth, any other auth you can implement.
See
http://kamailio.org/docs/modules/stable/modules/auth_db.html
http://kamailio.org/docs/modules/stable/modules/avpops.html

Resources