Send Message API¶
Overview¶
This endpoint allows you to send messages and notifications to users in your app. It supports text-only messages, messages with images, and messages with both images and URLs. This is the same endpoint used for sending reminder notifications.
Endpoint¶
URLs:
- Development:
https://<your-server-domain>/api/send-message - Production:
https://<your-server-domain>/api/send-message
Method: POST
Content-Type: application/json
Use Cases¶
- Text-only message: Send a simple text message
- Text + Image message: Send text accompanied by an image
- Text + Image + URL message: Send text with both an image and a URL link
- Reminder notifications: Send reminders that display as notifications in the app
Required Fields¶
| Field | Type | Description | Example |
|---|---|---|---|
to_id |
string | Unique identifier of the recipient user in your system |
"user_abc123" |
message_body |
string | Text content of the message | "Hello, how are you today?" |
message_type |
string | Type: "message" (text), "image", or "error" |
"message" |
Optional Fields¶
| Field | Type | Description | Example |
|---|---|---|---|
message_sid |
string | Optional unique message identifier for tracking (will be echoed back in response if provided) |
"msg_sid_12345" |
image_url |
string | Publicly accessible image URL to accompany the text | "https://example.com/images/offer_banner.jpg" |
Example Requests¶
Text-Only Message¶
Text + Image Message¶
{
"to_id": "user_abc123",
"message_body": "Check out this healthy recipe!",
"image_url": "https://example.com/images/healthy_recipe.jpg"
}
Text + Image + URL Message¶
{
"to_id": "user_abc123",
"message_body": "Special discount on premium membership!",
"image_url": "https://example.com/images/discount_banner.jpg",
"url": "https://example.com/upgrade-premium"
}
Reminder Notification¶
{
"to_id": "user_abc123",
"message_body": "Time for your evening meal! Remember to log it in your nutrition tracker."
}
Response¶
Success (200 OK):
{
"status": "success",
"message": "Message sent successfully",
"message_id": "msg_12345",
"message_sid": "msg_sid_from_request",
"message_type": "message",
"timestamp": "2023-12-18T15:30:00Z"
}
Error Responses¶
| Code | Description | Example |
|---|---|---|
| 400 Bad Request | Missing required fields or invalid data | {"error": "Missing required field: to_id"} |
| 404 Not Found | Recipient user not found | {"error": "User not found"} |
| 500 Internal Server Error | Server error | {"error": "Failed to send message"} |
Message Display¶
- In-App Messages: Messages appear in the user's message inbox within your app
- Notifications: Messages can be displayed as push notifications
- Reminders: Reminder messages appear as notifications in the app interface
Media Requirements¶
- Image URLs: Must be publicly accessible (no authentication required)
- Supported Formats:
.jpg,.jpeg,.png,.gif - File Size: Recommended maximum 5MB for optimal performance
- URLs: Must be valid HTTP/HTTPS URLs
Rate Limiting¶
- Per User: Maximum 100 messages per user per hour
- Global: Contact Rex Nutribot team for enterprise rate limits
Authentication¶
This endpoint requires authentication. Contact the Rex Nutribot team for specific authentication requirements for your custom domain.