Clinic Webhooks API
Endpoints for handling webhook integrations within the clinic system.
Twilio SMS Webhook
Handle incoming SMS messages from Twilio.
Endpoint: POST /v1/clinic/webhooks/twilio/sms
Authentication: Not required (webhook endpoint)
Request Body Parameters
This endpoint receives webhook data from Twilio when SMS messages are received. The parameters are automatically provided by Twilio’s webhook system.
| Parameter | Type | Required | Description |
|---|---|---|---|
MessageSid | string | Yes | Unique identifier for the message |
From | string | Yes | Phone number that sent the message |
To | string | Yes | Phone number that received the message |
Body | string | Yes | Content of the SMS message |
NumMedia | string | No | Number of media files attached |
MediaUrl0 | string | No | URL of first media attachment |
MediaContentType0 | string | No | Content type of first media attachment |
Example Webhook Payload
POST /v1/clinic/webhooks/twilio/sms HTTP/1.1
Content-Type: application/x-www-form-urlencoded
MessageSid=SM1234567890abcdef&From=%2B15551234567&To=%2B15559876543&Body=Hello%20from%20patient&NumMedia=0Response Format
The webhook endpoint returns a TwiML response to control Twilio’s behavior:
<?xml version="1.0" encoding="UTF-8"?>
<Response>
<Message>Thank you for your message. We will respond shortly.</Message>
</Response>Webhook Security
Twilio Signature Validation
Twilio webhooks include a signature header for security validation:
X-Twilio-Signature: base64_encoded_signatureThe system automatically validates this signature to ensure the webhook is from Twilio.
Webhook Processing
When an SMS webhook is received, the system:
- Validates the Twilio signature
- Identifies the patient based on the phone number
- Processes the message content for keywords or commands
- Routes the message to appropriate handlers
- Sends an automatic response if configured
- Logs the interaction for audit purposes
Common SMS Commands
Patients can send specific keywords to trigger automated responses:
HELP- Get help informationSTOP- Unsubscribe from SMS notificationsSTART- Re-subscribe to SMS notificationsCONFIRM- Confirm an appointmentCANCEL- Request appointment cancellationRESCHEDULE- Request appointment rescheduling
Error Handling
Invalid Phone Number
If the sender’s phone number is not found in the system:
<?xml version="1.0" encoding="UTF-8"?>
<Response>
<Message>We don't recognize this phone number. Please contact our office directly.</Message>
</Response>System Error
If there’s a system error processing the webhook:
<?xml version="1.0" encoding="UTF-8"?>
<Response>
<Message>We're experiencing technical difficulties. Please try again later or call our office.</Message>
</Response>Webhook Configuration
Twilio Setup
To configure Twilio webhooks:
- Set the webhook URL in your Twilio console
- Configure the HTTP method as POST
- Ensure the webhook URL is publicly accessible
- Set up signature validation for security
Required Twilio Configuration
Webhook URL: https://your-api-domain.com/v1/clinic/webhooks/twilio/sms
HTTP Method: POST
Content Type: application/x-www-form-urlencodedNotes
- Webhook endpoints do not require authentication as they use signature validation
- All incoming SMS messages are logged for compliance and audit purposes
- Automatic responses can be customized based on clinic preferences
- The system handles both text messages and media attachments (images, documents)
- Rate limiting may be applied to prevent abuse
- Webhook failures are automatically retried by Twilio with exponential backoff