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

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

  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:

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

    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
    JSON
    • 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.txt to see incoming payloads
    • Check actions_cache.txt to avoid duplicate alerts
    • Use getUpdates API 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.

    Mahbub Hasan Imon
    Mahbub Hasan Imon

    I am a Software Developer specializing in using PHP, JavaScript, ReactJS, and WordPress. I have been working as a Developer for more than 5 years. I love to learn new things daily.

    Articles: 2

    Leave a Reply

    Your email address will not be published. Required fields are marked *