Twilio: Difference between revisions

From Wildsong
Jump to navigationJump to search
Brian Wilson (talk | contribs)
Brian Wilson (talk | contribs)
mNo edit summary
 
(18 intermediate revisions by the same user not shown)
Line 1: Line 1:
== Elastic Trunk + Asterisk ==
== Fun with Twilio ==


This is nothing to do with elephants or the back part of a sedan or rubber bands. It has nothing to do with the symbol above the "8" on your keyboard.
Implementing a [[Dispatch system for first responders]] using Twilio. Start of an idea.


Refer to https://www.twilio.com/docs/api/sip-trunking/sample-configuration
[[Caller ID processing]]
and https://www.twilio.com/resources/images/docs/Asterisk-Twilio.pdf


"Elastic" means you are not limited to a preset number of calls with one SIP account.
Stuff I want to try.
You can make any number of outbound and accept any number of inbound calls over the one account;
you just have to pay for the calls.


The price for a single phone number is $1 per month.
Twilio Client
The rate for calls is about a penny a minute.


Products -> Phone numbers
Voice transcription
You need one. Set it up.
Products -> Elastic SIP Trunking -> Trunks
First time through, "Create Sip Trunk"
Termination - set it up so you can make calls. You need something like "bellman.pstn.twilio.com" where you choose "bellman".
Origination - set it up so you can receive calls and attach a phone number to it. Try using your server like sip:bellman.wildsong.biz


You need to set up authentication on the termination settings for the trunk. The first time through you get prompted but you can edit it later
Watson Conversation service https://www.ibm.com/watson/developercloud/doc/conversation/index.html?cm_mmc=Email_Events-_-Developer_Productivity-_-WW_WW-_-Twilio+Followup+2+How+to&cm_mmca1=000019RT&cm_mmca2=10004803&cm_mmca3=M00009907&cvosrc=email.Events.M00009907&cvo_campaign=Developer_Productivity-WW_WW


Products -> Elastic SIP Trunking -> Authentication
Functions
IP Access Control Lists - Should have the IP addresses that your server uses for outbound traffic. 67.180.204.170
Credential lists - should have a username and password that you will put into your Asterisk set up.


You can have multiple IP addresses in one ACL, more than one ACL, and more than one credential set.
== Using Twilio services ==
That way you can use one Twilio account from more than one site if you want to.


=== Set up on Twilio account ===
=== Programmable Voice ===


# Go to http://twilio.com/
Geo-CEG - TwimlBin directs Geo-CEG calls to a SIP URI that goes into my Asterisk PBX via Elastic Trunk.
# Create an account if you don't have one
Asterisk rings the phones.
# Buy a phone number
# Attach the number to a trunk, the account comes with one trunk.


Access is controlled via IP address.
Wildsong - Call forwarding via TwiML bin is covered here:
You have to create an access control list for your Asterisk server and put its IP address into it.
[https://support.twilio.com/hc/en-us/articles/223179908-Setting-Up-Call-Forwarding Setting up call forwarding]
They also cover another service called Twilio Functions.


You have to set up URLs for both termination and origination.
Currently that's all I do, forward calls from Twilio to my mobile.


You have to set up a credential with a username and password.
=== Programmable SMS ===


=== Modifications to Asterisk ===
This is a very simple way to allow you to receive SMS messages on any Twilio number.
You just set it up to forward them to a mobile phone.


extensions.conf
Put this in a TwiML bin and connect messaging to it to forward SMS.


sip.conf
<?xml version="1.0" encoding="UTF-8"?>
<Response>
  <Message to="+1707yournumberhere">{{From}}: {{Body}}</Message>
</Response>


== SMS messages ==
=== Elastic Trunk + Asterisk ===


You can use the same number to send and receive SMS calls.
I ran this set up for about 5 years. See [[Asterisk]] for more info. Every few months something changed,
I tested it using the sample code by putting the PHP on my own server and then pointing the SMS URL at my server.
and I had to debug and fix it. Stuff like firewall issues and changing ip addresses. Twilio was fine,
It works. That's how I can receive SMS messages. I have not tried sending an SMS yet, except that the PHP code sends a reply back.
it was all stuff on my end.
 
The price for a single Twilio phone number is $1/month and another $1/month if you want 911 support.
The rate for calls (inbound or outbound) is less than a penny a minute.
 
== Twilio for Geo-CEG ==
 
Geo-CEG is a small non-profit. The board members live all over the place.  


I set up a script in my dev SSL server, sms.php.
I got a Twilio account through their program to support non-profits.  


=== HTTPS server set up ====
Currently I have a little IVR that just offers to send your call to either me or Christian (press '1' or '2')


To set up HTTPS,  I had to tighten up security on my Apache, test it here: https://ssllabs.com/ssltest I started with a "C" rating and moved up to "A"!
I want the number to be able to forward calls to whoever is "on call", and to store voice mails when no one is available.
How to: see https://hynek.me/articles/hardening-your-web-servers-ssl-ciphers/


See also https://wiki.mozilla.org/Security/Server_Side_TLS
== Programmable SMS ==


Complete your certificate chain: https://certificatechain.io/ and http://superuser.com/questions/644343/how-do-you-fix-an-incomplete-ssl-chain
You can use the same number to send and receive SMS calls.
I tested it using the sample code by putting the PHP on my own server and then pointing the SMS URL at my server.
It works. That's how I can receive SMS messages. I have not tried sending an SMS yet, except that the PHP code sends a reply back.


Goal - send text to server. Have the server phone back and read a message.
I set up a script in my dev SSL server, sms.php.


# Receive SMS - done
I have written a Python Flask app to play with SMS more, see http://github.com/brian32768/twilio-weatherman
# Log information about SMS
It uses both Programmable SMS and Programmable Voice.
# Initiate a call


Goal - build a system that will receive an SMS, perform an action, and send a confirmation.
== Programmable Voice ==


This can be (and he stopped typing there)
See the same app mentioned above, http://github.com/brian32768/twilio-weatherman


== Take aways from Signal Conference 2015 ==
== Take aways from Signal Conference 2015 ==


=== Move stuff into Asterisk ===
=== Move stuff into Asterisk ===
Lots of stuff in Twilio space could be implemented in Asterisk space
Lots of stuff in Twilio space could be implemented in Asterisk space. But here at the end of 2016 I am now working on going the other direction. I have Asterisk working just fine but am thinking of dumping it in favor of [[OpenVBX]].


ie TWIML could be used to design IVR / autoattendant systems in Asterisk.
My thought back then was that TWIML could be used to design IVR / autoattendant systems in Asterisk.
Doing this could make it easy to implement a failover, primary would be Asterisk
Doing this could make it easy to implement a failover, primary would be Asterisk
but if * is down then the same code would fire up and run in Twilio.
but if * is down then the same code would fire up and run in Twilio.
Line 96: Line 93:
I can buy one phone line for $1 a month.
I can buy one phone line for $1 a month.


=== What does it take to build a basic PBX in the cloud? ===
== Resources ==


# Set up SIP phone and provision it
=== Online resources ===
# Give the SIP phone an extension
# Allow VOIP extensions to call each other
# Set up a receptionist line
# Create an after hours autoattendant
# Voicemail
# Tracking usage of extensions at receptionist station


=== Now that I have a PBX, how can I extend it? ===
[https://www.twilio.com/docs/ Twilio docs] is of course the ultimate resource.


# SMS support
Twilio on Github
# WebRTC
# Text to Speech
# Speech to Text
# Presence detection
# Softphones
# Mobile softphones


== What can Asterisk do that Twilio CANT and vice versa ==
=== Books ===


'''Twilio Best Practices''', Tim Rogers, Packt Pubs 2014
Good book, but it's more than 10 minutes old. ;-) Twilio is changing fast.
Everything I looked at still applies, but Twilio adds new features all the time.


[[Category: VOIP]]
[[Category: Telephones]]
[[Category: Messaging]]

Latest revision as of 15:54, 31 August 2022

Fun with Twilio

Implementing a Dispatch system for first responders using Twilio. Start of an idea.

Caller ID processing

Stuff I want to try.

Twilio Client

Voice transcription

Watson Conversation service https://www.ibm.com/watson/developercloud/doc/conversation/index.html?cm_mmc=Email_Events-_-Developer_Productivity-_-WW_WW-_-Twilio+Followup+2+How+to&cm_mmca1=000019RT&cm_mmca2=10004803&cm_mmca3=M00009907&cvosrc=email.Events.M00009907&cvo_campaign=Developer_Productivity-WW_WW

Functions

Using Twilio services

Programmable Voice

Geo-CEG - TwimlBin directs Geo-CEG calls to a SIP URI that goes into my Asterisk PBX via Elastic Trunk. Asterisk rings the phones.

Wildsong - Call forwarding via TwiML bin is covered here: Setting up call forwarding They also cover another service called Twilio Functions.

Currently that's all I do, forward calls from Twilio to my mobile.

Programmable SMS

This is a very simple way to allow you to receive SMS messages on any Twilio number. You just set it up to forward them to a mobile phone.

Put this in a TwiML bin and connect messaging to it to forward SMS.

<?xml version="1.0" encoding="UTF-8"?>
<Response>
 <Message to="+1707yournumberhere">Template:From: Template:Body</Message>
</Response>

Elastic Trunk + Asterisk

I ran this set up for about 5 years. See Asterisk for more info. Every few months something changed, and I had to debug and fix it. Stuff like firewall issues and changing ip addresses. Twilio was fine, it was all stuff on my end.

The price for a single Twilio phone number is $1/month and another $1/month if you want 911 support. The rate for calls (inbound or outbound) is less than a penny a minute.

Twilio for Geo-CEG

Geo-CEG is a small non-profit. The board members live all over the place.

I got a Twilio account through their program to support non-profits.

Currently I have a little IVR that just offers to send your call to either me or Christian (press '1' or '2')

I want the number to be able to forward calls to whoever is "on call", and to store voice mails when no one is available.

Programmable SMS

You can use the same number to send and receive SMS calls. I tested it using the sample code by putting the PHP on my own server and then pointing the SMS URL at my server. It works. That's how I can receive SMS messages. I have not tried sending an SMS yet, except that the PHP code sends a reply back.

I set up a script in my dev SSL server, sms.php.

I have written a Python Flask app to play with SMS more, see http://github.com/brian32768/twilio-weatherman It uses both Programmable SMS and Programmable Voice.

Programmable Voice

See the same app mentioned above, http://github.com/brian32768/twilio-weatherman

Take aways from Signal Conference 2015

Move stuff into Asterisk

Lots of stuff in Twilio space could be implemented in Asterisk space. But here at the end of 2016 I am now working on going the other direction. I have Asterisk working just fine but am thinking of dumping it in favor of OpenVBX.

My thought back then was that TWIML could be used to design IVR / autoattendant systems in Asterisk. Doing this could make it easy to implement a failover, primary would be Asterisk but if * is down then the same code would fire up and run in Twilio.

What Twilio is doing

What Twilio is doing is building a big company by (1) doing only the back end, no applications. They provide only APIs and you write your own applications. (2) Using cloud. Everything they do lives in Amazon. Based on that there must be some backend to connect to carriers that does not require anything but IP. :-) That is, they don't have big server rooms full of HT503's

They have that big giant corporation mentality. But they do make their services available to little fleas like us. I can buy one phone line for $1 a month.

Resources

Online resources

Twilio docs is of course the ultimate resource.

Twilio on Github

Books

Twilio Best Practices, Tim Rogers, Packt Pubs 2014 Good book, but it's more than 10 minutes old. ;-) Twilio is changing fast. Everything I looked at still applies, but Twilio adds new features all the time.