Telegram Integration
Send a message to a Telegram chat or group via a bot when a form is submitted.
Action type: telegram
Class: Core_Forms\Actions\Telegram
Source: src/actions/class-telegram.php
Setup
- Open Telegram and message @BotFather.
- Send
/newbot, follow the prompts, and copy the Bot Token (format:123456789:ABCdefGHIjklMNOpqrSTUvwxYZ). - Add the bot to your target chat/group. For channels, add it as an administrator.
- Get your Chat ID: message @userinfobot for personal chats, or use the bot API to get group IDs (group IDs are negative numbers like
-1001234567890). - In WordPress, edit your form > Actions tab > Add Action > Send to Telegram.
- Enter the Bot Token and Chat ID.
Settings Reference
| Setting | Required | Default | Description |
|---|---|---|---|
| Bot Token | Yes | -- | Token from @BotFather (digits:alphanumeric) |
| Chat ID | Yes | -- | User, group, or channel ID |
| Message | No | All fields | Custom message template with HTML formatting |
Token Validation
The bot token format is validated with a regex pattern: ^\d+:[A-Za-z0-9_-]+$. This prevents URL manipulation attacks. If the token does not match this format, the action returns false without making any API call.
Message Variables
Use these variables in the Message field:
[all:label]-- all submitted fields as "Label: Value" pairs[field_name]-- value of any form field by its name attribute
HTML Formatting
Telegram messages are sent with parse_mode: HTML. Supported tags in custom messages:
<b>bold</b>-- bold text<i>italic</i>-- italic text<code>monospace</code>-- inline code<a href="url">link</a>-- hyperlink
Auto-Generated Message
When the Message field is left empty, all fields are sent with bold labels:
<b>Contact Form</b>
<b>Name:</b> Jane Smith
<b>Email:</b> jane@example.com
<b>Message:</b> I'd like to learn more.
Example: Custom Message
<b>New Lead</b>
Name: [NAME]
Email: [EMAIL]
Company: [company]
<i>Submitted via [CF_FORM_TITLE]</i>
How It Works
- On successful submission, the action validates the bot token format.
- Builds the message (auto-generated or custom with variable replacement).
- POSTs to
https://api.telegram.org/bot{TOKEN}/sendMessagewith the chat ID and HTML message. - The request times out after 15 seconds.
- Returns
trueon success,falseon failure or invalid configuration.
Troubleshooting
- Bot token rejected: Ensure the token matches the format
digits:alphanumeric. Re-copy from @BotFather. - Chat not found: The bot must be added to the group/channel before it can send messages. For groups, the bot needs to be a member. For channels, it needs admin rights.
- No message received: Check that the Chat ID is correct. Group IDs are negative. Use the Telegram Bot API
getUpdatesendpoint to verify.