Overview
The Telegram integration uses the Bot API to deliver receipts as PDF documents. Each message includes:- PDF attachment with full order details
- Caption with restaurant name and timestamp
- Silent delivery (no sound notification)
Telegram receipts are sent asynchronously and never block the user experience. If delivery fails, the error is logged silently without affecting checkout.
Prerequisites
Before setting up the Telegram bot, ensure you have:- A Telegram account (mobile number required)
- Access to the Telegram app (iOS, Android, or Desktop)
- Your personal chat ID or a group/channel ID for receipts
Bot setup
Create a bot with BotFather
Open Telegram and search for @BotFather (official bot creation tool).Send the BotFather will respond with your bot token:Copy this token—you’ll need it in step 3.
/newbot command and follow the prompts:Bot usernames must end in “bot” and be globally unique. If your first choice is taken, try adding a number or your restaurant name.
Get your chat ID
Telegram requires a numeric chat ID to know where to send messages. There are two methods:Method 1: Personal chat (recommended for testing)Copy the
- Search for @userinfobot or @RawDataBot on Telegram
- Send any message to the bot
- It will reply with your user info, including your chat ID
Id value—this is your chat ID.Method 2: Group or channel- Create a group/channel for receipt tracking
- Add your bot as a member (search by username)
- Send a test message to the group
- Visit
https://api.telegram.org/bot<YOUR_BOT_TOKEN>/getUpdates - Look for
"chat":{"id":-123456789}in the response
Service implementation
The Telegram integration is handled bysrc/lib/services/telegramService.ts:
src/lib/services/telegramService.ts
Key features
Graceful degradation
Missing credentials cause a warning, not a crash. The app continues functioning normally.
Silent error handling
Network failures or API errors are logged but never shown to the user.
Multipart upload
Uses React Native’s FormData with proper MIME type for PDF attachments.
Timestamped filenames
Each PDF is named with a Unix timestamp to prevent filename collisions.
Bot API reference
TableOrder uses thesendDocument method to upload PDF files:
Request format
Response format
The
file_id can be used to forward the same PDF to other chats without re-uploading.Receipt content
PDFs are generated byexpo-print before being sent to Telegram. Each receipt includes:
- Header: Restaurant name and order type (Mesa/Delivery)
- Order details: Table number or delivery address
- Items: Product names, quantities, and prices
- Totals: Subtotal, service fee, shipping cost (if applicable), discount (if applicable), and final total
- Footer: Payment timestamp and order number
Advanced configuration
Using a private channel
For team-based receipt tracking, create a private Telegram channel:- Create a new channel (not a group)
- Add your bot as an administrator with Post Messages permission
- Forward any message from the channel to @userinfobot
- Copy the forwarded message’s chat ID (starts with
-100)
Multiple receipt destinations
To send receipts to multiple chats, modify the service to loop through an array of chat IDs:Custom caption formatting
Edit the caption intelegramService.ts to include additional details:
Troubleshooting
No receipts arriving in Telegram
Cause 1: Missing or invalid bot token Solution: VerifyEXPO_PUBLIC_TELEGRAM_BOT_TOKEN matches the token from BotFather. Tokens are case-sensitive and should not contain spaces.
Cause 2: Incorrect chat ID
Solution: Double-check the chat ID using @userinfobot. Remember that group IDs are negative.
Cause 3: Bot not added to group/channel
Solution: Ensure the bot is a member (for groups) or administrator (for channels) before sending messages.
”Chat not found” error
Cause: Bot has never interacted with the user Solution: Send any message to your bot directly (e.g.,/start). This initializes the chat and allows the bot to send messages.
PDF uploads fail with 400 Bad Request
Cause: Invalid file URI or corrupted PDF Solution: Check console logs for thepdfUri value. Ensure expo-print successfully generated the PDF before calling sendTicketToTelegram().
Rate limit errors (429 Too Many Requests)
Cause: Exceeding Telegram’s rate limit (30 messages/second) Solution: Implement exponential backoff or queue messages for batch processing. For typical restaurant volumes, this should never occur.Security considerations
Keep these best practices in mind:
- Never share your bot token publicly or commit it to git
- Use a dedicated bot for production (separate from test bots)
- Restrict group/channel access to authorized personnel only
- Monitor bot activity in @BotFather settings
- Revoke and regenerate tokens if compromised
- Consider using a private channel instead of personal chat for team access
API limits and pricing
Telegram Bot API is completely free with generous limits:| Limit Type | Threshold |
|---|---|
| Messages per second | 30 (per bot) |
| File size | 50 MB (per file) |
| Storage | Unlimited (files never expire) |
| API calls | Unlimited |
A restaurant processing 500 orders per day will send ~500 PDF messages—well below any practical limit.
Next steps
Environment setup
Review all configuration options
Mapbox configuration
Set up delivery routing