TGM Expert supports multi-channel messaging including SMS, WhatsApp, Telegram, Slack, Discord, and more. Unlike email, messaging providers are not enabled by default and must be explicitly configured.
Table of Contents¶
- Overview
- Supported Channels
- Supported Providers
- Configuration
- Sending Messages
- Admin API
- Provider Setup Guides
- Best Practices
Overview¶
Key Features¶
- 8 Message Channels - SMS, WhatsApp, Telegram, Slack, Discord, Viber, Signal, Facebook Messenger
- 12 Providers - Twilio, Vonage, AWS SNS, Telegram Bot, Slack API, and more
- Per-Company Configuration - Each company can have its own providers
- Channel-Specific Providers - Different providers for different channels
- Media Support - Send images, documents, and rich content
- Template Messages - WhatsApp Business API template support
Key Differences from Email¶
| Aspect | Messaging | |
|---|---|---|
| Default enabled | Yes | No |
| System fallback | Yes (SendGrid) | No |
| Provider required | Optional | Required |
| Configuration | Optional | Mandatory |
Supported Channels¶
| Channel | Code | Description | Media Support |
|---|---|---|---|
| SMS | sms |
Short Message Service | No |
whatsapp |
WhatsApp messaging | Yes | |
| Telegram | telegram |
Telegram messaging | Yes |
| Slack | slack |
Slack workspaces | Yes |
| Discord | discord |
Discord servers | Yes |
| Viber | viber |
Viber messaging | Yes |
| Signal | signal |
Signal messaging | Yes |
| Facebook Messenger | facebook_messenger |
Meta Messenger | Yes |
Supported Providers¶
Provider Overview¶
| Provider | SMS | Telegram | Slack | Discord | Viber | Messenger | |
|---|---|---|---|---|---|---|---|
| Twilio | ✓ | ✓ | - | - | - | - | - |
| Vonage (Nexmo) | ✓ | ✓ | - | - | - | ✓ | ✓ |
| AWS SNS | ✓ | - | - | - | - | - | - |
| Plivo | ✓ | - | - | - | - | - | - |
| MessageBird | ✓ | ✓ | - | - | - | - | - |
| Sinch | ✓ | ✓ | - | - | - | - | - |
| ClickSend | ✓ | - | - | - | - | - | - |
| Infobip | ✓ | ✓ | ✓ | - | - | ✓ | - |
| Meta WhatsApp | - | ✓ | - | - | - | - | ✓ |
| Telegram Bot | - | - | ✓ | - | - | - | - |
| Slack API | - | - | - | ✓ | - | - | - |
| Discord Bot | - | - | - | - | ✓ | - | - |
Provider Details¶
Twilio¶
- Best for: SMS and WhatsApp
- Features: Global coverage, phone number provisioning, delivery reports
- Pricing: Pay-per-message
- Website: twilio.com
Vonage (Nexmo)¶
- Best for: Multi-channel messaging
- Features: SMS, WhatsApp, Viber, Facebook Messenger
- Pricing: Pay-per-message
- Website: vonage.com
AWS SNS¶
- Best for: High-volume SMS at scale
- Features: Cost-effective, integrates with AWS ecosystem
- Pricing: Very low per-message cost
- Website: aws.amazon.com/sns
Telegram Bot¶
- Best for: Telegram notifications
- Features: Free, rich media support, bot commands
- Pricing: Free
- Website: core.telegram.org/bots
Slack API¶
- Best for: Team notifications
- Features: Channels, threads, rich formatting
- Pricing: Free (part of Slack subscription)
- Website: api.slack.com
Discord Bot¶
- Best for: Community notifications
- Features: Server channels, embeds, rich content
- Pricing: Free
- Website: discord.com/developers
Configuration¶
Creating a Provider Configuration¶
curl -X POST https://api.tgm-expert.com/api/admin/messaging-providers \
-H "Authorization: Bearer $JWT_TOKEN" \
-H "Content-Type: application/json" \
-d '{
"name": "Company Twilio SMS",
"providerType": "TWILIO",
"primaryChannel": "SMS",
"companyId": 1,
"accountSid": "ACxxxxxxxxxxxxxxxxx",
"authToken": "your_auth_token",
"senderId": "+15551234567",
"activate": true
}'
Provider Configuration Fields¶
Common Fields¶
| Field | Type | Required | Description |
|---|---|---|---|
name |
string | Yes | Configuration name |
providerType |
string | Yes | Provider type code |
primaryChannel |
string | Yes | Primary channel (SMS, WHATSAPP, etc.) |
companyId |
number | No | Company ID (null for system) |
senderId |
string | No | Default sender ID/phone |
senderName |
string | No | Sender display name |
isActive |
boolean | No | Active status |
notes |
string | No | Admin notes |
Twilio¶
{
"providerType": "TWILIO",
"accountSid": "ACxxxxxxxxxxxxxxxxx",
"authToken": "your_auth_token",
"senderId": "+15551234567"
}
Vonage¶
{
"providerType": "VONAGE",
"apiKey": "your_api_key",
"apiSecret": "your_api_secret",
"senderId": "YourBrand"
}
AWS SNS¶
{
"providerType": "AWS_SNS",
"awsAccessKeyId": "AKIAIOSFODNN7EXAMPLE",
"awsSecretAccessKey": "wJalrXUtnFEMI/K7MDENG/bPxRfiCYEXAMPLEKEY",
"awsRegion": "us-east-1"
}
Telegram Bot¶
{
"providerType": "TELEGRAM_BOT",
"telegramBotToken": "123456789:ABCdefGHIjklMNOpqrSTUvwxYZ",
"telegramDefaultChatId": "123456789"
}
Slack API¶
{
"providerType": "SLACK_API",
"slackBotToken": "xoxb-your-bot-token",
"slackDefaultChannel": "#alerts"
}
Discord Bot¶
{
"providerType": "DISCORD_BOT",
"discordBotToken": "your-bot-token",
"discordDefaultChannelId": "123456789012345678"
}
Meta WhatsApp Business¶
{
"providerType": "META_WHATSAPP",
"authToken": "your_access_token",
"whatsappBusinessAccountId": "123456789",
"whatsappPhoneNumberId": "987654321"
}
Sending Messages¶
Using MessagingService (Programmatic)¶
@Service
@RequiredArgsConstructor
public class AlertNotificationService {
private final MessagingService messagingService;
public void sendAlertNotification(User user, Alert alert) {
// Set company context
MessagingService.setCurrentCompanyId(user.getCompany().getId());
try {
// Send SMS
if (user.getPhoneNumber() != null) {
messagingService.sendSms(
user.getPhoneNumber(),
"Alert: " + alert.getMessage()
);
}
// Send Telegram (if configured)
if (user.getTelegramChatId() != null) {
messagingService.sendTelegram(
user.getTelegramChatId(),
"🚨 *Alert*: " + alert.getMessage()
);
}
// Send Slack
messagingService.sendSlack(
"#alerts",
"Alert triggered: " + alert.getMessage()
);
} finally {
MessagingService.clearCurrentCompanyId();
}
}
}
MessagingService Methods¶
// SMS
messagingService.sendSms(phoneNumber, message);
messagingService.sendSms(phoneNumber, message, senderId);
// WhatsApp
messagingService.sendWhatsApp(phoneNumber, message);
messagingService.sendWhatsAppWithMedia(phoneNumber, caption, mediaUrl, mediaType);
// Telegram
messagingService.sendTelegram(chatId, message);
messagingService.sendTelegramWithMedia(chatId, caption, mediaUrl, mediaType);
// Slack
messagingService.sendSlack(channel, message);
// Discord
messagingService.sendDiscord(channelId, message);
// Check availability
boolean available = messagingService.isChannelAvailable(MessageChannel.SMS);
String providerType = messagingService.getProviderType(MessageChannel.SMS);
Company-Specific Sending¶
// Send for specific company (bypasses ThreadLocal context)
messagingService.sendSmsForCompany(companyId, phoneNumber, message, senderId);
Admin API¶
Provider Types and Channels¶
# List all provider types
curl -X GET "https://api.tgm-expert.com/api/admin/messaging-providers/types" \
-H "Authorization: Bearer $JWT_TOKEN"
# List all channels
curl -X GET "https://api.tgm-expert.com/api/admin/messaging-providers/channels" \
-H "Authorization: Bearer $JWT_TOKEN"
Provider Management¶
| Method | Endpoint | Description |
|---|---|---|
| GET | /api/admin/messaging-providers/types |
List provider types |
| GET | /api/admin/messaging-providers/channels |
List channels |
| GET | /api/admin/messaging-providers/company/{id} |
List company configs |
| GET | /api/admin/messaging-providers/{id} |
Get config details |
| POST | /api/admin/messaging-providers |
Create config |
| PUT | /api/admin/messaging-providers/{id} |
Update config |
| DELETE | /api/admin/messaging-providers/{id} |
Delete config |
| POST | /api/admin/messaging-providers/{id}/activate |
Activate config |
| POST | /api/admin/messaging-providers/{id}/deactivate |
Deactivate config |
| POST | /api/admin/messaging-providers/{id}/test |
Test connection |
| POST | /api/admin/messaging-providers/{id}/test-message |
Send test message |
Testing Configuration¶
# Test provider connection
curl -X POST "https://api.tgm-expert.com/api/admin/messaging-providers/1/test" \
-H "Authorization: Bearer $JWT_TOKEN"
# Send test message
curl -X POST "https://api.tgm-expert.com/api/admin/messaging-providers/1/test-message?to=+15551234567" \
-H "Authorization: Bearer $JWT_TOKEN"
System Status¶
curl -X GET "https://api.tgm-expert.com/api/admin/messaging-providers/status" \
-H "Authorization: Bearer $JWT_TOKEN"
Response:
{
"data": {
"messagingEnabled": true,
"availableProviders": ["Twilio", "Vonage", "AWS SNS", "Telegram Bot", ...],
"availableChannels": ["SMS", "WhatsApp", "Telegram", "Slack", ...]
}
}
Provider Setup Guides¶
Twilio Setup¶
- Create Twilio Account
- Go to twilio.com
-
Sign up for an account
-
Get Credentials
- Navigate to Console Dashboard
-
Copy Account SID and Auth Token
-
Get Phone Number
- Go to Phone Numbers → Manage → Buy a Number
-
Purchase a number with SMS capability
-
For WhatsApp
- Go to Messaging → Try it Out → WhatsApp
-
Follow sandbox setup or apply for WhatsApp Business API
-
Configure in TGM Expert
{ "providerType": "TWILIO", "accountSid": "ACxxxxxxxxxxxxxxxxx", "authToken": "your_auth_token", "senderId": "+15551234567" }
Telegram Bot Setup¶
- Create Bot
- Open Telegram and search for @BotFather
- Send
/newbotcommand - Follow prompts to name your bot
-
Save the bot token provided
-
Get Chat ID
- Add your bot to a group or start a chat
- Send a message to the bot
- Visit
https://api.telegram.org/bot<TOKEN>/getUpdates -
Find the chat_id in the response
-
Configure in TGM Expert
{ "providerType": "TELEGRAM_BOT", "telegramBotToken": "123456789:ABCdefGHIjklMNOpqrSTUvwxYZ", "telegramDefaultChatId": "123456789" }
Slack Setup¶
- Create Slack App
- Go to api.slack.com/apps
- Click "Create New App"
-
Choose "From scratch"
-
Configure Bot
- Go to "OAuth & Permissions"
- Add Bot Token Scopes:
chat:write,chat:write.public - Install to Workspace
-
Copy Bot User OAuth Token
-
Configure in TGM Expert
{ "providerType": "SLACK_API", "slackBotToken": "xoxb-your-bot-token", "slackDefaultChannel": "#alerts" }
Discord Setup¶
- Create Discord Application
- Go to Discord Developer Portal
-
Click "New Application"
-
Create Bot
- Go to "Bot" section
- Click "Add Bot"
-
Copy the bot token
-
Invite Bot to Server
- Go to OAuth2 → URL Generator
- Select "bot" scope
- Select "Send Messages" permission
-
Use generated URL to invite bot
-
Get Channel ID
- Enable Developer Mode in Discord settings
-
Right-click channel → Copy ID
-
Configure in TGM Expert
{ "providerType": "DISCORD_BOT", "discordBotToken": "your-bot-token", "discordDefaultChannelId": "123456789012345678" }
Best Practices¶
1. Use Appropriate Channels¶
- SMS: Critical alerts, authentication codes
- WhatsApp: Customer communication, detailed notifications
- Telegram: Team notifications, automated reports
- Slack: Internal team communication
- Discord: Community updates
2. Handle Failures Gracefully¶
try {
messagingService.sendSms(phone, message);
} catch (Exception e) {
// Log error, don't fail the main operation
log.error("Failed to send SMS: {}", e.getMessage());
}
3. Respect Rate Limits¶
| Provider | Rate Limit |
|---|---|
| Twilio | 1 msg/second/number |
| Vonage | 30 msg/second |
| AWS SNS | 20 msg/second (default) |
| Telegram | 30 msg/second |
4. Use Company Context¶
Always set and clear the company context when sending messages:
MessagingService.setCurrentCompanyId(companyId);
try {
// Send messages
} finally {
MessagingService.clearCurrentCompanyId();
}
5. Test Before Production¶
Always test messaging configurations before enabling in production:
curl -X POST ".../messaging-providers/1/test-message?to=+15551234567"
6. Monitor Provider Health¶
Regularly check test results and failure counts in the admin UI.
Troubleshooting¶
Messages Not Sending¶
-
Check if messaging is enabled
messagingService.isMessagingEnabled(); // true/false -
Check channel availability
messagingService.isChannelAvailable(MessageChannel.SMS); -
Verify provider configuration
- Test connection via admin API
-
Check credentials are valid
-
Check company context
- Ensure
setCurrentCompanyId()is called - Verify company has active provider for channel
Invalid Credentials¶
- Verify API keys/tokens are correct
- Check for whitespace or encoding issues
- Ensure credentials have correct permissions
- Check if credentials have expired
Rate Limiting¶
- Implement queuing for bulk sends
- Add delays between messages
- Consider upgrading provider tier
- Distribute load across multiple numbers
Delivery Failures¶
- Verify recipient number format (E.164 for SMS)
- Check if number can receive messages
- Verify sender ID is valid for destination country
- Review provider's delivery reports