In this quickstart, you'll build your first application to programmatically send and receive text messages with Twilio Programmable Messaging. This quickstart uses the Programmable Messaging REST API, the Twilio helper libraries, and the Twilio Virtual Phone.
For a no-code quickstart, see No-code programmable messaging quickstart with Twilio Studio.
Select your programming language and complete the prerequisites:
PythonNode.jsPHPC# (.NET Framework)C# (.NET Core)JavaGoRubyThe Twilio Virtual Phone lets you try Twilio quickly regardless of your country's regulations for messaging mobile handsets. To message a mobile handset, see Send SMS and MMS messages.
Follow these steps to send an SMS message from your Twilio phone number.
PythonNode.jsPHPC# (.NET Framework)C# (.NET Core)JavaGoRubyCreate and open a new file called send_sms.py
anywhere on your machine and paste in the following code:
1# Download the helper library from https://www.twilio.com/docs/python/install
3from twilio.rest import Client
5# Find your Account SID and Auth Token at twilio.com/console
6# and set the environment variables. See http://twil.io/secure
7account_sid = os.environ["TWILIO_ACCOUNT_SID"]
8auth_token = os.environ["TWILIO_AUTH_TOKEN"]
9client = Client(account_sid, auth_token)
11message = client.messages.create(
12body="Join Earth's mightiest heroes. Like Kevin Bacon.",
In the send_sms.py
file, replace the values for account_sid
and auth_token
with your Account SID and Auth Token surrounded by quotation marks.
(error)
Don't include credentials in production appsThis quickstart hardcodes your credentials for faster setup. To keep credentials secret and control access when you deploy to production, use environment variables and API keys.
Replace the value for from
with the phone number that Twilio gave you in E.164 format.
Replace the value for to
with the Twilio Virtual Phone number (+18777804236
).
Save your changes and run this command from your terminal in the directory that contains send_sms.py
:
After a few moments, you receive an SMS from your Twilio number on the Twilio Virtual Phone.
Create and open a new file called send_sms.js
anywhere on your machine and paste in the following code:
1// Download the helper library from https://www.twilio.com/docs/node/install
2const twilio = require("twilio"); // Or, for ESM: import twilio from "twilio";
4// Find your Account SID and Auth Token at twilio.com/console
5// and set the environment variables. See http://twil.io/secure
6const accountSid = process.env.TWILIO_ACCOUNT_SID;
7const authToken = process.env.TWILIO_AUTH_TOKEN;
8const client = twilio(accountSid, authToken);
10async function createMessage() {
11const message = await client.messages.create({
12body: "This is the ship that made the Kessel Run in fourteen parsecs?",
17console.log(message.body);
In the send_sms.js
file, replace the values for accountSid
and authToken
with your Account SID and Auth Token surrounded by quotation marks.
(error)
Don't include credentials in production appsThis quickstart hardcodes your credentials for faster setup. To keep credentials secret and control access when you deploy to production, use environment variables and API keys.
Replace the value for from
with the phone number that Twilio gave you in E.164 format.
Replace the value for to
with the Twilio Virtual Phone number (+18777804236
).
Save your changes and run this command from your terminal in the directory that contains send_sms.js
:
After a few moments, you receive an SMS from your Twilio number on the Twilio Virtual Phone.
Create and open a new file called send_sms.php
in the project directory and paste in the following code:
3// Update the path below to your autoload.php,
4// see https://getcomposer.org/doc/01-basic-usage.md
5require_once "/path/to/vendor/autoload.php";
9// Find your Account SID and Auth Token at twilio.com/console
10// and set the environment variables. See http://twil.io/secure
11$sid = getenv("TWILIO_ACCOUNT_SID");
12$token = getenv("TWILIO_AUTH_TOKEN");
13$twilio = new Client($sid, $token);
15$message = $twilio->messages->create(
19"This is the ship that made the Kessel Run in fourteen parsecs?",
20"from" => "+15017122661",
In the send_sms.php
file, replace the values for $sid
and $token
with your Account SID and Auth Token surrounded by quotation marks.
(error)
Don't include credentials in production appsThis quickstart hardcodes your credentials for faster setup. To keep credentials secret and control access when you deploy to production, use environment variables and API keys.
Replace the value for from
with the phone number that Twilio gave you in E.164 format.
Replace the value for To
with the Twilio Virtual Phone number (+18777804236
).
Update line 5 of send_sms.php
to require __DIR__ . '/vendor/autoload.php';
Save your changes and run this command from your terminal in the directory that contains send_sms.php
:
After a few moments, you receive an SMS from your Twilio number on the Twilio Virtual Phone.
Create and set up a new project in Visual Studio:
Open the file in your new Visual Studio project called Program.cs
and paste in the following code, replacing the existing template code:
1// Install the C# / .NET helper library from twilio.com/docs/csharp/install
5using Twilio.Rest.Api.V2010.Account;
6using System.Threading.Tasks;
9public static async Task Main(string[] args) {
10// Find your Account SID and Auth Token at twilio.com/console
11// and set the environment variables. See http://twil.io/secure
12string accountSid = Environment.GetEnvironmentVariable("TWILIO_ACCOUNT_SID");
13string authToken = Environment.GetEnvironmentVariable("TWILIO_AUTH_TOKEN");
15TwilioClient.Init(accountSid, authToken);
17var message = await MessageResource.CreateAsync(
18body: "Join Earth's mightiest heroes. Like Kevin Bacon.",
19from: new Twilio.Types.PhoneNumber("+15017122661"),
20to: new Twilio.Types.PhoneNumber("+15558675310"));
22Console.WriteLine(message.Body);
In the Program.cs
file, replace the values for accountSid
and authToken
with your Account SID and Auth Token surrounded by quotation marks.
(error)
Don't include credentials in production appsThis quickstart hardcodes your credentials for faster setup. To keep credentials secret and control access when you deploy to production, use environment variables and API keys.
Replace the value for from: new Twilio.Types.PhoneNumber
with the phone number that Twilio gave you in E.164 format.
Replace the value for to: new Twilio.Types.PhoneNumber
with the Twilio Virtual Phone number (+18777804236
).
Save your changes and run your project in Visual Studio.
After a few moments, you receive an SMS from your Twilio number on the Twilio Virtual Phone.
Run the following commands to create a new .NET project and install the Twilio NuGet package:
4dotnet add package Twilio
Open the file in your new project called Program.cs
and paste in the following code, replacing the existing template code:
1// Install the C# / .NET helper library from twilio.com/docs/csharp/install
5using Twilio.Rest.Api.V2010.Account;
6using System.Threading.Tasks;
9public static async Task Main(string[] args) {
10// Find your Account SID and Auth Token at twilio.com/console
11// and set the environment variables. See http://twil.io/secure
12string accountSid = Environment.GetEnvironmentVariable("TWILIO_ACCOUNT_SID");
13string authToken = Environment.GetEnvironmentVariable("TWILIO_AUTH_TOKEN");
15TwilioClient.Init(accountSid, authToken);
17var message = await MessageResource.CreateAsync(
18body: "Join Earth's mightiest heroes. Like Kevin Bacon.",
19from: new Twilio.Types.PhoneNumber("+15017122661"),
20to: new Twilio.Types.PhoneNumber("+15558675310"));
22Console.WriteLine(message.Body);
In the Program.cs
file, replace the values for accountSid
and authToken
with your Account SID and Auth Token surrounded by quotation marks.
(error)
Don't include credentials in production appsThis quickstart hardcodes your credentials for faster setup. To keep credentials secret and control access when you deploy to production, use environment variables and API keys.
Replace the value for from: new Twilio.Types.PhoneNumber
with the phone number that Twilio gave you in E.164 format.
Replace the value for to: new Twilio.Types.PhoneNumber
with the Twilio Virtual Phone number (+18777804236
).
Save your changes and run this command in the directory that contains Program.cs
:
After a few moments, you receive an SMS from your Twilio number on the Twilio Virtual Phone.
Create and open a new file called Example.java
in the same directory as the fat jar file and paste in the following code:
1// Install the Java helper library from twilio.com/docs/java/install
3import com.twilio.type.PhoneNumber;
4import com.twilio.Twilio;
5import com.twilio.rest.api.v2010.account.Message;
8// Find your Account SID and Auth Token at twilio.com/console
9// and set the environment variables. See http://twil.io/secure
10public static final String ACCOUNT_SID = System.getenv("TWILIO_ACCOUNT_SID");
11public static final String AUTH_TOKEN = System.getenv("TWILIO_AUTH_TOKEN");
13public static void main(String[] args) {
14Twilio.init(ACCOUNT_SID, AUTH_TOKEN);
15Message message = Message
16.creator(new com.twilio.type.PhoneNumber("+15558675310"),
17new com.twilio.type.PhoneNumber("+15017122661"),
18"This is the ship that made the Kessel Run in fourteen parsecs?")
21System.out.println(message.getBody());
In the Example.java
file, replace the values for ACCOUNT_SID
and AUTH_TOKEN
with your Account SID and Auth Token surrounded by quotation marks.
(error)
Don't include credentials in production appsThis quickstart hardcodes your credentials for faster setup. To keep credentials secret and control access when you deploy to production, use environment variables and API keys.
Replace the value for the first phone number with the Twilio Virtual Phone number (+18777804236
).
Replace the value for the second phone number with the phone number that Twilio gave you in E.164 format.
Save your changes and compile the Java from your terminal in the directory that contains Example.java
. Replace 10.9.0
with the version of your fat jar file.
javac -cp twilio-10.9.0-jar-with-dependencies.jar Example.java
Run the Java. Replace 10.9.0
with the version of your fat jar file.
On Linux or macOS, run:
java -cp .:twilio-10.9.0-jar-with-dependencies.jar Example
On Windows, run:
java -cp ".;twilio-10.9.0-jar-with-dependencies.jar" Example
After a few moments, you receive an SMS from your Twilio number on the Twilio Virtual Phone.
Create and set up your Go project.
Create a new Go project by running the following command:
go mod init twilio-example
Install the Gin Framework (link takes you to an external page) :
go get -u github.com/gin-gonic/gin
Install the Twilio Go helper library (link takes you to an external page) :
go get github.com/twilio/twilio-go
Install the TwiML dependency:
go get github.com/twilio/twilio-go/twiml@latest
Create and open a new file called send_sms.go
in your Go project directory and paste in the following code:
1// Download the helper library from https://www.twilio.com/docs/go/install
6"github.com/twilio/twilio-go"
7api "github.com/twilio/twilio-go/rest/api/v2010"
12// Find your Account SID and Auth Token at twilio.com/console
13// and set the environment variables. See http://twil.io/secure
14// Make sure TWILIO_ACCOUNT_SID and TWILIO_AUTH_TOKEN exists in your environment
15client := twilio.NewRestClient()
17params := &api.CreateMessageParams{}
18params.SetBody("Join Earth's mightiest heroes. Like Kevin Bacon.")
19params.SetFrom("+15017122661")
20params.SetTo("+15558675310")
22resp, err := client.Api.CreateMessage(params)
Run the following command in the terminal to set your environment variables. Replace <your-account-sid>
and <your-auth-token>
with your Account SID and Auth Token:
1export TWILIO_ACCOUNT_SID=<your-account-sid>
2export TWILIO_AUTH_TOKEN=<your-auth-token>
To learn more, see Store your Twilio credentials securely.
Replace the value for params.SetFrom
with the phone number that Twilio gave you in E.164 format.
Replace the value for params.SetTo
with the Twilio Virtual Phone number (+18777804236
).
Save your changes and run this command in the directory that contains send_sms.go
:
After a few moments, you receive an SMS from your Twilio number on the Twilio Virtual Phone.
Create and open a new file called send_sms.rb
anywhere on your machine and paste in the following code:
1# Download the helper library from https://www.twilio.com/docs/ruby/install
5# Find your Account SID and Auth Token at twilio.com/console
6# and set the environment variables. See http://twil.io/secure
7account_sid = ENV['TWILIO_ACCOUNT_SID']
8auth_token = ENV['TWILIO_AUTH_TOKEN']
9@client = Twilio::REST::Client.new(account_sid, auth_token)
16body: 'Join Earth\'s mightiest heroes. Like Kevin Bacon.',
In the send_sms.rb
file, replace the values for account_sid
and auth_token
with your Account SID and Auth Token surrounded by single quotation marks.
(error)
Don't include credentials in production appsThis quickstart hardcodes your credentials for faster setup. To keep credentials secret and control access when you deploy to production, use environment variables and API keys.
Replace the value for from
with the phone number that Twilio gave you in E.164 format.
Replace the value for to
with the Twilio Virtual Phone number (+18777804236
).
Save your changes and run this command from your terminal in the directory that contains send_sms.rb
:
After a few moments, you receive an SMS from your Twilio number on the Twilio Virtual Phone.
Follow these steps to reply to an SMS message sent to your Twilio phone number.
PythonNode.jsPHPC# (.NET Framework)C# (.NET Core)JavaGoRubyCreate and open a new file called reply_sms.py
anywhere on your machine and paste in the following code:
1from flask import Flask, request, Response
2from twilio.twiml.messaging_response import MessagingResponse
6@app.route("/reply_sms", methods=['POST'])
8# Create a new Twilio MessagingResponse
9resp = MessagingResponse()
10resp.message("The Robots are coming! Head for the hills!")
12# Return the TwiML (as XML) response
13return Response(str(resp), mimetype='text/xml')
15if __name__ == "__main__":
Save the file.
In a new terminal window, run the following command to start the Python development server on port 3000:
In a new terminal window, run the following command to start ngrok (link takes you to an external page) and create a tunnel to your localhost:
(warning)
WarningUse ngrok only for testing because it creates a temporary URL that exposes your local development machine to the internet. Host your application with a cloud provider or your public server when you deploy to production.
Set up a webhook that triggers when your Twilio phone number receives an SMS message:
Open the Active Numbers page in the Twilio Console (link takes you to an external page) .
Click your Twilio phone number.
In the Messaging Configuration section, in the URL field for A message comes in, enter the temporary forwarding URL from your ngrok console with /reply_sms
appended to the end.
For example, if your ngrok console shows Forwarding https://1aaa-123-45-678-910.ngrok-free.app
, enter https://1aaa-123-45-678-910.ngrok-free.app/reply_sms
.
Click Save configuration.
With the Python development server and ngrok running, send an SMS to your Twilio phone number:
An HTTP request shows in your ngrok console, and you get the response back as an SMS on the Twilio Virtual Phone.
Create and open a new file called server.js
anywhere on your machine and paste in the following code:
1const express = require('express');
2const { MessagingResponse } = require('twilio').twiml;
6app.post('/sms', (req, res) => {
7const twiml = new MessagingResponse();
9twiml.message('The Robots are coming! Head for the hills!');
11res.type('text/xml').send(twiml.toString());
15console.log('Express server listening on port 3000');
In a new terminal window, start the Node.js development server on port 3000 by running this command in the directory that contains server.js
:
In a new terminal window, run the following command to start ngrok (link takes you to an external page) and create a tunnel to your localhost:
(warning)
WarningUse ngrok only for testing because it creates a temporary URL that exposes your local development machine to the internet. Host your application with a cloud provider or your public server when you deploy to production.
Set up a webhook that triggers when your Twilio phone number receives an SMS message:
Open the Active Numbers page in the Twilio Console (link takes you to an external page) .
Click the phone number that Twilio gave you.
In the Messaging Configuration section, in the URL field for A message comes in, enter the temporary forwarding URL from your ngrok console with /sms
appended to the end.
For example, if your ngrok console shows Forwarding https://1aaa-123-45-678-910.ngrok-free.app
, enter https://1aaa-123-45-678-910.ngrok-free.app/sms
.
Click Save configuration.
With the Node.js development server and ngrok running, send an SMS to your Twilio phone number:
An HTTP request shows in your ngrok console, and you get the response back as an SMS on the Twilio Virtual Phone.
Create and open a new file called reply_sms.php
in the same directory as send_sms.php
and paste in the following code:
2require_once "vendor/autoload.php";
3use Twilio\TwiML\MessagingResponse;
5// Set the content-type to XML to send back TwiML from the PHP Helper Library
6header("content-type: text/xml");
8$response = new MessagingResponse();
10"The Robots are coming! Head for the hills!"
Save the file.
In a new terminal window, start the PHP development server on port 3000 by running this command:
In a new terminal window, run the following command to start ngrok (link takes you to an external page) and create a tunnel to your localhost:
(warning)
WarningUse ngrok only for testing because it creates a temporary URL that exposes your local development machine to the internet. Host your application with a cloud provider or your public server when you deploy to production.
Set up a webhook that triggers when your Twilio phone number receives an SMS message:
Open the Active Numbers page in the Twilio Console (link takes you to an external page) .
Click your Twilio phone number.
In the Messaging Configuration section, in the URL field for A message comes in, enter the temporary forwarding URL from your ngrok console with /reply_sms.php
appended to the end.
For example, if your ngrok console shows Forwarding https://1aaa-123-45-678-910.ngrok-free.app
, enter https://1aaa-123-45-678-910.ngrok-free.app/reply_sms.php
.
Click Save configuration.
With the PHP development server and ngrok running, send an SMS to your Twilio phone number:
An HTTP request shows in your ngrok console, and you get the response back as an SMS on the Twilio Virtual Phone.
Create a new ASP.NET MVC Project in Visual Studio:
Create a new controller:
Controllers
folderAdd
> Controller...
> MVC 5 Controller - Empty
.SmsController.cs
.Paste the following code into SmsController.cs
:
1// Code sample for ASP.NET MVC on .NET Framework 4.6.1+
2// In Package Manager, run:
3// Install-Package Twilio.AspNet.Mvc -DependencyVersion HighestMinor
5using Twilio.AspNet.Common;
9namespace WebApplication1.Controllers
11public class SmsController : TwilioController
13public TwiMLResult Index(SmsRequest incomingMessage)
15var messagingResponse = new MessagingResponse();
16messagingResponse.Message("The copy cat says: " +
19return TwiML(messagingResponse);
Save the file.
In Visual Studio, run the application by clicking the play arrow. Your web browser opens on a localhost URL. Note the port number; for example, if the URL opens on https://localhost:44360
, your port number is 44360
.
In a new terminal window, run the following command to start ngrok (link takes you to an external page) and create a tunnel to your localhost. Replace <port>
with the port number from your application.
(warning)
WarningUse ngrok only for testing because it creates a temporary URL that exposes your local development machine to the internet. Host your application with a cloud provider or your public server when you deploy to production.
Set up a webhook that triggers when your Twilio phone number receives an SMS message:
Open the Active Numbers page in the Twilio Console (link takes you to an external page) .
Click your Twilio phone number.
In the Messaging Configuration section, in the URL field for A message comes in, enter the temporary forwarding URL from your ngrok console with /sms
appended to the end.
For example, if your ngrok console shows Forwarding https://1aaa-123-45-678-910.ngrok-free.app
, enter https://1aaa-123-45-678-910.ngrok-free.app/sms
.
Click Save configuration.
With the application and ngrok running, send an SMS to your Twilio phone number:
An HTTP request shows in your ngrok console, and you get the response back as an SMS on the Twilio Virtual Phone.
Run the following commands to create a new ASP.NET Core project and install the Twilio NuGet package:
4dotnet add package Twilio.AspNet.Core
In the Controllers
directory, create a file named SmsController.cs
and paste in the following code:
1// Code sample for ASP.NET Core on .NET Core
2// From command prompt, run:
3// dotnet add package Twilio.AspNet.Core
5using Twilio.AspNet.Common;
6using Twilio.AspNet.Core;
9namespace TwilioReceive.Controllers
11public class SmsController : TwilioController
13public TwiMLResult Index(SmsRequest incomingMessage)
15var messagingResponse = new MessagingResponse();
16messagingResponse.Message("The copy cat says: " +
19return TwiML(messagingResponse);
Save the file.
From the root of the project directory, run following command to start the application:
Check the command output for the localhost URL. Note the port number; for example, if the URL opens on https://localhost:5242
, your port number is 5242
.
In a new terminal window, run the following command to start ngrok (link takes you to an external page) and create a tunnel to your localhost. Replace <port>
with the port number from your command output.
(warning)
WarningUse ngrok only for testing because it creates a temporary URL that exposes your local development machine to the internet. Host your application with a cloud provider or your public server when you deploy to production.
Set up a webhook that triggers when your Twilio phone number receives an SMS message:
Open the Active Numbers page in the Twilio Console (link takes you to an external page) .
Click your Twilio phone number.
In the Messaging Configuration section, in the URL field for A message comes in, enter the temporary forwarding URL from your ngrok console with /sms
appended to the end.
For example, if your ngrok console shows Forwarding https://1aaa-123-45-678-910.ngrok-free.app
, enter https://1aaa-123-45-678-910.ngrok-free.app/sms
.
Click Save configuration.
With the application and ngrok running, send an SMS to your Twilio phone number:
An HTTP request shows in your ngrok console, and you get the response back as an SMS on the Twilio Virtual Phone.
Create and set up the IntelliJ project.
com.twilio.sdk:twilio
com.sparkjava:sparkcore
org.slf4j
To learn more about the dependencies, see SparkJava (link takes you to an external page) and Simple Logging Facade 4 Java (SLF4J) (link takes you to an external page) .java
folder under src
> main
.SmsApp
.In the new SmsApp.java
file that IntelliJ creates, paste in the following code:
1import com.twilio.twiml.MessagingResponse;
2import com.twilio.twiml.messaging.Body;
3import com.twilio.twiml.messaging.Message;
5import static spark.Spark.*;
8public static void main(String[] args) {
9get("/", (req, res) -> "Hello Web");
11post("/sms", (req, res) -> {
12res.type("application/xml");
14.Builder("The Robots are coming! Head for the hills!")
16Message sms = new Message
20MessagingResponse twiml = new MessagingResponse
Right-click on the SmsApp class in the project outline and choose Run 'SmsApp.main()'.
The Java spark web application server starts listening on port 4567.
In a new terminal window, run the following command to start ngrok (link takes you to an external page) and create a tunnel to your localhost:
(warning)
WarningUse ngrok only for testing because it creates a temporary URL that exposes your local development machine to the internet. Host your application with a cloud provider or your public server when you deploy to production.
Set up a webhook that triggers when your Twilio phone number receives an SMS message:
Open the Active Numbers page in the Twilio Console (link takes you to an external page) .
Click the phone number that Twilio gave you.
In the Messaging Configuration section, in the URL field for A message comes in, enter the temporary forwarding URL from your ngrok console with /sms
appended to the end.
For example, if your ngrok console shows Forwarding https://1aaa-123-45-678-910.ngrok-free.app
, enter https://1aaa-123-45-678-910.ngrok-free.app/sms
.
Click Save configuration.
With the Java development server and ngrok running, send an SMS to your Twilio phone number:
An HTTP request shows in your ngrok console, and you get the response back as an SMS on the Twilio Virtual Phone.
Create and open a new file called server.go
in your Go project directory and paste in the following code:
6"github.com/gin-gonic/gin"
7"github.com/twilio/twilio-go/twiml"
13router.POST("/sms", func(context *gin.Context) {
14message := &twiml.MessagingMessage{
15Body: "The Robots are coming! Head for the hills!",
18twimlResult, err := twiml.Messages([]twiml.Element{message})
20context.String(http.StatusInternalServerError, err.Error())
22context.Header("Content-Type", "text/xml")
23context.String(http.StatusOK, twimlResult)
In a new terminal window, start the Go development server on port 3000 by running this command in the directory that contains server.go
:
In a new terminal window, run the following command to start ngrok (link takes you to an external page) and create a tunnel to your localhost:
(warning)
WarningUse ngrok only for testing because it creates a temporary URL that exposes your local development machine to the internet. Host your application with a cloud provider or your public server when you deploy to production.
Set up a webhook that triggers when your Twilio phone number receives an SMS message:
Open the Active Numbers page in the Twilio Console (link takes you to an external page) .
Click the phone number that Twilio gave you.
In the Messaging Configuration section, in the URL field for A message comes in, enter the temporary forwarding URL from your ngrok console with /sms
appended to the end.
For example, if your ngrok console shows Forwarding https://1aaa-123-45-678-910.ngrok-free.app
, enter https://1aaa-123-45-678-910.ngrok-free.app/sms
.
Click Save configuration.
With the Go development server and ngrok running, send an SMS to your Twilio phone number:
An HTTP request shows in your ngrok console, and you get the response back as an SMS on the Twilio Virtual Phone.
To install Sinatra (link takes you to an external page) and the Twilio Ruby helper library (link takes you to an external page) , create and open a new file called Gemfile
anywhere on your machine and paste in the following code.
If you prefer to use the Rails framework, see the How to Receive and Reply to an SMS in Rails with Twilio (link takes you to an external page) .
2source 'https://rubygems.org'
In the same directory as Gemfile
, run the following command from the terminal:
Create and open a new file called reply_sms.rb
in the same directory as Gemfile
and paste in the following code:
4# disable HostAuthorization for development only
5configure :development do
6set :host_authorization, { permitted_hosts: [] }
9post '/sms-quickstart' do
10twiml = Twilio::TwiML::MessagingResponse.new do |r|
11r.message(body: 'Ahoy! Thanks so much for your message.')
Save the file.
In a new terminal window, start the Ruby development server on port 4567 by running this command:
In a new terminal window, run the following command to start ngrok (link takes you to an external page) and create a tunnel to your localhost:
(warning)
WarningUse ngrok only for testing because it creates a temporary URL that exposes your local development machine to the internet. Host your application with a cloud provider or your public server when you deploy to production.
Set up a webhook that triggers when your Twilio phone number receives an SMS message:
Open the Active Numbers page in the Twilio Console (link takes you to an external page) .
Click your Twilio phone number.
In the Messaging Configuration section, in the URL field for A message comes in, enter the temporary forwarding URL from your ngrok console with /sms-quickstart
appended to the end.
For example, if your ngrok console shows Forwarding https://1aaa-123-45-678-910.ngrok-free.app
, enter https://1aaa-123-45-678-910.ngrok-free.app/sms-quickstart
.
Click Save configuration.
With the Ruby development server and ngrok running, send an SMS to your Twilio phone number:
An HTTP request shows in your ngrok console, and you get the response back as an SMS on the Twilio Virtual Phone.
RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4