Skip to content

Conversation

jcortes
Copy link
Collaborator

@jcortes jcortes commented Jan 13, 2025

WHY

Resolves #15250

Summary by CodeRabbit

  • New Features

    • Added Intercom integration capabilities:
      • Add tags to contacts
      • Reply to conversations
      • Send messages to contacts
      • Track new tickets
      • Added options for selecting tags and conversations
    • Enhanced Intercom API interactions with new methods for listing tags, searching tickets, and managing conversations.
  • Improvements

    • Updated Intercom package version to 0.6.0
    • Expanded user and contact management options
  • Technical Updates

    • Introduced new modules for Intercom-specific actions and sources
    • Incremented version numbers for various modules to reflect updates

@jcortes jcortes self-assigned this Jan 13, 2025
Copy link

vercel bot commented Jan 13, 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 Jan 28, 2025 6:31pm
pipedream-docs ⬜️ Ignored (Inspect) Jan 28, 2025 6:31pm
pipedream-docs-redirect-do-not-edit ⬜️ Ignored (Inspect) Jan 28, 2025 6:31pm

Copy link
Contributor

coderabbitai bot commented Jan 13, 2025

Walkthrough

This pull request introduces enhancements to the Intercom component library by adding new actions and sources for managing contacts, conversations, messages, and tickets. It includes functionality for adding tags to contacts, sending messages, replying to conversations, and creating a new ticket source. The Intercom application module has been extended with new properties and methods to support these features, and the package version has been incremented to reflect these updates.

Changes

File Change Summary
components/intercom/actions/add-tag-to-contact/add-tag-to-contact.mjs New module for adding tags to Intercom contacts with addTagToContact method
components/intercom/actions/reply-to-conversation/reply-to-conversation.mjs New module for replying to Intercom conversations with dynamic reply type handling
components/intercom/actions/send-message-to-contact/send-message-to-contact.mjs New module for sending messages to Intercom contacts
components/intercom/intercom.app.mjs Added new properties (tagId, conversationId, messageType), methods (listTags, searchTickets), and updated existing methods
components/intercom/package.json Version updated from 0.5.0 to 0.6.0
components/intercom/sources/new-ticket/new-ticket.mjs New source for handling Intercom ticket events with generateMeta and run methods
components/intercom/actions/create-note/create-note.mjs Version updated from 0.0.4 to 0.0.5
components/intercom/actions/send-incoming-message/send-incoming-message.mjs Version updated from 0.0.4 to 0.0.5
components/intercom/actions/upsert-contact/upsert-contact.mjs Version updated from 0.0.1 to 0.0.2
components/intercom/sources/conversation-closed/conversation-closed.mjs Version updated from 0.0.6 to 0.0.7
components/intercom/sources/lead-added-email/lead-added-email.mjs Version updated from 0.0.6 to 0.0.7
components/intercom/sources/new-admin-reply/new-admin-reply.mjs Version updated from 0.0.6 to 0.0.7
components/intercom/sources/new-company/new-company.mjs Version updated from 0.0.6 to 0.0.7
components/intercom/sources/new-conversation-rating-added/new-conversation-rating-added.mjs Version updated from 0.0.2 to 0.0.3
components/intercom/sources/new-conversation/new-conversation.mjs Version updated from 0.0.6 to 0.0.7
components/intercom/sources/new-event/new-event.mjs Version updated from 0.0.6 to 0.0.7
components/intercom/sources/new-lead/new-lead.mjs Version updated from 0.0.6 to 0.0.7
components/intercom/sources/new-topic/new-topic.mjs Version updated from 0.0.3 to 0.0.4
components/intercom/sources/new-unsubscription/new-unsubscription.mjs Version updated from 0.0.6 to 0.0.7
components/intercom/sources/new-user-reply/new-user-reply.mjs Version updated from 0.0.6 to 0.0.7
components/intercom/sources/new-user/new-user.mjs Version updated from 0.0.6 to 0.0.7
components/intercom/sources/tag-added-to-conversation/tag-added-to-conversation.mjs Version updated from 0.0.6 to 0.0.7
components/intercom/sources/tag-added-to-lead/tag-added-to-lead.mjs Version updated from 0.0.6 to 0.0.7
components/intercom/sources/tag-added-to-user/tag-added-to-user.mjs Version updated from 0.0.6 to 0.0.7

Assessment against linked issues

Objective Addressed Explanation
New ticket polling source [#15250]
Send message to contact [#15250]
Reply to conversation [#15250]
Add tag to contact [#15250]

Possibly related PRs

  • Intercom - new-conversation-rating-added source #14456: This PR introduces a new source for emitting events when a customer adds a rating to a conversation in Intercom, which is directly related to the functionality of the main PR that adds a tag to a contact in Intercom.
  • [ACTION] Intercom Upsert Contact #14268 #14479: This PR implements an action for upserting contacts in Intercom, which involves similar properties and methods as the main PR that introduces a new module for adding a tag to a contact.
  • Hubspot New Notes and New Tasks #15209: This PR focuses on adding new functionalities related to notes and tasks in HubSpot, which may involve similar concepts of managing entities like contacts and tags as seen in the main PR.

Suggested labels

action

Suggested reviewers

  • michelle0927

Poem

🐰 Intercom's dance of tags and chats,
Hopping through APIs with coding stats,
Messages fly, conversations bloom,
A rabbit's code dispels the gloom,
Pipedream's magic, version point-six-oh! 🚀


Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

❤️ Share
🪧 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. (Beta)
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @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.

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: 5

🧹 Nitpick comments (4)
components/intercom/actions/add-tag-to-contact/add-tag-to-contact.mjs (1)

57-74: Enhance response handling and add input validation.

The success message could be more informative, and input validation should be added.

Consider these improvements:

  async run({ $ }) {
+   if (!contactId?.match(/^[0-9a-fA-F]{24}$/)) {
+     throw new Error('Invalid contact ID format. Expected a 24-character hexadecimal string.');
+   }

    const response = await addTagToContact({
      $,
      contactId,
      data: {
        id: tagId,
      },
    });

-   $.export("$summary", `Successfully added tag to contact with ID \`${response.id}\`.`);
+   $.export("$summary", `Successfully added tag '${response.tag.name}' to contact '${response.contact.name}' (ID: ${response.id}).`);
    return response;
  },
components/intercom/intercom.app.mjs (3)

32-45: Consider adding error handling in the options method.

The implementation looks good, but consider handling potential API errors to provide a better user experience.

 async options() {
+  try {
     const { data: tags } = await this.listTags();
     return tags.map(({
       id: value, name: label,
     }) => ({
       label,
       value,
     }));
+  } catch (error) {
+    console.error('Failed to fetch tags:', error);
+    return [];
+  }
 },

46-65: Consider limiting the number of conversations returned.

The implementation looks good, but fetching all conversations could be slow for accounts with many conversations. Consider adding a limit parameter.

 async options({
   data = {
     query: {
       field: "source.type",
       operator: "=",
       value: "conversation",
     },
+    pagination: {
+      per_page: 50,  // Adjust based on UI requirements
+    },
   },
 })

66-85: Consider using a more maintainable approach for message types.

While the implementation is correct, consider using a map object for better maintainability.

-options({ type = "user" }) {
-  if (type === "user") {
-    return [
-      "comment",
-    ];
-  }
-
-  if (type === "admin") {
-    return [
-      "comment",
-      "note",
-    ];
-  }
-  return [];
-},
+const MESSAGE_TYPES = {
+  user: ["comment"],
+  admin: ["comment", "note"],
+};
+options({ type = "user" }) {
+  return MESSAGE_TYPES[type] || [];
+},
📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between 2e729e5 and ea14eff.

⛔ Files ignored due to path filters (1)
  • pnpm-lock.yaml is excluded by !**/pnpm-lock.yaml
📒 Files selected for processing (6)
  • components/intercom/actions/add-tag-to-contact/add-tag-to-contact.mjs (1 hunks)
  • components/intercom/actions/reply-to-conversation/reply-to-conversation.mjs (1 hunks)
  • components/intercom/actions/send-message-to-contact/send-message-to-contact.mjs (1 hunks)
  • components/intercom/intercom.app.mjs (3 hunks)
  • components/intercom/package.json (1 hunks)
  • components/intercom/sources/new-ticket/new-ticket.mjs (1 hunks)
✅ Files skipped from review due to trivial changes (1)
  • components/intercom/package.json
⏰ Context from checks skipped due to timeout of 90000ms (3)
  • GitHub Check: pnpm publish
  • GitHub Check: Publish TypeScript components
  • GitHub Check: Verify TypeScript components
🔇 Additional comments (3)
components/intercom/actions/reply-to-conversation/reply-to-conversation.mjs (1)

118-123: ⚠️ Potential issue

Fix incorrect API method name and add request validation.

The code uses _makeRequest (private) instead of makeRequest (public) method.

Apply this fix:

-     return this.intercom._makeRequest({
+     return this.intercom.makeRequest({
        method: "POST",
        endpoint: `conversations/${conversationId}/parts`,
        ...args,
      });

Likely invalid or redundant comment.

components/intercom/intercom.app.mjs (2)

11-19: LGTM! Well-structured parameter handling.

The modification to accept a parameter object with defaults improves flexibility while maintaining backward compatibility.


Line range hint 1-313: Consider adding integration tests for the new functionality.

The new features for managing tags, conversations, and tickets should be covered by integration tests to ensure reliability across Intercom API updates.

Would you like me to help create integration test examples for these new features?

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: 1

🧹 Nitpick comments (3)
components/intercom/actions/add-tag-to-contact/add-tag-to-contact.mjs (2)

9-45: Add input validation for contactId.

While the props are well-structured, consider adding validation to ensure the contactId format matches Intercom's expected pattern (e.g., 63a07ddf05a32042dffac965).

 contactId: {
   type: "string",
   label: "Contact ID",
   description: "The unique identifier for the contact which is given by Intercom. Eg. `63a07ddf05a32042dffac965`.",
+  validate: (value) => {
+    if (!/^[a-f0-9]{24}$/.test(value)) {
+      throw new Error("Contact ID must be a 24-character hexadecimal string");
+    }
+  },
   propDefinition: [
     intercom,
     "userIds",

57-74: Enhance success message with tag details.

The success message could be more informative by including the tag name along with the ID.

-    $.export("$summary", `Successfully added tag to contact with ID \`${response.id}\`.`);
+    const tag = await this.intercom.getTag(tagId);
+    $.export("$summary", `Successfully added tag "${tag.name}" to contact with ID \`${response.id}\`.`);
components/intercom/intercom.app.mjs (1)

32-45: Add caching for tag options.

The tagId options method makes an API call on every invocation. Consider caching the results to improve performance.

 tagId: {
   type: "string",
   label: "Tag ID",
   description: "The unique identifier for the tag which is given by Intercom. Eg. `7522907`.",
+  _cachedTags: null,
+  _cacheExpiry: null,
   async options() {
+    const CACHE_TTL = 5 * 60 * 1000; // 5 minutes
+    if (this._cachedTags && this._cacheExpiry > Date.now()) {
+      return this._cachedTags;
+    }
     const { data: tags } = await this.listTags();
-    return tags.map(({
+    this._cachedTags = tags.map(({
       id: value, name: label,
     }) => ({
       label,
       value,
     }));
+    this._cacheExpiry = Date.now() + CACHE_TTL;
+    return this._cachedTags;
   },
 },
📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between ea14eff and b1030aa.

📒 Files selected for processing (24)
  • components/intercom/actions/add-tag-to-contact/add-tag-to-contact.mjs (1 hunks)
  • components/intercom/actions/create-note/create-note.mjs (1 hunks)
  • components/intercom/actions/reply-to-conversation/reply-to-conversation.mjs (1 hunks)
  • components/intercom/actions/send-incoming-message/send-incoming-message.mjs (1 hunks)
  • components/intercom/actions/send-message-to-contact/send-message-to-contact.mjs (1 hunks)
  • components/intercom/actions/upsert-contact/upsert-contact.mjs (1 hunks)
  • components/intercom/intercom.app.mjs (3 hunks)
  • components/intercom/package.json (1 hunks)
  • components/intercom/sources/conversation-closed/conversation-closed.mjs (1 hunks)
  • components/intercom/sources/lead-added-email/lead-added-email.mjs (1 hunks)
  • components/intercom/sources/new-admin-reply/new-admin-reply.mjs (1 hunks)
  • components/intercom/sources/new-company/new-company.mjs (1 hunks)
  • components/intercom/sources/new-conversation-rating-added/new-conversation-rating-added.mjs (1 hunks)
  • components/intercom/sources/new-conversation/new-conversation.mjs (1 hunks)
  • components/intercom/sources/new-event/new-event.mjs (1 hunks)
  • components/intercom/sources/new-lead/new-lead.mjs (1 hunks)
  • components/intercom/sources/new-ticket/new-ticket.mjs (1 hunks)
  • components/intercom/sources/new-topic/new-topic.mjs (1 hunks)
  • components/intercom/sources/new-unsubscription/new-unsubscription.mjs (1 hunks)
  • components/intercom/sources/new-user-reply/new-user-reply.mjs (1 hunks)
  • components/intercom/sources/new-user/new-user.mjs (1 hunks)
  • components/intercom/sources/tag-added-to-conversation/tag-added-to-conversation.mjs (1 hunks)
  • components/intercom/sources/tag-added-to-lead/tag-added-to-lead.mjs (1 hunks)
  • components/intercom/sources/tag-added-to-user/tag-added-to-user.mjs (1 hunks)
✅ Files skipped from review due to trivial changes (18)
  • components/intercom/sources/tag-added-to-lead/tag-added-to-lead.mjs
  • components/intercom/sources/tag-added-to-conversation/tag-added-to-conversation.mjs
  • components/intercom/sources/new-user/new-user.mjs
  • components/intercom/actions/create-note/create-note.mjs
  • components/intercom/sources/new-unsubscription/new-unsubscription.mjs
  • components/intercom/sources/conversation-closed/conversation-closed.mjs
  • components/intercom/sources/tag-added-to-user/tag-added-to-user.mjs
  • components/intercom/sources/new-company/new-company.mjs
  • components/intercom/sources/new-topic/new-topic.mjs
  • components/intercom/sources/new-lead/new-lead.mjs
  • components/intercom/sources/new-conversation/new-conversation.mjs
  • components/intercom/sources/lead-added-email/lead-added-email.mjs
  • components/intercom/actions/upsert-contact/upsert-contact.mjs
  • components/intercom/sources/new-admin-reply/new-admin-reply.mjs
  • components/intercom/sources/new-conversation-rating-added/new-conversation-rating-added.mjs
  • components/intercom/sources/new-event/new-event.mjs
  • components/intercom/actions/send-incoming-message/send-incoming-message.mjs
  • components/intercom/sources/new-user-reply/new-user-reply.mjs
🚧 Files skipped from review as they are similar to previous changes (4)
  • components/intercom/package.json
  • components/intercom/actions/send-message-to-contact/send-message-to-contact.mjs
  • components/intercom/actions/reply-to-conversation/reply-to-conversation.mjs
  • components/intercom/sources/new-ticket/new-ticket.mjs
⏰ Context from checks skipped due to timeout of 90000ms (2)
  • GitHub Check: Verify TypeScript components
  • GitHub Check: Publish TypeScript components
🔇 Additional comments (5)
components/intercom/actions/add-tag-to-contact/add-tag-to-contact.mjs (1)

3-8: LGTM! Well-structured component metadata.

The component is properly defined with a clear name, description, and version. The documentation link is a nice touch for reference.

components/intercom/intercom.app.mjs (4)

11-19: LGTM! Improved userIds options method.

The options method now accepts a data parameter with query configuration, making it more flexible.


46-85: LGTM! Well-structured conversation and message type props.

The props are well-defined with clear labels, descriptions, and appropriate options.


304-308: Add method documentation and explicit HTTP method.

The implementation should include JSDoc documentation and explicitly specify the HTTP method.


309-311: Add method documentation and data validation.

The implementation should include JSDoc documentation and validate the search data parameter.

GTFalcao
GTFalcao previously approved these changes Jan 27, 2025
Copy link
Collaborator

@GTFalcao GTFalcao left a comment

Choose a reason for hiding this comment

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

LGTM!

@jcortes jcortes force-pushed the intercom-new-components branch 2 times, most recently from ee6a169 to 3dc5f81 Compare January 27, 2025 21:58
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: 2

🧹 Nitpick comments (4)
components/intercom/actions/add-tag-to-contact/add-tag-to-contact.mjs (1)

18-36: Simplify the contactId query structure.

The current query structure can be simplified while maintaining the same functionality.

 data: {
   query: {
-    operator: "OR",
-    value: [
-      {
-        field: "role",
-        operator: "=",
-        value: "user",
-      },
-      {
-        field: "role",
-        operator: "=",
-        value: "lead",
-      },
-    ],
+    field: "role",
+    operator: "IN",
+    value: ["user", "lead"]
   },
 },
components/intercom/actions/reply-to-conversation/reply-to-conversation.mjs (1)

54-113: Extract constants and add ID validation.

Consider extracting magic strings into constants and adding validation for the admin ID format.

+const REPLY_TYPES = {
+  ADMIN: "admin",
+  USER: "user",
+};
+
+const REPLY_ON_BEHALF_OF = {
+  INTERCOM_USER: "intercom_user_id",
+  EMAIL: "email",
+  USER_ID: "user_id",
+};
+
 additionalProps() {
   const {
     replyType,
     replyOnBehalfOf,
   } = this;
 
-  if (replyType === "admin") {
+  if (replyType === REPLY_TYPES.ADMIN) {
     return {
       adminId: {
         type: "string",
         label: "Admin ID",
         description: "The id of the admin who is authoring the comment.",
+        validate: (value) => {
+          if (!/^\d+$/.test(value)) {
+            throw new Error("Admin ID must be a numeric string");
+          }
+        },
       },
     };
   }
components/intercom/intercom.app.mjs (2)

11-19: Add parameter documentation for options method.

The options method would benefit from detailed parameter documentation.

+/**
+ * Get user options for dropdown
+ * @param {Object} params - The parameters object
+ * @param {Object} [params.data] - Query parameters for filtering users
+ * @param {Object} params.data.query - The query object
+ * @param {string} params.data.query.field - Field to filter on
+ * @param {string} params.data.query.operator - Comparison operator
+ * @param {string|string[]} params.data.query.value - Value to compare against
+ * @returns {Promise<Array<{label: string, value: string}>>} Array of options
+ */
 async options({
   data = {
     query: {

66-85: Improve messageType options maintainability.

Extract message types into constants and use a more maintainable structure.

+const MESSAGE_TYPES = {
+  USER: {
+    type: "user",
+    options: ["comment"],
+  },
+  ADMIN: {
+    type: "admin",
+    options: ["comment", "note"],
+  },
+};
+
 messageType: {
   type: "string",
   label: "Message Type",
   description: "The kind of message being created.",
   options({ type = "user" }) {
-    if (type === "user") {
-      return [
-        "comment",
-      ];
-    }
-
-    if (type === "admin") {
-      return [
-        "comment",
-        "note",
-      ];
-    }
-    return [];
+    return MESSAGE_TYPES[type.toUpperCase()]?.options ?? [];
   },
 },
📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between b1030aa and 3dc5f81.

⛔ Files ignored due to path filters (1)
  • pnpm-lock.yaml is excluded by !**/pnpm-lock.yaml
📒 Files selected for processing (24)
  • components/intercom/actions/add-tag-to-contact/add-tag-to-contact.mjs (1 hunks)
  • components/intercom/actions/create-note/create-note.mjs (1 hunks)
  • components/intercom/actions/reply-to-conversation/reply-to-conversation.mjs (1 hunks)
  • components/intercom/actions/send-incoming-message/send-incoming-message.mjs (1 hunks)
  • components/intercom/actions/send-message-to-contact/send-message-to-contact.mjs (1 hunks)
  • components/intercom/actions/upsert-contact/upsert-contact.mjs (1 hunks)
  • components/intercom/intercom.app.mjs (4 hunks)
  • components/intercom/package.json (1 hunks)
  • components/intercom/sources/conversation-closed/conversation-closed.mjs (1 hunks)
  • components/intercom/sources/lead-added-email/lead-added-email.mjs (1 hunks)
  • components/intercom/sources/new-admin-reply/new-admin-reply.mjs (1 hunks)
  • components/intercom/sources/new-company/new-company.mjs (1 hunks)
  • components/intercom/sources/new-conversation-rating-added/new-conversation-rating-added.mjs (1 hunks)
  • components/intercom/sources/new-conversation/new-conversation.mjs (1 hunks)
  • components/intercom/sources/new-event/new-event.mjs (1 hunks)
  • components/intercom/sources/new-lead/new-lead.mjs (1 hunks)
  • components/intercom/sources/new-ticket/new-ticket.mjs (1 hunks)
  • components/intercom/sources/new-topic/new-topic.mjs (1 hunks)
  • components/intercom/sources/new-unsubscription/new-unsubscription.mjs (1 hunks)
  • components/intercom/sources/new-user-reply/new-user-reply.mjs (1 hunks)
  • components/intercom/sources/new-user/new-user.mjs (1 hunks)
  • components/intercom/sources/tag-added-to-conversation/tag-added-to-conversation.mjs (1 hunks)
  • components/intercom/sources/tag-added-to-lead/tag-added-to-lead.mjs (1 hunks)
  • components/intercom/sources/tag-added-to-user/tag-added-to-user.mjs (1 hunks)
🚧 Files skipped from review as they are similar to previous changes (21)
  • components/intercom/sources/tag-added-to-lead/tag-added-to-lead.mjs
  • components/intercom/actions/upsert-contact/upsert-contact.mjs
  • components/intercom/actions/send-incoming-message/send-incoming-message.mjs
  • components/intercom/sources/new-user/new-user.mjs
  • components/intercom/sources/tag-added-to-conversation/tag-added-to-conversation.mjs
  • components/intercom/sources/new-topic/new-topic.mjs
  • components/intercom/actions/create-note/create-note.mjs
  • components/intercom/sources/new-conversation-rating-added/new-conversation-rating-added.mjs
  • components/intercom/sources/lead-added-email/lead-added-email.mjs
  • components/intercom/package.json
  • components/intercom/sources/conversation-closed/conversation-closed.mjs
  • components/intercom/sources/new-company/new-company.mjs
  • components/intercom/sources/new-admin-reply/new-admin-reply.mjs
  • components/intercom/sources/new-conversation/new-conversation.mjs
  • components/intercom/sources/new-unsubscription/new-unsubscription.mjs
  • components/intercom/sources/new-lead/new-lead.mjs
  • components/intercom/sources/new-user-reply/new-user-reply.mjs
  • components/intercom/actions/send-message-to-contact/send-message-to-contact.mjs
  • components/intercom/sources/tag-added-to-user/tag-added-to-user.mjs
  • components/intercom/sources/new-event/new-event.mjs
  • components/intercom/sources/new-ticket/new-ticket.mjs
⏰ Context from checks skipped due to timeout of 90000ms (3)
  • GitHub Check: Publish TypeScript components
  • GitHub Check: pnpm publish
  • GitHub Check: Verify TypeScript components
🔇 Additional comments (5)
components/intercom/actions/add-tag-to-contact/add-tag-to-contact.mjs (1)

46-56: Add error handling and method documentation.

The addTagToContact method should include proper error handling, parameter validation, and documentation.

 methods: {
+  /**
+   * Adds a tag to a contact in Intercom
+   * @param {Object} params - The parameters object
+   * @param {string} params.contactId - The contact's ID
+   * @param {Object} params.args - Additional arguments for the request
+   * @throws {Error} If contactId is missing or invalid
+   * @returns {Promise<Object>} The API response
+   */
   addTagToContact({
     contactId, ...args
   } = {}) {
+    if (!contactId) {
+      throw new Error("Contact ID is required");
+    }
+    
+    try {
       return this.intercom.makeRequest({
         method: "POST",
         endpoint: `contacts/${contactId}/tags`,
         ...args,
       });
+    } catch (error) {
+      throw new Error(`Failed to add tag to contact: ${error.message}`);
+    }
   },
 },
components/intercom/actions/reply-to-conversation/reply-to-conversation.mjs (2)

139-152: Clean up the request payload.

Remove undefined values from the request payload.

 const response = await replyToConversation({
   $,
   conversationId,
   data: {
     body,
-    attachment_urls: attachmentUrls,
-    admin_id: adminId,
-    intercom_user_id: intercomUserId,
-    email,
-    user_id: userId,
-    message_type: messageType,
     type: replyType,
+    ...(attachmentUrls?.length && { attachment_urls: attachmentUrls }),
+    ...(adminId && { admin_id: adminId }),
+    ...(intercomUserId && { intercom_user_id: intercomUserId }),
+    ...(email && { email }),
+    ...(userId && { user_id: userId }),
+    ...(messageType && { message_type: messageType }),
   },
 });

115-123: 🛠️ Refactor suggestion

Use consistent request method naming.

The method uses _makeRequest while other components use makeRequest. Maintain consistency across the codebase.

 replyToConversation({
   conversationId, ...args
 } = {}) {
-  return this.intercom._makeRequest({
+  return this.intercom.makeRequest({
     method: "POST",
     endpoint: `conversations/${conversationId}/parts`,
     ...args,
   });
 },

Likely invalid or redundant comment.

components/intercom/intercom.app.mjs (2)

305-309: Add method documentation and explicit HTTP method.

The implementation should include JSDoc documentation and explicitly specify the HTTP method.

+/**
+ * Get a list of all tags
+ * @returns {Promise<Object>} Object containing an array of tags in the data property
+ */
 listTags() {
   return this.makeRequest({
+    method: "GET",
     endpoint: "tags",
   });
 },

310-312: Add method documentation and data validation.

The implementation should include JSDoc documentation and validate the search data parameter.

+/**
+ * Search for tickets
+ * @param {Object} data - A query object used to search for tickets
+ * @returns {Promise<Array>} List of tickets matching search query
+ * @throws {Error} If data parameter is missing or invalid
+ */
 async searchTickets(data) {
+  if (!data || typeof data !== 'object') {
+    throw new Error('Search data parameter is required and must be an object');
+  }
   return this.paginate("tickets", "POST", data, true);
 },

@jcortes jcortes force-pushed the intercom-new-components branch from 3dc5f81 to 75e9bd8 Compare January 28, 2025 18:30
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/intercom/intercom.app.mjs (2)

72-91: Document the messageType options method parameters.

The messageType options method accepts a type parameter but lacks documentation about its purpose and allowed values. Additionally, the hardcoded options would benefit from explanatory comments.

Apply this diff to improve documentation:

 messageType: {
   type: "string",
   label: "Message Type",
   description: "The kind of message being created.",
+  /**
+   * Returns available message types based on the sender type
+   * @param {Object} opts - Options object
+   * @param {string} [opts.type="user"] - The sender type: "user" or "admin"
+   * @returns {string[]} Array of available message types
+   */
   options({ type = "user" }) {
     if (type === "user") {
       return [
-        "comment",
+        "comment", // Users can only create comments
       ];
     }

     if (type === "admin") {
       return [
-        "comment",
-        "note",
+        "comment", // Admins can create public comments
+        "note",    // Admins can create private notes
       ];
     }
     return [];
   },
 },

333-338: Add method documentation for listConversations.

The method lacks documentation about its parameters and return value.

Apply this diff to add documentation:

+/**
+ * List conversations with pagination support
+ * @param {Object} [args={}] - Additional arguments for the request
+ * @param {Object} [args.params] - Query parameters
+ * @param {number} [args.params.per_page] - Number of results per page
+ * @param {string} [args.params.starting_after] - Cursor for pagination
+ * @returns {Promise<Object>} Object containing conversations array and pagination info
+ */
 listConversations(args = {}) {
   return this.makeRequest({
     endpoint: "conversations",
     ...args,
   });
 },
📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between 3dc5f81 and 75e9bd8.

⛔ Files ignored due to path filters (1)
  • pnpm-lock.yaml is excluded by !**/pnpm-lock.yaml
📒 Files selected for processing (24)
  • components/intercom/actions/add-tag-to-contact/add-tag-to-contact.mjs (1 hunks)
  • components/intercom/actions/create-note/create-note.mjs (1 hunks)
  • components/intercom/actions/reply-to-conversation/reply-to-conversation.mjs (1 hunks)
  • components/intercom/actions/send-incoming-message/send-incoming-message.mjs (1 hunks)
  • components/intercom/actions/send-message-to-contact/send-message-to-contact.mjs (1 hunks)
  • components/intercom/actions/upsert-contact/upsert-contact.mjs (1 hunks)
  • components/intercom/intercom.app.mjs (4 hunks)
  • components/intercom/package.json (1 hunks)
  • components/intercom/sources/conversation-closed/conversation-closed.mjs (1 hunks)
  • components/intercom/sources/lead-added-email/lead-added-email.mjs (1 hunks)
  • components/intercom/sources/new-admin-reply/new-admin-reply.mjs (1 hunks)
  • components/intercom/sources/new-company/new-company.mjs (1 hunks)
  • components/intercom/sources/new-conversation-rating-added/new-conversation-rating-added.mjs (1 hunks)
  • components/intercom/sources/new-conversation/new-conversation.mjs (1 hunks)
  • components/intercom/sources/new-event/new-event.mjs (1 hunks)
  • components/intercom/sources/new-lead/new-lead.mjs (1 hunks)
  • components/intercom/sources/new-ticket/new-ticket.mjs (1 hunks)
  • components/intercom/sources/new-topic/new-topic.mjs (1 hunks)
  • components/intercom/sources/new-unsubscription/new-unsubscription.mjs (1 hunks)
  • components/intercom/sources/new-user-reply/new-user-reply.mjs (1 hunks)
  • components/intercom/sources/new-user/new-user.mjs (1 hunks)
  • components/intercom/sources/tag-added-to-conversation/tag-added-to-conversation.mjs (1 hunks)
  • components/intercom/sources/tag-added-to-lead/tag-added-to-lead.mjs (1 hunks)
  • components/intercom/sources/tag-added-to-user/tag-added-to-user.mjs (1 hunks)
🚧 Files skipped from review as they are similar to previous changes (21)
  • components/intercom/package.json
  • components/intercom/actions/create-note/create-note.mjs
  • components/intercom/sources/tag-added-to-conversation/tag-added-to-conversation.mjs
  • components/intercom/sources/tag-added-to-user/tag-added-to-user.mjs
  • components/intercom/actions/send-incoming-message/send-incoming-message.mjs
  • components/intercom/sources/conversation-closed/conversation-closed.mjs
  • components/intercom/sources/new-admin-reply/new-admin-reply.mjs
  • components/intercom/sources/new-unsubscription/new-unsubscription.mjs
  • components/intercom/sources/new-conversation/new-conversation.mjs
  • components/intercom/sources/tag-added-to-lead/tag-added-to-lead.mjs
  • components/intercom/sources/new-event/new-event.mjs
  • components/intercom/sources/new-lead/new-lead.mjs
  • components/intercom/sources/new-topic/new-topic.mjs
  • components/intercom/sources/lead-added-email/lead-added-email.mjs
  • components/intercom/sources/new-user-reply/new-user-reply.mjs
  • components/intercom/sources/new-company/new-company.mjs
  • components/intercom/sources/new-user/new-user.mjs
  • components/intercom/sources/new-conversation-rating-added/new-conversation-rating-added.mjs
  • components/intercom/actions/upsert-contact/upsert-contact.mjs
  • components/intercom/actions/send-message-to-contact/send-message-to-contact.mjs
  • components/intercom/actions/reply-to-conversation/reply-to-conversation.mjs
⏰ Context from checks skipped due to timeout of 90000ms (4)
  • GitHub Check: Verify TypeScript components
  • GitHub Check: pnpm publish
  • GitHub Check: Lint Code Base
  • GitHub Check: Publish TypeScript components
🔇 Additional comments (5)
components/intercom/sources/new-ticket/new-ticket.mjs (1)

23-48: Add error handling and pagination support to the run method.

The current implementation has several potential issues:

  1. Missing try-catch block for error handling
  2. No pagination handling for the searchTickets API
  3. Potential race condition with lastTicketCreatedAt updates
components/intercom/actions/add-tag-to-contact/add-tag-to-contact.mjs (2)

46-56: Add error handling and parameter validation.

The addTagToContact method should include error handling and parameter validation.


57-74: Add error handling in the run function.

The run function should include try-catch block and provide more detailed success message.

components/intercom/intercom.app.mjs (2)

325-329: Add method documentation and explicit HTTP method.

The implementation should include JSDoc documentation and explicitly specify the HTTP method.


330-332: Add method documentation and data validation.

The implementation should include JSDoc documentation and validate the search data parameter.

Copy link
Collaborator

@michelle0927 michelle0927 left a comment

Choose a reason for hiding this comment

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

LGTM!

@jcortes jcortes merged commit 7c175d7 into master Jan 29, 2025
11 checks passed
@jcortes jcortes deleted the intercom-new-components branch January 29, 2025 16:59
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.

[Components] intercom
3 participants