How to Send Trello Notifications to Telegram Group Topic Using PHP Webhooks
Mahbub Hasan Imon

Mahbub Hasan Imon @mhimon

Location:
Pabna, Dhaka, Bangladesh
Joined:
Oct 16, 2018

How to Send Trello Notifications to Telegram Group Topic Using PHP Webhooks

Publish Date: Jul 31
1 0

Trello is a great tool for task management, but its notification system is often limited when working with real-time team collaboration. If you're already using Telegram for team discussions, wouldn't it be great to get Trello notifications directly into a Telegram group topic?

In this guide, you’ll learn how to set up a Trello webhook that sends live updates (like card creation, movement, and comments) to your Telegram group using a PHP script.

🛠 What You’ll Learn

  1. How to get your Trello API key and token
  2. How to create a Telegram bot and get your group/topic IDs
  3. How to set up a webhook to listen to Trello board activity
  4. How to use a PHP script to forward notifications to Telegram

🔑 Step 1: Get Your Trello API Key, Secret, and Token

To interact with the Trello API, you'll need an App Key and a Token.

🔗 Trello Power-Up Admin

Go to:
👉 https://trello.com/power-ups/admin

  1. Click Create a new Power-Up
  2. Name it and generate an App Key
  3. Save your API Key and API Secret
  4. Then go to this URL to generate your token:

https://trello.com/1/authorize?key=YOUR_API_KEY&name=TrelloToTelegram&expiration=never&response_type=token&scope=read,write

🧾 Step 2: Get Your Trello Board ID

You need the Board ID to create a webhook.

  1. Find your board short link (e.g. https://trello.com/b/7G08MJrU/project-name)
  2. Use this endpoint (replace key and token):

https://api.trello.com/1/boards/7G08MJrU?key=YOUR_API_KEY&token=YOUR_TOKEN

It returns JSON like:

{
"id": "63f8c1c1234567890abcdef1",
"name": "Project Board",
...
}

Copy the id — that’s your full Board ID.

🤖 Step 3: Create a Telegram Bot & Get Topic ID

  1. Go to @BotFather
  2. Use /newbot to create a bot
  3. Copy the bot token
  4. Add the bot to your Telegram group and make it an admin
  5. Enable topics in your group (Group Settings > Manage Topics)

Now send any message to your desired topic.

Get your topic ID (message_thread_id):

Visit https://api.telegram.org/botYOUR_BOT_TOKEN/getUpdates

Look for:

"message_thread_id": 1253

Save the topic ID and your group’s chat_id (like -1001842173606)

🧰 Step 4: Create the PHP Webhook Handler

Create a file like trello-to-telegram.php and upload it to your hosting.

Here’s a complete, production-ready script:

`<?php
$telegramToken = 'YOUR_TELEGRAM_BOT_TOKEN';
$chatId = '-100YOUR_GROUP_ID';
$topicId = 1253; // Topic ID in Telegram

if ($_SERVER['REQUEST_METHOD'] === 'GET' || $_SERVER['REQUEST_METHOD'] === 'HEAD') {
http_response_code(200);
exit;
}

$input = file_get_contents('php://input');
$data = json_decode($input, true);

file_put_contents(DIR . '/log.txt', date('Y-m-d H:i:s') . " " . $input . PHP_EOL, FILE_APPEND);

if (!isset($data['action'])) {
http_response_code(400);
echo 'Invalid webhook';
exit;
}

$actionId = $data['action']['id'] ?? '';
$cacheFile = DIR . '/actions_cache.txt';
$processed = file_exists($cacheFile) ? explode("\n", trim(file_get_contents($cacheFile))) : [];

if (in_array($actionId, $processed)) {
http_response_code(200);
exit;
}

file_put_contents($cacheFile, $actionId . "\n", FILE_APPEND);

$allowedActions = ['createCard', 'commentCard', 'updateCard'];
$action = $data['action'];
$actionType = $action['type'] ?? '';

if (!in_array($actionType, $allowedActions)) {
http_response_code(200);
exit;
}

$user = $action['memberCreator']['fullName'] ?? 'Someone';
$cardName = $action['data']['card']['name'] ?? '';
$cardShortLink = $action['data']['card']['shortLink'] ?? '';
$cardUrl = $cardShortLink ? "https://trello.com/c/$cardShortLink" : '';
$boardName = $action['data']['board']['name'] ?? '';
$message = "📋 Board: {$boardName}\n";

if ($actionType === 'createCard') {
$message .= "🆕 $user created a card:\n*{$cardName}*";

} elseif ($actionType === 'commentCard') {
$comment = $action['data']['text'] ?? '[No comment]';
$commentUrl = $cardShortLink ? "https://trello.com/c/$cardShortLink#comment-{$actionId}" : '';
$message .= "💬 $user commented on {$cardName}:\n\"{$comment}\"\n🔗 View Comment";

} elseif ($actionType === 'updateCard') {
$fromList = $action['data']['listBefore']['name'] ?? null;
$toList = $action['data']['listAfter']['name'] ?? null;

if ($fromList && $toList) {
    $message .= "🔄 *$user* moved *{$cardName}* from _{$fromList}_ to _{$toList}_";
} else {
    $message .= "✏️ *$user* updated *{$cardName}*";
}
Enter fullscreen mode Exit fullscreen mode

}

if ($cardUrl) {
$message .= "\n🔗 View Card";
}

$sendUrl = "https://api.telegram.org/bot$telegramToken/sendMessage";
$params = [
'chat_id' => $chatId,
'message_thread_id' => $topicId,
'text' => $message,
'parse_mode' => 'Markdown',
];
$options = [
'http' => [
'header' => "Content-type: application/json",
'method' => 'POST',
'content' => json_encode($params),
'timeout' => 10,
],
];
$context = stream_context_create($options);
file_get_contents($sendUrl, false, $context);

http_response_code(200);
echo 'OK';
?>`

🔗 Step 5: Create the Webhook in Trello

Use the Trello API to create a webhook:

curl -X POST "https://api.trello.com/1/webhooks?key=YOUR_API_KEY&token=YOUR_TOKEN" \
-H "Content-Type: application/json" \
-d '{
"description": "Trello to Telegram",
"callbackURL": "https://yourdomain.com/trello-to-telegram.php",
"idModel": "YOUR_BOARD_ID"
}'

✅ If it responds with "active": true, your webhook is working.

🔍 Logging and Debugging

To debug or view logs:

  1. Check log.txt to see incoming payloads
  2. Check actions_cache.txt to avoid duplicate alerts
  3. Use getUpdates API in Telegram to inspect recent messages:

https://api.telegram.org/botYOUR_BOT_TOKEN/getUpdates

✅ Final Result

Whenever someone:

  1. Creates a card
  2. Moves a card
  3. Comments on a card

Your Telegram topic gets an instant notification. 🔔

👋 Conclusion

This setup is simple yet powerful for connecting Trello boards to Telegram using webhooks and plain PHP. You can customize it further to support checklist items, due dates, or even button-based interactions.

Comments 0 total

    Add comment