cancel
Showing results for 
Search instead for 
Did you mean: 
cancel
Showing results for 
Search instead for 
Did you mean: 

Community Tip - Learn all about the Community Ranking System, a fun gamification element of the PTC Community. X

Send Messages with Twilio

No ratings

 

Send voice and text messages with Twilio.

 

GUIDE CONCEPT

 

This project will demonstrate how you can create applications that provide information to users, even when they are away from their computer. Users who are on the go can benefit from your application by receiving text and voice messages.

 

Following the steps in this guide, you will learn how to configure and use the Twilio Widget and explore it’s ability to send messages.

 

We will teach you how data can be used to send pertinent information to any cell phone.

 

YOU'LL LEARN HOW TO

 

  • Download and import the Twilio Widget extension
  • Create a Thing using the Twilio Thing Template
  • Configure the Twilio Thing to use your Twilio account
  • Send text messages using a Service

 

NOTE:  The estimated time to complete this guide is 30 minutes.

 

 

Step 1: Install Twilio Extension

 

  1. Download the Twilio Extension from IQNOX.com.

    Note:  IQNOX is a PTC Partner and will be maintaining and supporting specific extensions going forward.  It will be necessary to create an account on the IQNOX website, but the ThingWorx extensions are free.

  2. In the lower-left side of Composer, click Import/Export, then Import.


    v90_import.png

     

  3. In the Import From File pop-up, under Import Option select Extension from the drop-down, then click Browse.

  4. Navigate to the .zip file you downloaded.


    v90_Google_Map_import.png

     
  5. Click Import in the Import From File pop-up, then click Close after file is successfully imported.

 

 

Step 2: Create Twilio Thing

 

In this step, you will create a Thing that represents a connection with the Twilio service.

 

  1. Start on the Browse, folder icon tab on the far left of ThingWorx Composer

    foundation_QS_addThingv90.png

  2. Under the Modeling tab, hover over Things then click the + button.
  3. Type twilio-connector in the Name field.


    new-twilio-connector-name.png

     

    NOTE: This name, with matching capitalization, is required for the example code which will be entered in a later step.

  4. If Project is not already set, click the + in the Project text box and select the PTCDefaultProject.

  5. In the Base Thing Template text box, click the + and select Twilio.
     

    new-twilio-connector.png

     

  6. Click Save.

 

 

Step 3: Configure Twilio Thing

 

Now that we have created a Thing to represent the Twilio connection, we will configure it with your Twilio account credentials.

 

When the Twilio Extension is installed, it does not include the Twilio account credentials required to send messages.

 

You will need Twilio account credentials to complete this step. If you do not already have a Twilio account, you can click on this link to create a Twilio account.

 

  1. Open the twilio-connection Thing if it is not already open.

  2. Click on the Configuration tab.

  3. Click the pencil icon next to the authToken field.


    twil-connector-config.png

     

  4. Copy your AUTH TOKEN from your Twilio account dashboard.


    twilio-account-auth-sid.png

     

  5. Paste your AUTH TOKEN into the New Password and Confirm Password fields under authToken.


    auth-token-entered.png

     

  6. Click the pencil icon next to the accountSID field.

  7. Copy your ACCOUNT SID from your Twilio account dashboard, and paste it into the New Password and Confirm Password fields under accountSID.

  8. Follow the steps in your Twilio account dashboard to get a trial phone number.


    twilio-new-number.PNG

     

  9. Copy your PHONE NUMBER from your Twilio account dashboardand paste it into the callerID field.


    twil-connector-save-config.png

     

  10. Click Save.

 

 

Step 4: Test Twilio Thing

 

Now that we have created a Thing to represent the Twilio connection and configured it with Twilio account credentials, we will confirm that everything is working.

 

  1. Click the Services tab at the top of the twilio-connector Thing.
     

    twilio-services.png

     

  2. Click the link to the SendSMSMessage Service in the Services Name column.

  3. Enter a phone number in the to field.

  4. Enter a test message in the text field.


    send-sms-clicked.png

     

  5. Click the Execute button to send the SMS message.

  6. The service should execute without any errors within a couple of seconds and the phone number will receive your message.

  7. Click Close to end testing the service.

 

 

Step 5: Sample Alerting App

 

At this point, you have created and tested a Thing that can send text messages. This step will demonstrate sending a message when a Property Value is out of the desired range.

 

Import Simulated Freezer Thing

 

  1. Download and unzip the attached sample Things_freezer.zip.

  2. In Composer, click the Import/Export icon at the lower-left of the page.


    click-import-icon.png

     
  3. Click Import.

    import-clicked.png

  4. Leave all default values and click Browse to select the Things_freezer.twx file that you just downloaded.

  5. Click Open, then Import.

  6. When you see the success message, click Close.

 

Explore Imported Entities

 

  1. Navigate to the freezer Thing by using the search bar at the top of the screen.

  2. Click the Subscriptions tab.


    freezer-subscriptions.png

     

  3. Click reportFreezer under Name.

  4. Open the Subscription Info tab.

  5. Select the Enabled checkbox.


    freezer-subscription-enabled.png

     

  6. Click Done then Save to save any changes.

 

Verify Data Simulation

 

  1. Open the freezer Thing and click Properties and Alerts tab.

  2. Click the Set value in the alertedPhone Property row, in the Value column.


    set-alerted-phone.png

     
  3. Enter a phone number to receive the SMS alert, then click the Check icon above where you entered the phone number.

  4. Click the pencil icon in the temp Property row, in the Value column.


    set-freezer-temp.png



  5. Enter a value for the temp property that is greater than 30, and click the Check icon.

  6. In a couple seconds, the phone number you entered will receive an alert that includes the value you entered. 

 

 

Step 6: Next Steps

 

Congratulations!

 

In this guide, you learned how to:

 

  • Create a Thing using the Twilio Thing Template
  • Configure the Twilio Thing to use your Twilio account
  • Send text messages using a Service

 

Additional Resources

 

If you have questions, issues, or need additional information, refer to:

 

ResourceLink
CommunityDeveloper Community Forum
SupportTwilio Extension Help Center
Version history
Last update:
‎Nov 15, 2022 04:42 PM
Updated by:
Labels (2)
Attachments
Contributors