Skip to main content

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

  1. Open Telegram and message @BotFather.
  2. Send /newbot, follow the prompts, and copy the Bot Token (format: 123456789:ABCdefGHIjklMNOpqrSTUvwxYZ).
  3. Add the bot to your target chat/group. For channels, add it as an administrator.
  4. 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).
  5. In WordPress, edit your form > Actions tab > Add Action > Send to Telegram.
  6. 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

  1. On successful submission, the action validates the bot token format.
  2. Builds the message (auto-generated or custom with variable replacement).
  3. POSTs to https://api.telegram.org/bot{TOKEN}/sendMessage with the chat ID and HTML message.
  4. The request times out after 15 seconds.
  5. Returns true on success, false on 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 getUpdates endpoint to verify.