We’ll use the code we wrote in the sms.cr file as the starting point for making phone calls so open that file and copy and paste the code from it into phone.cr .

Now we can make a few modifications so we’re making calls instead of sending messages.

First, make a simple JSON mapping for our call object.

Next, rename the function from send_sms to make_calls and change the last parameter from body to url . The url will need to point to an application that can handle incoming HTTP requests. When the call connects, Twilio will make a request, known as a webhook, to the url to find out what to do next. We’ll see how that is implemented later.

Change the post_form URL so that we’re calling the Calls resource.

Finally parse the response from Twilio into a Call object. Here’s the completed code: