Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Telegram Bot - New Message Updates (Instant) - Add optional Chat ID prop #16071

Open
wants to merge 6 commits into
base: master
Choose a base branch
from

Conversation

michelle0927
Copy link
Collaborator

@michelle0927 michelle0927 commented Mar 27, 2025

Resolves #16050

Summary by CodeRabbit

  • New Features
    • Enhanced message processing with improved source validation to ensure events are handled only from the correct chat, reducing potential misrouted communications.
    • Added a new optional chatId property for better chat identification.
    • Introduced an asynchronous deploy method to manage chat ID retrieval and storage.
  • Chores
    • Updated component versions and upgraded dependencies for increased performance, stability, and compatibility.

Copy link

vercel bot commented Mar 27, 2025

The latest updates on your projects. Learn more about Vercel for Git ↗︎

3 Skipped Deployments
Name Status Preview Comments Updated (UTC)
docs-v2 ⬜️ Ignored (Inspect) Visit Preview Apr 1, 2025 4:03pm
pipedream-docs ⬜️ Ignored (Inspect) Apr 1, 2025 4:03pm
pipedream-docs-redirect-do-not-edit ⬜️ Ignored (Inspect) Apr 1, 2025 4:03pm

Copy link
Contributor

coderabbitai bot commented Mar 27, 2025

Important

Review skipped

Review was skipped due to path filters

⛔ Files ignored due to path filters (1)
  • pnpm-lock.yaml is excluded by !**/pnpm-lock.yaml

CodeRabbit blocks several paths by default. You can override this behavior by explicitly including those paths in the path filters. For example, including **/dist/** will override the default block on the dist directory, by removing the pattern from both the lists.

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Walkthrough

This pull request updates the Telegram Bot API component. In the package configuration, it bumps the version from 0.3.11 to 0.3.12 and updates the dependency on @pipedream/platform from ^0.9.0 to ^3.0.3. In the message updates source, it bumps the version from 0.1.5 to 0.1.6, adds an optional chatId property to the props, introduces a new asynchronous deploy method, and implements a conditional check in the processEvent method that prevents emitting events when the configured chatId does not match the incoming message’s chat ID.

Changes

File(s) Change Summary
components/.../package.json Bumped version from 0.3.11 to 0.3.12; updated dependency @pipedream/platform from ^0.9.0 to ^3.0.3
components/.../message-updates.mjs Bumped version from 0.1.5 to 0.1.6; added optional chatId prop in props; added async deploy method; added _getChatId and _setChatId methods; added conditional check in processEvent to filter messages

Sequence Diagram(s)

sequenceDiagram
    participant M as Incoming Message
    participant P as processEvent Method
    participant E as Event Emitter
    M->>P: Deliver message (with chat.id)
    P->>P: Check if 'chatId' is configured
    alt 'chatId' is configured
        P->>P: Compare configured chatId with message.chat.id
        alt chatId matches
            P->>E: Emit event
        else chatId mismatches
            P-->>M: Return early (ignore event)
        end
    else 'chatId' not configured
        P->>E: Emit event
    end
Loading

Assessment against linked issues

Objective Addressed Explanation
Add optional Chat ID prop for message filtering (#16050)

Suggested labels

User submitted

Suggested reviewers

  • GTFalcao
  • jcortes

Poem

Hoppity-hop, through code I scurry,
Updating versions in a flurry.
Dependencies leap high with each change,
And chatId checks keep events in range.
With twitching whiskers and joyful cheer,
This rabbit celebrates a PR so dear! 🐇✨


🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai plan to trigger planning for file edits and PR creation.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

luancazarine
luancazarine previously approved these changes Mar 31, 2025
Copy link
Collaborator

@luancazarine luancazarine left a comment

Choose a reason for hiding this comment

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

Hi @michelle0927, LGTM! Ready for QA!

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 0

🧹 Nitpick comments (2)
components/telegram_bot_api/sources/message-updates/message-updates.mjs (2)

22-31: Add error handling to the deploy hook.

The deploy hook properly initializes the chatId in the database and calls the base implementation. However, there's no error handling for the getChat API call, which could fail if the provided chatId is invalid.

Consider adding error handling:

async deploy() {
  if (this.chatId) {
-    const { id } = await this.telegramBotApi.sdk().getChat(this.chatId);
-    this._setChatId(id);
+    try {
+      const { id } = await this.telegramBotApi.sdk().getChat(this.chatId);
+      this._setChatId(id);
+    } catch (error) {
+      console.error(`Failed to get chat with ID ${this.chatId}: ${error.message}`);
+      // Consider whether to throw or just log the error
+    }
  }
  await base.hooks.deploy.call(this);
},

55-60: Use strict equality for chatId comparison.

The implementation correctly filters messages by chat ID, but the comparison uses loose equality (!=) instead of strict equality (!==), which could lead to unexpected behavior if the values are of different types (e.g., string vs. number).

Consider using strict equality for safer comparison:

if (this.chatId) {
  const chatId = this._getChatId();
-  if (chatId && chatId != message?.chat?.id) {
+  if (chatId && chatId !== message?.chat?.id) {
    return;
  }
}
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 14ab3f5 and 244d854.

⛔ Files ignored due to path filters (1)
  • pnpm-lock.yaml is excluded by !**/pnpm-lock.yaml
📒 Files selected for processing (1)
  • components/telegram_bot_api/sources/message-updates/message-updates.mjs (2 hunks)
⏰ Context from checks skipped due to timeout of 90000ms (2)
  • GitHub Check: Verify TypeScript components
  • GitHub Check: Publish TypeScript components
🔇 Additional comments (3)
components/telegram_bot_api/sources/message-updates/message-updates.mjs (3)

9-9: Version number correctly incremented.

The version increment from 0.1.5 to 0.1.6 follows semantic versioning principles for adding a new optional feature.


12-21: Good addition of optional chatId property.

The new chatId property is properly defined as optional and reuses the existing propDefinition from the base component, following the component's established patterns.


34-39: Good database abstraction.

The helper methods for getting and setting the chatId in the database follow good encapsulation principles.

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.

[FEATURE] Telegram Bot - New Message Updates (Instant) - Add optional Chat ID prop
2 participants