Send voice and text messages with Twilio.
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
- 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.
- In the lower-left side of Composer, click Import/Export, then Import.
- In the Import From File pop-up, under Import Option select Extension from the drop-down, then click Browse.
- Navigate to the .zip file you downloaded.
- 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.
- Start on the Browse, folder icon tab on the far left of ThingWorx Composer.
- Under the Modeling tab, hover over Things then click the + button.
- Type twilio-connector in the Name field.
NOTE: This name, with matching capitalization, is required for the example code which will be entered in a later step.
- If Project is not already set, click the + in the Project text box and select the PTCDefaultProject.
- In the Base Thing Template text box, click the + and select Twilio.
- 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.
- Open the twilio-connection Thing if it is not already open.
- Click on the Configuration tab.
- Click the pencil icon next to the authToken field.
- Copy your AUTH TOKEN from your Twilio account dashboard.
- Paste your AUTH TOKEN into the New Password and Confirm Password fields under authToken.
- Click the pencil icon next to the accountSID field.
- Copy your ACCOUNT SID from your Twilio account dashboard, and paste it into the New Password and Confirm Password fields under accountSID.
- Follow the steps in your Twilio account dashboard to get a trial phone number.
- Copy your PHONE NUMBER from your Twilio account dashboard, and paste it into the callerID field.
- 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.
- Click the Services tab at the top of the twilio-connector Thing.
- Click the link to the SendSMSMessage Service in the Services Name column.
- Enter a phone number in the to field.
- Enter a test message in the text field.
- Click the Execute button to send the SMS message.
- The service should execute without any errors within a couple of seconds and the phone number will receive your message.
- 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
- Download and unzip the attached sample Things_freezer.zip.
- In Composer, click the Import/Export icon at the lower-left of the page.
- Click Import.
- Leave all default values and click Browse to select the Things_freezer.twx file that you just downloaded.
- Click Open, then Import.
- When you see the success message, click Close.
Explore Imported Entities
- Navigate to the freezer Thing by using the search bar at the top of the screen.
- Click the Subscriptions tab.
- Click reportFreezer under Name.
- Open the Subscription Info tab.
- Select the Enabled checkbox.
- Click Done then Save to save any changes.
Verify Data Simulation
- Open the freezer Thing and click Properties and Alerts tab.
- Click the Set value in the alertedPhone Property row, in the Value column.
- Enter a phone number to receive the SMS alert, then click the Check icon above where you entered the phone number.
- Click the pencil icon in the temp Property row, in the Value column.
- Enter a value for the temp property that is greater than 30, and click the Check icon.
- 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
If you have questions, issues, or need additional information, refer to: