-
Notifications
You must be signed in to change notification settings - Fork 5.5k
New Components - messagebird #15247
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
New Components - messagebird #15247
Conversation
The latest updates on your projects. Learn more about Vercel for Git ↗︎ 3 Skipped Deployments
|
WalkthroughThis pull request introduces a comprehensive implementation of MessageBird components for Pipedream, including a new application configuration, actions for creating contacts, sending SMS and voice messages, and a source for handling incoming messages. The changes involve creating new MessageBird app modules, defining multiple actions for contact and message management, and implementing webhook-based message reception sources. The project structure has been updated with new files and modifications to the package configuration. Changes
Assessment against linked issues
Possibly related PRs
Suggested labels
Suggested reviewers
Poem
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? 🪧 TipsChatThere are 3 ways to chat with CodeRabbit:
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)
Other keywords and placeholders
CodeRabbit Configuration File (
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 13
🧹 Nitpick comments (6)
components/messagebird/sources/new-message-received/test-event.mjs (1)
5-7
: Use consistent test IDsThe test event contains multiple UUIDs and a platform reference that appear to be from a real system. For test events, use consistent, obviously fake IDs to make the test data more recognizable.
- "id": "404544c5-9920-45f1-8990-0855634ab7ac", - "channelId": "52ad151f-f7b4-46f9-a5c6-d3318e650c84", + "id": "test-message-id-123", + "channelId": "test-channel-id-123",Also applies to: 16-17, 34-34
components/messagebird/actions/create-contact/create-contact.mjs (3)
6-6
: Update documentation URL domainThe documentation URL uses 'bird.com' instead of 'messagebird.com'.
- description: "Creates a new contact. [See the documentation](https://docs.bird.com/api/contacts-api/api-reference/manage-workspace-contacts/create-a-contact)", + description: "Creates a new contact. [See the documentation](https://docs.messagebird.com/api/contacts-api/api-reference/manage-workspace-contacts/create-a-contact)",
26-30
: Add input validation for display nameThe display name property lacks validation for length and format. Consider adding constraints to prevent invalid inputs.
displayName: { type: "string", label: "Display Name", description: "The display name for the contact", + validate: (value) => { + if (!value?.trim()) { + return "Display name cannot be empty"; + } + if (value.length > 100) { + return "Display name cannot exceed 100 characters"; + } + }, },
31-36
: Add email format validationThe email property should include format validation to ensure valid email addresses.
email: { type: "string", label: "Email", description: "The email address of the contact", optional: true, + validate: (value) => { + if (value && !/^[^\s@]+@[^\s@]+\.[^\s@]+$/.test(value)) { + return "Please enter a valid email address"; + } + }, },components/messagebird/actions/send-sms/send-sms.mjs (1)
6-6
: Update documentation URL domainThe documentation URL uses 'bird.com' instead of 'messagebird.com'.
- description: "Sends an SMS message. [See the documentation](https://docs.bird.com/api/channels-api/supported-channels/programmable-sms/sending-sms-messages)", + description: "Sends an SMS message. [See the documentation](https://docs.messagebird.com/api/channels-api/supported-channels/programmable-sms/sending-sms-messages)",components/messagebird/actions/send-voice-message/send-voice-message.mjs (1)
6-6
: Update documentation URL domainThe documentation URL uses 'bird.com' instead of 'messagebird.com'.
- description: "Send a voice message to any phone number globally. [See the documentation](https://docs.bird.com/api/voice-api/voice-calls-api/initiate-an-outbound-call)", + description: "Send a voice message to any phone number globally. [See the documentation](https://docs.messagebird.com/api/voice-api/voice-calls-api/initiate-an-outbound-call)",
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
⛔ Files ignored due to path filters (1)
pnpm-lock.yaml
is excluded by!**/pnpm-lock.yaml
📒 Files selected for processing (9)
components/messagebird/.gitignore
(0 hunks)components/messagebird/actions/create-contact/create-contact.mjs
(1 hunks)components/messagebird/actions/send-sms/send-sms.mjs
(1 hunks)components/messagebird/actions/send-voice-message/send-voice-message.mjs
(1 hunks)components/messagebird/app/messagebird.app.ts
(0 hunks)components/messagebird/messagebird.app.mjs
(1 hunks)components/messagebird/package.json
(1 hunks)components/messagebird/sources/new-message-received/new-message-received.mjs
(1 hunks)components/messagebird/sources/new-message-received/test-event.mjs
(1 hunks)
💤 Files with no reviewable changes (2)
- components/messagebird/.gitignore
- components/messagebird/app/messagebird.app.ts
⏰ Context from checks skipped due to timeout of 90000ms (4)
- GitHub Check: Verify TypeScript components
- GitHub Check: pnpm publish
- GitHub Check: Publish TypeScript components
- GitHub Check: Lint Code Base
🔇 Additional comments (1)
components/messagebird/package.json (1)
15-17
: Verify platform dependency versionPlease verify if version 3.0.3 of @pipedream/platform is the latest stable version that's compatible with your implementation.
✅ Verification successful
@pipedream/platform dependency is using the latest version
The package is correctly using version 3.0.3, which is confirmed to be the latest available version in the npm registry.
🏁 Scripts executed
The following scripts were executed for the analysis:
Script:
#!/bin/bash # Check latest version of @pipedream/platform npm view @pipedream/platform versions --json | jq -r '.[-1]' # Check for any breaking changes in recent versions npm view @pipedream/platform@">3.0.3" version --jsonLength of output: 754
components/messagebird/actions/send-voice-message/send-voice-message.mjs
Show resolved
Hide resolved
components/messagebird/sources/new-message-received/new-message-received.mjs
Outdated
Show resolved
Hide resolved
components/messagebird/sources/new-message-received/new-message-received.mjs
Outdated
Show resolved
Hide resolved
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 4
🧹 Nitpick comments (1)
components/messagebird/sources/new-message-received/new-message-received.mjs (1)
30-46
: Add validation for platform valuesConsider adding validation to ensure the platform value matches MessageBird's supported channels. Also, consider using constants for the platform options to prevent typos and enable easier maintenance.
+const PLATFORM_OPTIONS = { + SMS: "sms", + WHATSAPP: "whatsapp", + EMAIL: "email", + LINE: "line", + INSTAGRAM: "instagram", + FACEBOOK: "facebook", + VIBER: "viber", + LINKEDIN: "linkedin", + TIKTOK: "tiktok", + TELEGRAM: "telegram", +}; platform: { type: "string", label: "Platform", description: "The type of inbound message to watch for", - options: [ - "sms", - "whatsapp", - "email", - "line", - "instagram", - "facebook", - "viber", - "linkedin", - "tiktok", - "telegram", - ], + options: Object.values(PLATFORM_OPTIONS), + validate: (value) => Object.values(PLATFORM_OPTIONS).includes(value), },
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (2)
components/messagebird/package.json
(1 hunks)components/messagebird/sources/new-message-received/new-message-received.mjs
(1 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
- components/messagebird/package.json
⏰ Context from checks skipped due to timeout of 90000ms (3)
- GitHub Check: Verify TypeScript components
- GitHub Check: Publish TypeScript components
- GitHub Check: Lint Code Base
🔇 Additional comments (1)
components/messagebird/sources/new-message-received/new-message-received.mjs (1)
7-7
: Update documentation URLThe documentation URL appears to be incorrect. It points to
docs.bird.com
instead of the official MessageBird documentation.
components/messagebird/sources/new-message-received/new-message-received.mjs
Show resolved
Hide resolved
components/messagebird/sources/new-message-received/new-message-received.mjs
Show resolved
Hide resolved
components/messagebird/sources/new-message-received/new-message-received.mjs
Show resolved
Hide resolved
There was a problem hiding this 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!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 8
♻️ Duplicate comments (3)
components/message_bird/message_bird.app.mjs (2)
24-26
:⚠️ Potential issueFix API base URL
The base URL is incorrect. According to MessageBird's documentation, it should be "https://conversations.messagebird.com/v1".
_baseUrl() { - return "https://rest.messagebird.com"; + return "https://conversations.messagebird.com/v1"; },
27-39
: 🛠️ Refactor suggestionEnhance request error handling
The
_makeRequest
method should include proper error handling and request timeout._makeRequest({ $ = this, path, + timeout = 10000, ...opts }) { + const headers = { + "Authorization": `AccessKey ${this.$auth.access_key}`, + "Content-Type": "application/json", + }; + + try { return axios($, { url: `${this._baseUrl()}${path}`, - headers: { - "Authorization": `AccessKey ${this.$auth.access_key}`, - }, + headers, + timeout, ...opts, }); + } catch (error) { + const status = error.response?.status; + const message = error.response?.data?.errors?.[0]?.description || error.message; + throw new Error(`MessageBird API request failed: ${status} - ${message}`); + } },components/messagebird/messagebird.app.mjs (1)
136-138
:⚠️ Potential issueFix API base URL
The base URL is incorrect. According to MessageBird's documentation, it should be "https://conversations.messagebird.com/v1".
_baseUrl() { - return "https://api.bird.com"; + return "https://conversations.messagebird.com/v1"; },
🧹 Nitpick comments (5)
components/message_bird/actions/send-sms/send-sms.mjs (1)
30-41
: Add input validation for required fieldsConsider validating the required fields before making the API call to provide better error messages.
async run({ $ }) { + if (!this.originator) { + throw new Error("Originator is required"); + } + if (!this.body) { + throw new Error("Message body is required"); + } + if (!this.recipients) { + throw new Error("Recipients are required"); + } const response = await this.messagebird.sendSMS({components/message_bird/actions/create-contact/create-contact.mjs (1)
29-37
: Handle empty optional fieldsRemove optional fields from the request if they are empty to avoid sending unnecessary null values.
async run({ $ }) { + const data = { + msisdn: this.phone, + ...(this.firstName && { firstName: this.firstName }), + ...(this.lastName && { lastName: this.lastName }), + }; const response = await this.messagebird.createContact({ $, - data: { - msisdn: this.phone, - firstName: this.firstName, - lastName: this.lastName, - }, + data, });components/message_bird/sources/new-sms-message-received/new-sms-message-received.mjs (1)
16-18
: Consider configurable polling intervalAllow users to configure the polling interval based on their needs while maintaining reasonable limits.
type: "$.interface.timer", - default: { - intervalSeconds: DEFAULT_POLLING_SOURCE_TIMER_INTERVAL, - }, + label: "Polling Interval", + description: "How often to poll for new messages (in seconds)", + default: { + intervalSeconds: DEFAULT_POLLING_SOURCE_TIMER_INTERVAL, + }, + min: 60, // Minimum 1 minute + max: 900, // Maximum 15 minutescomponents/message_bird/message_bird.app.mjs (1)
40-65
: Add pagination support to list methodsThe list methods should support pagination to handle large datasets efficiently.
listSMSMessages(opts = {}) { + const { page = 1, perPage = 10, ...otherOpts } = opts; return this._makeRequest({ path: "/messages", + params: { + page, + per_page: perPage, + ...otherOpts.params, + }, - ...opts, + ...otherOpts, }); },components/messagebird/messagebird.app.mjs (1)
211-228
: Add rate limiting support for message sendingThe message sending methods should implement rate limiting to prevent API throttling.
+ async _getRateLimit() { + const response = await this._makeRequest({ + path: "/rate-limit", + }); + return response.remaining; + }, async sendVoiceMessage({ workspaceId, channelId, ...opts }) { + const remaining = await this._getRateLimit(); + if (remaining <= 0) { + throw new Error("Rate limit exceeded. Please try again later."); + } return this._makeRequest({ method: "POST", path: `/workspaces/${workspaceId}/channels/${channelId}/calls`, ...opts, }); },
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
⛔ Files ignored due to path filters (1)
pnpm-lock.yaml
is excluded by!**/pnpm-lock.yaml
📒 Files selected for processing (7)
components/message_bird/actions/create-contact/create-contact.mjs
(1 hunks)components/message_bird/actions/send-sms/send-sms.mjs
(1 hunks)components/message_bird/actions/send-voice-message/send-voice-message.mjs
(1 hunks)components/message_bird/message_bird.app.mjs
(1 hunks)components/message_bird/package.json
(1 hunks)components/message_bird/sources/new-sms-message-received/new-sms-message-received.mjs
(1 hunks)components/messagebird/messagebird.app.mjs
(1 hunks)
✅ Files skipped from review due to trivial changes (1)
- components/message_bird/package.json
⏰ Context from checks skipped due to timeout of 90000ms (4)
- GitHub Check: Verify TypeScript components
- GitHub Check: pnpm publish
- GitHub Check: Publish TypeScript components
- GitHub Check: Lint Code Base
components/message_bird/actions/send-voice-message/send-voice-message.mjs
Show resolved
Hide resolved
components/message_bird/sources/new-sms-message-received/new-sms-message-received.mjs
Outdated
Show resolved
Hide resolved
components/message_bird/sources/new-sms-message-received/new-sms-message-received.mjs
Show resolved
Hide resolved
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM!
There was a problem hiding this 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
♻️ Duplicate comments (6)
components/messagebird/messagebird.app.mjs (4)
11-34
: 🛠️ Refactor suggestionAdd error handling and input validation in async options.
The async options functions need proper error handling and input validation to prevent UI failures.
Additionally, consider adding debouncing to prevent race conditions when dependencies change rapidly.
async options({ prevContext }) { + try { const { next: pageToken } = prevContext; + if (typeof pageToken === 'string' && pageToken.length > 1000) { + throw new Error('Invalid page token'); + } const { results, nextPageToken, } = await this.listWorkspaces({ organizationId: this._organizationId(), params: pageToken ? { pageToken, } : {}, }); return { options: results?.map(({ id: value, name: label, }) => ({ value, label, })) || [], context: { next: nextPageToken, }, }; + } catch (error) { + console.error('Failed to fetch options:', error); + return { + options: [], + context: { next: null }, + }; + } },Also applies to: 40-68, 74-102, 109-122
126-128
:⚠️ Potential issueFix API base URL.
The base URL is incorrect. It should point to the official MessageBird API endpoint.
_baseUrl() { - return "https://api.bird.com"; + return "https://conversations.messagebird.com/v1"; },
132-144
: 🛠️ Refactor suggestionEnhance request error handling and add request timeout.
The
_makeRequest
method should include proper error handling and request timeout._makeRequest({ $ = this, path, + timeout = 10000, ...otherOpts }) { + const headers = { + "Authorization": `AccessKey ${this.$auth.api_key}`, + "Content-Type": "application/json", + }; + + try { return axios($, { url: `${this._baseUrl()}${path}`, - headers: { - "Authorization": `AccessKey ${this.$auth.api_key}`, - }, + headers, + timeout, ...otherOpts, }); + } catch (error) { + const status = error.response?.status; + const message = error.response?.data?.errors?.[0]?.description || error.message; + throw new Error(`MessageBird API request failed: ${status} - ${message}`); + } },
145-153
: 🛠️ Refactor suggestionAdd webhook event type validation.
The webhook creation method should validate event types against supported values.
+const VALID_WEBHOOK_EVENTS = [ + "message.created", + "message.updated", + "conversation.created", + "conversation.updated", +]; + createWebhook({ workspaceId, ...opts }) { + const { events } = opts.data || {}; + if (events?.some((event) => !VALID_WEBHOOK_EVENTS.includes(event))) { + throw new Error(`Invalid webhook event. Supported events: ${VALID_WEBHOOK_EVENTS.join(", ")}`); + } return this._makeRequest({ method: "POST", path: `/organizations/${this._organizationId()}/workspaces/${workspaceId}/webhook-subscriptions`, ...opts, }); },components/messagebird/sources/new-message-received/new-message-received.mjs (2)
40-50
:⚠️ Potential issueImplement webhook security measures
The webhook implementation lacks security controls.
async activate() { + // Validate webhook URL + if (!this.http.endpoint || !this.http.endpoint.startsWith('https://')) { + throw new Error('Invalid webhook URL. HTTPS is required.'); + } + + try { + // Generate and store webhook secret + const webhookSecret = crypto.randomBytes(32).toString('hex'); + this.db.set('webhookSecret', webhookSecret); + const { id } = await this.messagebird.createWebhook({ workspaceId: this.workspaceId, data: { service: "channels", event: `${this.platform}.inbound`, url: this.http.endpoint, + headers: { + 'X-Webhook-Secret': webhookSecret, + }, }, }); this._setHookId(id); + } catch (error) { + console.error('Failed to create webhook:', error); + throw error; + } },
62-74
:⚠️ Potential issueAdd robust error handling for database and metadata operations
The methods lack error handling for database operations and event structure validation.
_getHookId() { + try { return this.db.get("hookId"); + } catch (error) { + console.error("Failed to retrieve hook ID:", error); + throw error; + } }, _setHookId(hookId) { + if (!hookId) { + throw new Error("Hook ID is required"); + } + try { this.db.set("hookId", hookId); + } catch (error) { + console.error("Failed to store hook ID:", error); + throw error; + } }, generateMeta(event) { + if (!event?.payload?.id || !event?.createdAt) { + throw new Error("Invalid event structure"); + } return { id: event.payload.id, summary: `New Message ID: ${event.payload.id}`, ts: Date.parse(event.createdAt), }; },
🧹 Nitpick comments (2)
components/messagebird/messagebird.app.mjs (1)
202-219
: Add rate limiting for message sending endpoints.The message sending methods should implement rate limiting to prevent API quota exhaustion.
+const MESSAGE_RATE_LIMIT = { + maxRequests: 60, + perSeconds: 60, +}; + +let messageCounter = 0; +let lastResetTime = Date.now(); + sendVoiceMessage({ workspaceId, channelId, ...opts }) { + const now = Date.now(); + if (now - lastResetTime > MESSAGE_RATE_LIMIT.perSeconds * 1000) { + messageCounter = 0; + lastResetTime = now; + } + if (messageCounter >= MESSAGE_RATE_LIMIT.maxRequests) { + throw new Error(`Rate limit exceeded. Maximum ${MESSAGE_RATE_LIMIT.maxRequests} messages per ${MESSAGE_RATE_LIMIT.perSeconds} seconds.`); + } + messageCounter++; return this._makeRequest({ method: "POST", path: `/workspaces/${workspaceId}/channels/${channelId}/calls`, ...opts, }); },Apply similar rate limiting to
sendSmsMessage
method.components/messagebird/sources/new-message-received/new-message-received.mjs (1)
21-37
: Add platform validation and default valueThe platform prop should include validation and a default value for better user experience.
platform: { type: "string", label: "Platform", description: "The type of inbound message to watch for", + default: "sms", + reloadProps: true, options: [ "sms", "whatsapp", "email", "line", "instagram", "facebook", "viber", "linkedin", "tiktok", "telegram", ], + validate: (value) => { + const validPlatforms = ["sms", "whatsapp", "email", "line", "instagram", "facebook", "viber", "linkedin", "tiktok", "telegram"]; + if (!validPlatforms.includes(value)) { + throw new Error("Invalid platform selected"); + } + }, },
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
⛔ Files ignored due to path filters (1)
pnpm-lock.yaml
is excluded by!**/pnpm-lock.yaml
📒 Files selected for processing (5)
components/messagebird/actions/create-contact/create-contact.mjs
(1 hunks)components/messagebird/actions/send-sms/send-sms.mjs
(1 hunks)components/messagebird/actions/send-voice-message/send-voice-message.mjs
(1 hunks)components/messagebird/messagebird.app.mjs
(1 hunks)components/messagebird/sources/new-message-received/new-message-received.mjs
(1 hunks)
🚧 Files skipped from review as they are similar to previous changes (3)
- components/messagebird/actions/send-sms/send-sms.mjs
- components/messagebird/actions/send-voice-message/send-voice-message.mjs
- components/messagebird/actions/create-contact/create-contact.mjs
⏰ Context from checks skipped due to timeout of 90000ms (3)
- GitHub Check: Verify TypeScript components
- GitHub Check: pnpm publish
- GitHub Check: Publish TypeScript components
🔇 Additional comments (3)
components/messagebird/messagebird.app.mjs (1)
1-5
: LGTM! App configuration follows Pipedream's standard format.components/messagebird/sources/new-message-received/new-message-received.mjs (2)
7-7
: Update documentation URLThe documentation URL is incorrect. It should point to the official MessageBird documentation.
- description: "Emit new event for each new message received. [See the documentation](https://docs.bird.com/api/notifications-api/api-reference/webhook-subscriptions/create-a-webhook-subscription)", + description: "Emit new event for each new message received. [See the documentation](https://developers.messagebird.com/api/conversations/#webhooks)",
84-84
: Improve test coverageThe component lacks comprehensive test coverage.
Add test cases for:
- Different platform types
- Error scenarios
- Webhook lifecycle
- Event validation
Run this script to verify current test coverage:
#!/bin/bash # Search for test files and their content fd "test" components/messagebird/sources/new-message-received/ -t f -x cat {}
components/messagebird/sources/new-message-received/new-message-received.mjs
Show resolved
Hide resolved
/approve |
/approve |
Resolves #15227
Summary by CodeRabbit
New Features
Improvements
Changes
.gitignore
file to allow tracking of specified files.