Skip to main content

Telegram Notifications

Overview

After a successful form submission (all verification passed, CSV stored), a notification is sent to a Telegram chat via the Bot API. This runs alongside the email notification and does not consume Gmail storage.

The contact form uses its own bot and chat, separate from the newsletter subscribe form notification.

Trigger source: the Telegram notification is sent by the contact form snippet on WordPress (GC-SG-M8) immediately after the CSV row is saved — it is not triggered by Zammad. Zammad only receives the ticket via the REST API; it does not send these notifications. (Zammad-native Telegram/webhook triggering was considered but not adopted.)

Configuration

SettingOption NameDefault
Bot tokenopshell_contact_telegram_bot_token
Chat IDopshell_contact_telegram_chat_id

Both are stored as WordPress options (never hardcoded in the snippet). The bot must be added to the target chat (direct chat or group) and promoted to admin to reliably capture group chat IDs.

Channel separation: contact-form notifications and subscriber notifications use independent bots/chats:

  • Contact form → opshell_contact_telegram_bot_token / opshell_contact_telegram_chat_id (support bot, Support_notification group)
  • Subscribe form → opshell_subscribe_telegram_bot_token / opshell_subscribe_telegram_chat_id (main bot, subscriber_notification group)

Bot Setup

  1. Create a bot via @BotFather (/newbot) and save the HTTP API token.
  2. Add the bot to a chat/group.
  3. Resolve the chat ID from https://api.telegram.org/bot<TOKEN>/getUpdates after sending a message to the bot or mentioning it in the group.
  4. Store as options:
    • wp option add opshell_contact_telegram_bot_token "<TOKEN>"
    • wp option add opshell_contact_telegram_chat_id "<CHAT_ID>"

Sending

opshell_send_contact_telegram() uses wp_remote_post() to the Bot API sendMessage endpoint:

wp_remote_post(
"https://api.telegram.org/bot" . $token . "/sendMessage",
array(
"body" => array(
"chat_id" => $chat_id,
"text" => $text,
"parse_mode" => "HTML",
"disable_web_page_preview" => "true",
),
"timeout" => 15,
)
);

The message uses HTML parse_mode with the same fields as the email template:

  • Timestamp, IP Address, Name, Email, Subject, Message
  • Reoon verification results (status, safe_to_send, mode, score)
  • Footer: "Saved to messages.csv after Reoon power verification."

Safety

  • Message body is truncated to 2000 characters to stay within the 4096-character Bot API limit.
  • Fields are escaped with htmlspecialchars(..., ENT_QUOTES) for HTML parse mode.
  • If the token or chat ID options are empty, the function returns false without sending.
  • The bot token is a secret — keep it in the option, never in the repo or docs.

Deactivation

The email notification can later be disabled by removing the opshell_send_contact_notification_email() call in the snippet while keeping the Telegram call.