Skip to content

feat: improve Telegram integration plugin - #111

Merged
devjain32 merged 2 commits into
corsairdev:mainfrom
theRizwan:feat/telegram-integration
Jun 2, 2026
Merged

devjain32 merged 2 commits into
corsairdev:mainfrom
theRizwan:feat/telegram-integration

Conversation

@theRizwan

Copy link
Copy Markdown
Contributor

Summary

This pull request improves the existing Telegram integration package so it remains consistent with the repository's plugin conventions and deployment expectations.

What changed

  • Added package-level README documentation with setup and usage examples
    • Fixed plugin webhook matching so valid Telegram update payloads are accepted even when no secret-token header is configured
    • Wired the declared Telegram auth configuration into the plugin definition

Validation

  • pnpm exec tsc -p packages/telegram/tsconfig.json --noEmit

Checklist

  • Keeps changes focused on the Telegram integration
  • - [x] Does not break existing endpoint or webhook types
  • - [x] Includes setup and usage documentation

@vercel

vercel Bot commented Apr 6, 2026 •

Copy link
Copy Markdown
Contributor

The latest updates on your projects. Learn more about Vercel for GitHub.

2 Skipped Deployments
Project Deployment Actions Updated (UTC)
docs Skipped Skipped Jun 2, 2026 6:05pm
www Skipped Skipped Jun 2, 2026 6:05pm

Request Review

@greptile-apps

greptile-apps Bot commented Apr 6, 2026

Copy link
Copy Markdown
Contributor

Greptile Summary

This PR improves the Telegram plugin in three ways: adds package-level README documentation, wires the previously declared telegramAuthConfig into the plugin definition (a correct fix), and updates pluginWebhookMatcher to remove a bug that prevented webhook routing when no secret token was configured. The README and auth-config fix are clean improvements, but the webhook matcher change over-corrects: it now accepts any request whose body contains update_id with no header guard, which conflicts with the repository-wide convention where every other plugin uses a service-specific HTTP header to guarantee uniqueness.

  • README (packages/telegram/README.md): new documentation covering authentication, installation, representative operations, and webhook behavior — accurate and well-structured.
  • authConfig wiring (packages/telegram/index.ts line 256): correctly wires the already-declared telegramAuthConfig into the returned plugin object — this was a genuine omission.
  • pluginWebhookMatcher change (packages/telegram/index.ts lines 237–251): fixes the real bug (header required even when no secret is configured) but removes the header check entirely rather than making it conditional. Every other plugin in the repository (zoom, stripe, github, slack, discord, figma, typeform, jira, trello, sentry, etc.) uses a service-specific HTTP header. After this change, Telegram is the only plugin that matches solely on body content, meaning any webhook whose JSON body contains an update_id field will be routed to the Telegram plugin.
  • try/catch wrapping: a good defensive addition that gracefully handles malformed JSON bodies without throwing.

Confidence Score: 4/5

Requires one targeted fix to the webhook matcher before merging; the auth-config wiring and README are safe.

The authConfig fix and README are clean improvements with no issues. The pluginWebhookMatcher change has a real P1 defect: it removes the Telegram-specific header check entirely, making it the least-specific matcher in the codebase. Any webhook body containing update_id will now route to this plugin, violating the uniqueness rule enforced across all other plugins. The fix is straightforward and localized.

packages/telegram/index.ts — specifically the pluginWebhookMatcher logic at lines 237–251

Important Files Changed

Filename Overview
packages/telegram/index.ts pluginWebhookMatcher now matches solely on body content, breaking the repo-wide header-based uniqueness convention and risking routing of unrelated webhooks; authConfig wiring and try/catch are correct improvements
packages/telegram/README.md New documentation file — accurate, well-structured, covers auth, setup, representative operations, and webhook behavior

Sequence Diagram

sequenceDiagram
    participant TG as Telegram Server
    participant FW as Corsair Framework
    participant PM as pluginWebhookMatcher
    participant KB as keyBuilder
    participant WH as Webhook Handler

    TG->>FW: POST /webhook
    Note over TG,FW: body contains update_id<br/>optionally: X-Telegram-Bot-Api-Secret-Token header
    FW->>PM: pluginWebhookMatcher(request)
    Note over PM: NEW: checks only 'update_id' in body<br/>OLD: also required secret-token header presence
    alt update_id found in body
        PM-->>FW: true
        FW->>KB: keyBuilder(ctx, 'webhook')
        KB-->>FW: webhookSecret or key-manager value
        FW->>WH: dispatch to typed webhook handler
        WH-->>FW: response
        FW-->>TG: 200 OK
    else body missing update_id or parse error
        PM-->>FW: false
        FW-->>TG: skip plugin
    end
Loading

Reviews (1): Last reviewed commit: "feat: improve Telegram integration plugi..." | Re-trigger Greptile

Comment on lines 237 to 251
pluginWebhookMatcher: (request) => {
const body = typeof request.body === 'string'
? JSON.parse(request.body)
: request.body;

if (!body || typeof body !== 'object') {
try {
const body = typeof request.body === 'string'
? JSON.parse(request.body)
: request.body;

if (!body || typeof body !== 'object') {
return false;
}

return 'update_id' in body;
} catch {
return false;
}

const hasSignature = 'x-telegram-bot-api-secret-token' in request.headers;

return hasSignature && 'update_id' in body
},

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Webhook matcher is no longer uniquely Telegram-specific

After this change, pluginWebhookMatcher accepts any request whose body contains update_id, with no header check at all. Every other plugin in this repository uses a service-specific HTTP header to uniquely identify incoming webhooks:

  • Zoom → x-zm-signature
  • Stripe → stripe-signature
  • GitHub → x-github-event + x-hub-signature-256
  • Slack → x-slack-signature + x-slack-request-timestamp
  • Discord → x-signature-ed25519 + x-signature-timestamp
  • Sentry → sentry-hook-signature + sentry-hook-resource

Telegram is now the only plugin that matches purely on body content. Any third-party or internal webhook whose JSON body happens to include an update_id field will incorrectly match and be routed to the Telegram plugin.

The original bug was real: hasSignature required the X-Telegram-Bot-Api-Secret-Token header to exist, but Telegram only sends this header when a secret is registered on the webhook — deployments without a secret never matched. Removing the header check entirely is an over-correction.

A precise fix keeps uniqueness when a secret is configured and falls back gracefully when it is not:

pluginWebhookMatcher: (request) => {
    try {
        const body = typeof request.body === 'string'
            ? JSON.parse(request.body)
            : request.body;

        if (!body || typeof body !== 'object' || !('update_id' in body)) {
            return false;
        }

        // When a secret is configured, Telegram always sends the
        // X-Telegram-Bot-Api-Secret-Token header — require it so the
        // matcher stays uniquely Telegram-specific.
        if (options.webhookSecret) {
            return 'x-telegram-bot-api-secret-token' in request.headers;
        }

        // No secret configured: Telegram won't send the header,
        // so fall back to body-only matching.
        return true;
    } catch {
        return false;
    }
},

Rule Used: What: pluginWebhookMatcher in each plugin must b... (source)

@devjain32

Copy link
Copy Markdown
Contributor

Hi, @theRizwan! Thanks for this PR.

Please remove the Readme file that was generated. That shouldn't go into the main package. Also, I believe Greptile has pointed out an issue in the plugin webhook matcher. Please resolve that as well.

Thank you! We'll get this merged once those fixes are made.

@devjain32
devjain32 merged commit 7f7e182 into corsairdev:main Jun 2, 2026
2 checks passed
yuvrxj-afk pushed a commit to Vaibhav-Javre/corsair that referenced this pull request Sep 19, 2026

This branch was previously deployed

1 inactive deployment
Preview — 27d9fd42 Deployed Jun 2, 2026 by vercel[bot]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants