Real-time SMS/WhatsApp alerts using Twilio

Loading

Integrating Twilio with Microsoft Power Pages enables you to send real-time alerts via SMS or WhatsApp when users submit forms, upload documents, or perform any predefined actions. Twilio offers reliable global messaging APIs, making it a powerful tool for instant user engagement.

In this guide, you’ll learn how to:

  • Trigger messages from Power Pages submissions
  • Set up Twilio SMS/WhatsApp alerts using Power Automate
  • Secure and scale the integration for enterprise-grade use

Use Cases

  • OTPs for user registration or authentication
  • Confirmation messages after form submissions
  • Alerts to admins for new submissions or file uploads
  • Customer support workflows and appointment reminders

Architecture

mathematicaCopyEditUser → Power Pages Form → Dataverse → Power Automate → Twilio API → SMS/WhatsApp

Prerequisites

  1. Microsoft Power Pages Site
  2. Dataverse Table (e.g., for registrations)
  3. Power Automate Access
  4. Twilio Account
    • SMS number / WhatsApp-enabled number
    • Verified sender (for WhatsApp sandbox)
    • Auth Token and Account SID

Step-by-Step Integration


Step 1: Setup Your Twilio Account

  1. Go to https://www.twilio.com
  2. Sign up / log in
  3. Get your:
    • Account SID
    • Auth Token
    • Phone Number (SMS or WhatsApp enabled)

For WhatsApp, follow the Twilio Sandbox setup:
Messaging → Try It Out → Send a WhatsApp Message → Join the sandbox


Step 2: Create a Dataverse Table

  1. In Power Apps, create a table like UserMessages
  2. Add columns:
    • Full Name
    • Phone Number (Text)
    • Message Sent (Yes/No)
    • Channel (SMS/WhatsApp)
  3. Create a form in Power Pages bound to this table

Step 3: Configure Power Pages Form

  • Navigate to Power Pages Studio
  • Add a Basic Form bound to UserMessages
  • Publish your site
  • Ensure the phone number input is valid (country code included)

Step 4: Create Power Automate Flow to Send SMS/WhatsApp

A. Trigger

  • Type: Automated Cloud Flow
  • Trigger: When a row is added (Dataverse)
  • Table Name: UserMessages
  • Scope: Organization

B. Compose Message Content (Optional)

  • Add Compose action:
plaintextCopyEditHi @{triggerOutputs()?['body/FullName']}, thanks for contacting us. We'll get back to you shortly!

C. Send Message via Twilio API

  • Add an HTTP action
For SMS
  • Method: POST
  • URL:
https://api.twilio.com/2010-04-01/Accounts/{AccountSID}/Messages.json
  • Authentication: Basic
    • Username: AccountSID
    • Password: AuthToken
  • Headers:
{
"Content-Type": "application/x-www-form-urlencoded"
}
  • Body:
To=+91XXXXXXXXXX
&From=+1XXXXXXX (Twilio Number)
&Body=Hi [Name], your form is received!
For WhatsApp
  • Same as SMS, but:
To=whatsapp:+91XXXXXXXXXX  
From=whatsapp:+1XXXXXXXXXX

D. Update the Record

  • Add Update a row (Dataverse)
  • Mark Message Sent = true

Optional: Add Conditions Based on Channel

If your table has a column Channel, use a Condition:

  • If Channel = WhatsApp → use WhatsApp API
  • Else → use SMS API

Security and Governance

  • Store Twilio Auth tokens in Azure Key Vault or Power Automate environment variables
  • Use phone number validation in Power Pages with RegEx
  • Limit message frequency (no spam)
  • Monitor API usage via Twilio Console

Best Practices

  • Always prepend +CountryCode to phone numbers (e.g., +91)
  • Use WhatsApp Templates for pre-approved messages
  • For production, use verified numbers (especially WhatsApp)
  • Add logging in Power Automate for error tracking
  • Implement retry logic if messages fail

Testing

  1. Submit a form on your Power Pages site
  2. Open your mobile device
  3. Check for real-time message from Twilio (SMS or WhatsApp)
  4. Review Twilio dashboard for delivery status

Real-Life Scenarios

ScenarioMessage
OTP/Verification“Your code is 5729. Do not share it with anyone.”
Appointment Confirmed“Hi James, your appointment is confirmed for 3:00 PM on April 26.”
Submission Received“Hello Riya, we have received your document. Thank you!”
Admin Alert“New inquiry submitted by Paul at 10:15 AM”

Common Errors & Fixes

IssueSolution
Message not sentCheck Twilio Auth Token, From/To format
Invalid WhatsApp numberJoin WhatsApp Sandbox or use approved senders
Rate limitingMonitor Twilio account usage, increase limits
Power Automate errorReview Flow Run history for status codes (401, 403, 500)

Advanced Extensions

  • Send Bulk Messages using Apply to each in Power Automate
  • Store message logs in SharePoint or Dataverse
  • Integrate with Dynamics CRM to automate lead follow-ups
  • Set expiry timers for OTPs using scheduled flows
  • Two-way chat using Twilio Studio and Azure Bot Framework

Leave a Reply

Your email address will not be published. Required fields are marked *