A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from https://www.twilio.com/docs/quickstart/python/sms/hello-monkey below:

SMS developer quickstart | Twilio

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)JavaGoRuby
  1. Sign up for Twilio (link takes you to an external page) . When prompted to select a plan, click Continue with trial.
  2. On the landing page:
    1. Click Get phone number to get a phone number.
    2. Copy your Account SID and Auth Token and paste them in a temporary local file for use later in this quickstart.

The 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.

  1. Open the Send an SMS page in the Twilio Console (link takes you to an external page) .
  2. On the Send to Virtual Phone tab, select the number that Twilio gave you from the Phone number list.
  3. Click Virtual Phone. Messages you send with your application display on the Virtual Phone.

Follow these steps to send an SMS message from your Twilio phone number.

PythonNode.jsPHPC# (.NET Framework)C# (.NET Core)JavaGoRuby
  1. Create 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

    3

    from 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

    7

    account_sid = os.environ["TWILIO_ACCOUNT_SID"]

    8

    auth_token = os.environ["TWILIO_AUTH_TOKEN"]

    9

    client = Client(account_sid, auth_token)

    11

    message = client.messages.create(

    12

    body="Join Earth's mightiest heroes. Like Kevin Bacon.",

  2. 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 apps

    This 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.

  3. Replace the value for from with the phone number that Twilio gave you in E.164 format.

  4. Replace the value for to with the Twilio Virtual Phone number (+18777804236).

  5. 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.

  1. 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

    2

    const 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

    6

    const accountSid = process.env.TWILIO_ACCOUNT_SID;

    7

    const authToken = process.env.TWILIO_AUTH_TOKEN;

    8

    const client = twilio(accountSid, authToken);

    10

    async function createMessage() {

    11

    const message = await client.messages.create({

    12

    body: "This is the ship that made the Kessel Run in fourteen parsecs?",

    17

    console.log(message.body);

  2. 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 apps

    This 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.

  3. Replace the value for from with the phone number that Twilio gave you in E.164 format.

  4. Replace the value for to with the Twilio Virtual Phone number (+18777804236).

  5. 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.

  1. 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

    5

    require_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",

  2. 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 apps

    This 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.

  3. Replace the value for from with the phone number that Twilio gave you in E.164 format.

  4. Replace the value for To with the Twilio Virtual Phone number (+18777804236).

  5. Update line 5 of send_sms.php to require __DIR__ . '/vendor/autoload.php';

  6. 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.

  1. Create and set up a new project in Visual Studio:

    1. Open Visual Studio and click Create a new project.
    2. Click Console App (.NET Framework).
    3. Use the NuGet Package Manager (link takes you to an external page) to install the Twilio REST API helper library.
  2. 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

    5

    using Twilio.Rest.Api.V2010.Account;

    6

    using System.Threading.Tasks;

    9

    public 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

    12

    string accountSid = Environment.GetEnvironmentVariable("TWILIO_ACCOUNT_SID");

    13

    string authToken = Environment.GetEnvironmentVariable("TWILIO_AUTH_TOKEN");

    15

    TwilioClient.Init(accountSid, authToken);

    17

    var message = await MessageResource.CreateAsync(

    18

    body: "Join Earth's mightiest heroes. Like Kevin Bacon.",

    19

    from: new Twilio.Types.PhoneNumber("+15017122661"),

    20

    to: new Twilio.Types.PhoneNumber("+15558675310"));

    22

    Console.WriteLine(message.Body);

  3. 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 apps

    This 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.

  4. Replace the value for from: new Twilio.Types.PhoneNumber with the phone number that Twilio gave you in E.164 format.

  5. Replace the value for to: new Twilio.Types.PhoneNumber with the Twilio Virtual Phone number (+18777804236).

  6. 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.

  1. Run the following commands to create a new .NET project and install the Twilio NuGet package:

    4

    dotnet add package Twilio

  2. 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

    5

    using Twilio.Rest.Api.V2010.Account;

    6

    using System.Threading.Tasks;

    9

    public 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

    12

    string accountSid = Environment.GetEnvironmentVariable("TWILIO_ACCOUNT_SID");

    13

    string authToken = Environment.GetEnvironmentVariable("TWILIO_AUTH_TOKEN");

    15

    TwilioClient.Init(accountSid, authToken);

    17

    var message = await MessageResource.CreateAsync(

    18

    body: "Join Earth's mightiest heroes. Like Kevin Bacon.",

    19

    from: new Twilio.Types.PhoneNumber("+15017122661"),

    20

    to: new Twilio.Types.PhoneNumber("+15558675310"));

    22

    Console.WriteLine(message.Body);

  3. 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 apps

    This 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.

  4. Replace the value for from: new Twilio.Types.PhoneNumber with the phone number that Twilio gave you in E.164 format.

  5. Replace the value for to: new Twilio.Types.PhoneNumber with the Twilio Virtual Phone number (+18777804236).

  6. 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.

  1. 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

    3

    import com.twilio.type.PhoneNumber;

    4

    import com.twilio.Twilio;

    5

    import 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

    10

    public static final String ACCOUNT_SID = System.getenv("TWILIO_ACCOUNT_SID");

    11

    public static final String AUTH_TOKEN = System.getenv("TWILIO_AUTH_TOKEN");

    13

    public static void main(String[] args) {

    14

    Twilio.init(ACCOUNT_SID, AUTH_TOKEN);

    15

    Message message = Message

    16

    .creator(new com.twilio.type.PhoneNumber("+15558675310"),

    17

    new com.twilio.type.PhoneNumber("+15017122661"),

    18

    "This is the ship that made the Kessel Run in fourteen parsecs?")

    21

    System.out.println(message.getBody());

  2. 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 apps

    This 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.

  3. Replace the value for the first phone number with the Twilio Virtual Phone number (+18777804236).

  4. Replace the value for the second phone number with the phone number that Twilio gave you in E.164 format.

  5. 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

  6. 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.

  1. Create and set up your Go project.

    1. Create a new Go project by running the following command:

      go mod init twilio-example

    2. Install the Gin Framework (link takes you to an external page) :

      go get -u github.com/gin-gonic/gin

    3. Install the Twilio Go helper library (link takes you to an external page) :

      go get github.com/twilio/twilio-go

    4. Install the TwiML dependency:

      go get github.com/twilio/twilio-go/twiml@latest

  2. 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"

    7

    api "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

    15

    client := twilio.NewRestClient()

    17

    params := &api.CreateMessageParams{}

    18

    params.SetBody("Join Earth's mightiest heroes. Like Kevin Bacon.")

    19

    params.SetFrom("+15017122661")

    20

    params.SetTo("+15558675310")

    22

    resp, err := client.Api.CreateMessage(params)

  3. 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:

    1

    export TWILIO_ACCOUNT_SID=<your-account-sid>

    2

    export TWILIO_AUTH_TOKEN=<your-auth-token>

    To learn more, see Store your Twilio credentials securely.

  4. Replace the value for params.SetFrom with the phone number that Twilio gave you in E.164 format.

  5. Replace the value for params.SetTo with the Twilio Virtual Phone number (+18777804236).

  6. 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.

  1. 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

    7

    account_sid = ENV['TWILIO_ACCOUNT_SID']

    8

    auth_token = ENV['TWILIO_AUTH_TOKEN']

    9

    @client = Twilio::REST::Client.new(account_sid, auth_token)

    16

    body: 'Join Earth\'s mightiest heroes. Like Kevin Bacon.',

  2. 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 apps

    This 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.

  3. Replace the value for from with the phone number that Twilio gave you in E.164 format.

  4. Replace the value for to with the Twilio Virtual Phone number (+18777804236).

  5. 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)JavaGoRuby
  1. Create and open a new file called reply_sms.py anywhere on your machine and paste in the following code:

    1

    from flask import Flask, request, Response

    2

    from twilio.twiml.messaging_response import MessagingResponse

    6

    @app.route("/reply_sms", methods=['POST'])

    8

    # Create a new Twilio MessagingResponse

    9

    resp = MessagingResponse()

    10

    resp.message("The Robots are coming! Head for the hills!")

    12

    # Return the TwiML (as XML) response

    13

    return Response(str(resp), mimetype='text/xml')

    15

    if __name__ == "__main__":

    Save the file.

  2. In a new terminal window, run the following command to start the Python development server on port 3000:

  3. 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)

    Warning

    Use 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.

  4. Set up a webhook that triggers when your Twilio phone number receives an SMS message:

    1. Open the Active Numbers page in the Twilio Console (link takes you to an external page) .

    2. Click your Twilio phone number.

    3. 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.

    4. Click Save configuration.

  5. With the Python development server and ngrok running, send an SMS to your Twilio phone number:

    1. Enter a message in the Click here to reply field at the bottom of the Twilio Virtual Phone.
    2. Click the send icon.

    An HTTP request shows in your ngrok console, and you get the response back as an SMS on the Twilio Virtual Phone.

  1. Create and open a new file called server.js anywhere on your machine and paste in the following code:

    1

    const express = require('express');

    2

    const { MessagingResponse } = require('twilio').twiml;

    6

    app.post('/sms', (req, res) => {

    7

    const twiml = new MessagingResponse();

    9

    twiml.message('The Robots are coming! Head for the hills!');

    11

    res.type('text/xml').send(twiml.toString());

    15

    console.log('Express server listening on port 3000');

  2. 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:

  3. 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)

    Warning

    Use 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.

  4. Set up a webhook that triggers when your Twilio phone number receives an SMS message:

    1. Open the Active Numbers page in the Twilio Console (link takes you to an external page) .

    2. Click the phone number that Twilio gave you.

    3. 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.

  5. Click Save configuration.

  6. With the Node.js development server and ngrok running, send an SMS to your Twilio phone number:

    1. Enter a message in the Click here to reply field at the bottom of the Twilio Virtual Phone.
    2. Click the send icon.

    An HTTP request shows in your ngrok console, and you get the response back as an SMS on the Twilio Virtual Phone.

  1. Create and open a new file called reply_sms.php in the same directory as send_sms.php and paste in the following code:

    2

    require_once "vendor/autoload.php";

    3

    use Twilio\TwiML\MessagingResponse;

    5

    // Set the content-type to XML to send back TwiML from the PHP Helper Library

    6

    header("content-type: text/xml");

    8

    $response = new MessagingResponse();

    10

    "The Robots are coming! Head for the hills!"

    Save the file.

  2. In a new terminal window, start the PHP development server on port 3000 by running this command:

  3. 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)

    Warning

    Use 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.

  4. Set up a webhook that triggers when your Twilio phone number receives an SMS message:

    1. Open the Active Numbers page in the Twilio Console (link takes you to an external page) .

    2. Click your Twilio phone number.

    3. 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.

    4. Click Save configuration.

  5. With the PHP development server and ngrok running, send an SMS to your Twilio phone number:

    1. Enter a message in the Click here to reply field at the bottom of the Twilio Virtual Phone.
    2. Click the send icon.

    An HTTP request shows in your ngrok console, and you get the response back as an SMS on the Twilio Virtual Phone.

  1. Create a new ASP.NET MVC Project in Visual Studio:

    1. Open Visual Studio and click Create a new project.
    2. Click ASP.NET Web Application (.NET Framework).
    3. Click MVC to select the project type.
    4. Use the NuGet Package Manager (link takes you to an external page) to install the Twilio.AspNet.Mvc package.
  2. Create a new controller:

    1. Open the project directory.
    2. Right-click on the Controllers folder
    3. Select Add > Controller... > MVC 5 Controller - Empty.
    4. Name the file SmsController.cs.
  3. 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

    5

    using Twilio.AspNet.Common;

    9

    namespace WebApplication1.Controllers

    11

    public class SmsController : TwilioController

    13

    public TwiMLResult Index(SmsRequest incomingMessage)

    15

    var messagingResponse = new MessagingResponse();

    16

    messagingResponse.Message("The copy cat says: " +

    19

    return TwiML(messagingResponse);

    Save the file.

  4. 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.

  5. 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)

    Warning

    Use 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.

  6. Set up a webhook that triggers when your Twilio phone number receives an SMS message:

    1. Open the Active Numbers page in the Twilio Console (link takes you to an external page) .

    2. Click your Twilio phone number.

    3. 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.

    4. Click Save configuration.

  7. With the application and ngrok running, send an SMS to your Twilio phone number:

    1. Enter a message in the Click here to reply field at the bottom of the Twilio Virtual Phone.
    2. Click the send icon.

    An HTTP request shows in your ngrok console, and you get the response back as an SMS on the Twilio Virtual Phone.

  1. Run the following commands to create a new ASP.NET Core project and install the Twilio NuGet package:

    4

    dotnet add package Twilio.AspNet.Core

  2. 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

    5

    using Twilio.AspNet.Common;

    6

    using Twilio.AspNet.Core;

    9

    namespace TwilioReceive.Controllers

    11

    public class SmsController : TwilioController

    13

    public TwiMLResult Index(SmsRequest incomingMessage)

    15

    var messagingResponse = new MessagingResponse();

    16

    messagingResponse.Message("The copy cat says: " +

    19

    return TwiML(messagingResponse);

    Save the file.

  3. From the root of the project directory, run following command to start the application:

  4. 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.

  5. 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)

    Warning

    Use 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.

  6. Set up a webhook that triggers when your Twilio phone number receives an SMS message:

    1. Open the Active Numbers page in the Twilio Console (link takes you to an external page) .

    2. Click your Twilio phone number.

    3. 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.

    4. Click Save configuration.

  7. With the application and ngrok running, send an SMS to your Twilio phone number:

    1. Enter a message in the Click here to reply field at the bottom of the Twilio Virtual Phone.
    2. Click the send icon.

    An HTTP request shows in your ngrok console, and you get the response back as an SMS on the Twilio Virtual Phone.

  1. Create and set up the IntelliJ project.

    1. Open IntelliJ IDEA Community Edition.
    2. Create a new project with either Maven or Gradle as the build system.
    3. Install the following dependencies with Maven (link takes you to an external page) or with Gradle (link takes you to an external page) :
    4. Select the java folder under src > main.
    5. Click File > New> Java Class to create a new Java class. Name the class SmsApp.
  2. In the new SmsApp.java file that IntelliJ creates, paste in the following code:

    1

    import com.twilio.twiml.MessagingResponse;

    2

    import com.twilio.twiml.messaging.Body;

    3

    import com.twilio.twiml.messaging.Message;

    5

    import static spark.Spark.*;

    8

    public static void main(String[] args) {

    9

    get("/", (req, res) -> "Hello Web");

    11

    post("/sms", (req, res) -> {

    12

    res.type("application/xml");

    14

    .Builder("The Robots are coming! Head for the hills!")

    16

    Message sms = new Message

    20

    MessagingResponse twiml = new MessagingResponse

  3. 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.

  4. 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)

    Warning

    Use 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.

  5. Set up a webhook that triggers when your Twilio phone number receives an SMS message:

    1. Open the Active Numbers page in the Twilio Console (link takes you to an external page) .

    2. Click the phone number that Twilio gave you.

    3. 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.

    4. Click Save configuration.

  6. With the Java development server and ngrok running, send an SMS to your Twilio phone number:

    1. Enter a message in the Click here to reply field at the bottom of the Twilio Virtual Phone.
    2. Click the send icon.

    An HTTP request shows in your ngrok console, and you get the response back as an SMS on the Twilio Virtual Phone.

  1. 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"

    13

    router.POST("/sms", func(context *gin.Context) {

    14

    message := &twiml.MessagingMessage{

    15

    Body: "The Robots are coming! Head for the hills!",

    18

    twimlResult, err := twiml.Messages([]twiml.Element{message})

    20

    context.String(http.StatusInternalServerError, err.Error())

    22

    context.Header("Content-Type", "text/xml")

    23

    context.String(http.StatusOK, twimlResult)

  2. In a new terminal window, start the Go development server on port 3000 by running this command in the directory that contains server.go:

  3. 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)

    Warning

    Use 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.

  4. Set up a webhook that triggers when your Twilio phone number receives an SMS message:

    1. Open the Active Numbers page in the Twilio Console (link takes you to an external page) .

    2. Click the phone number that Twilio gave you.

    3. 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.

    4. Click Save configuration.

  5. With the Go development server and ngrok running, send an SMS to your Twilio phone number:

    1. Enter a message in the Click here to reply field at the bottom of the Twilio Virtual Phone.
    2. Click the send icon.

    An HTTP request shows in your ngrok console, and you get the response back as an SMS on the Twilio Virtual Phone.

  1. 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) .

    2

    source 'https://rubygems.org'

  2. In the same directory as Gemfile, run the following command from the terminal:

  3. 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

    5

    configure :development do

    6

    set :host_authorization, { permitted_hosts: [] }

    9

    post '/sms-quickstart' do

    10

    twiml = Twilio::TwiML::MessagingResponse.new do |r|

    11

    r.message(body: 'Ahoy! Thanks so much for your message.')

    Save the file.

  4. In a new terminal window, start the Ruby development server on port 4567 by running this command:

  5. 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)

    Warning

    Use 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.

  6. Set up a webhook that triggers when your Twilio phone number receives an SMS message:

    1. Open the Active Numbers page in the Twilio Console (link takes you to an external page) .

    2. Click your Twilio phone number.

    3. 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.

    4. Click Save configuration.

  7. With the Ruby development server and ngrok running, send an SMS to your Twilio phone number:

    1. Enter a message in the Click here to reply field at the bottom of the Twilio Virtual Phone.
    2. Click the send icon.

    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