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
- How to get your Trello API key and token
- How to create a Telegram bot and get your group/topic IDs
- How to set up a webhook to listen to Trello board activity
- 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
- Click Create a new Power-Up
- Name it and generate an App Key
- Save your
API KeyandAPI Secret - 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.
- Find your board short link (e.g.
https://trello.com/b/7G08MJrU/project-name) - Use this endpoint (replace
keyandtoken):
https://api.trello.com/1/boards/7G08MJrU?key=YOUR_API_KEY&token=YOUR_TOKEN
It returns JSON like:
jsonCopyEdit{
"id": "63f8c1c1234567890abcdef1",
"name": "Project Board",
...
}JSONCopy the id β thatβs your full Board ID.
π€ Step 3: Create a Telegram Bot & Get Topic ID
- Go to @BotFather
- Use
/newbotto create a bot - Copy the bot token
- Add the bot to your Telegram group and make it an admin
- 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": 1253JSON- 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]($commentUrl)";
} 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}*";
}
}
if ($cardUrl) {
$message .= "\nπ [View Card]($cardUrl)";
}
$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';
PHPπ 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"
}'ShellScript
β
If it responds with "active": true, your webhook is working.
π Logging and Debugging
To debug or view logs:
- Check
log.txtto see incoming payloads - Check
actions_cache.txtto avoid duplicate alerts - Use
getUpdatesAPI in Telegram to inspect recent messages:
https://api.telegram.org/botYOUR_BOT_TOKEN/getUpdates
β Final Result
Whenever someone:
- Creates a card
- Moves a card
- 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.
Need help setting it up for your team? The ultraDevs team can help you integrate this into your own project.
