Twilio, the Cloud… and Me!

Today, we’ll briefly detail how to setup a Twilio VoIP number in a way that it’ll allow us to:

– Receive SMS’s via Email
– Send SMS’s via CLI
– Receive Voice Calls via Landline, and if nobody picks up, fallback to Softphone
– Make Voice Calls via Softphone

Before we begin, you’ll need to:

1. Signup!
2. Register a Number!
3. Create a SIP Domain
4. Add a User under the SIP Domains > Credential Lists
5. Setup this “SMS to Email” PHP script”, in your favorite EC2 box

Once ready, let’s open the Developer Center, and opening the TwiML bins. Once there, add the following TwiML’s:

Name: Incoming Voice to Softphone:


<!--?xml version="1.0" encoding="UTF-8"?-->

USER@SIP-DOMAIN.sip.us1.twilio.com

Name: Incoming Voice to Landline:


<!--?xml version="1.0" encoding="UTF-8"?-->

Please, hold on the line while i put you through.

YOUR-LANDLINE-NUMBER

Name: Incoming SIP to Destination:


<!--?xml version="1.0" encoding="UTF-8"?-->

{{#e164}}{{To}}{{/e164}}

Name: Incoming SMS to Email:


<!--?xml version="1.0" encoding="UTF-8"?-->

URL-MAPPED-TO-YOUR-SEND-MAIL-SCRIPT

 

Once ready, open Phone Numbers > Manage Numbers > Active Numbers and map everything as follows:

A call comes in: Incoming voice to Landline TwiML
A message comes in: Incoming SMS to email Script’s URL

Finally, we need to map the “Incoming Voice to Softphone” TwiML, as follows:

– Open Programmable Voice
– Open SIP Domains and click over your domain
– Set the “Incoming Voice to Softphone” TwiML URL in the Voice Configuration > Request URL field

That should be it, pretty much. As per Soft Phones available for macOS, the most common one is X-Lite, which offers a free version (and it’s also available for iOS).

Hope that helps!

P.s.: With the following snippet, placed in you ~/.profile, you should be also able to send SMS’s via CLI:


function sms() {
curl -X POST 'https://api.twilio.com/2010-04-01/Accounts/ACCOUNT-KEY/Messages.json' \
--data-urlencode "To=${@:1:1}" \
--data-urlencode "From=YOUR-TWILIO-PHONE" \
--data-urlencode "Body=${@:2:1}" \
-u USER-KEY:USER-SECRET
}

Let’s Encrypt + Amazon AMI

Download certbot


$ wget https://dl.eff.org/certbot-auto
$ chmod a+x certbot-auto

Generate Certificates


sudo ./certbot-auto --debug -v --server https://acme-v01.api.letsencrypt.org/directory certonly -d YOUR_WEBSITE_HERE

Auto Renew Script:


sudo crontab -e
0 1,13 * * * /home/ec2-user/certbot-auto renew

Source Here

LLDB + Xcode 8 Kung Fu

Printing Arrays

parray  number pointer
poarray number pointer

Reading Method Parameters

register read $arg1 $arg2
memory read $arg1

Printing Objects in Swift

expr -O --language objc -- 0x1003183e0

Disassembling the current frame

disassemble --frame

Module Image

image list ModuleName

UIStackView inside UISScrollView

1. Disable tAMIC

scrollView.translatesAutoresizingMaskIntoConstraints = false
stackView.translatesAutoresizingMaskIntoConstraints = false

2. Pin the ScrollView

NSLayoutConstraint.activate([
  scrollView.leadingAnchor.constraint(equalTo: leadingAnchor),
  scrollView.trailingAnchor.constraint(equalTo: trailingAnchor),
  scrollView.topAnchor.constraint(equalTo: topAnchor),
  scrollView.bottomAnchor.constraint(equalTo: bottomAnchor)
  ])

3. Pin the StackView to the ScrollView corners. Include minimum width + padding:

let padding = CGFloat(10)
NSLayoutConstraint.activate([
  stackView.leadingAnchor.constraint(equalTo: scrollView.leadingAnchor, constant: padding),
  stackView.trailingAnchor.constraint(equalTo: scrollView.trailingAnchor, constant: -padding),
  stackView.topAnchor.constraint(equalTo: scrollView.topAnchor),
  stackView.bottomAnchor.constraint(equalTo: scrollView.bottomAnchor),
  stackView.heightAnchor.constraint(equalTo: scrollView.heightAnchor),
  stackView.widthAnchor.constraint(greaterThanOrEqualTo: scrollView.widthAnchor, constant: -2 * padding)
])