diff --git a/components/sendblue/actions/get-contact-list/get-contact-list.mjs b/components/sendblue/actions/get-contact-list/get-contact-list.mjs new file mode 100644 index 0000000000000..4036184542057 --- /dev/null +++ b/components/sendblue/actions/get-contact-list/get-contact-list.mjs @@ -0,0 +1,25 @@ +import app from "../../sendblue.app.mjs"; + +export default { + key: "sendblue-get-contact-list", + name: "Get Contact List", + description: "Retrieve a list of your existing contacts from Sendblue. [See the documentation](https://docs.sendblue.com/api/resources/contacts/methods/list)", + version: "0.0.1", + type: "action", + props: { + app, + }, + annotations: { + readOnlyHint: true, + destructiveHint: false, + openWorldHint: true, + }, + async run({ $ }) { + const response = await this.app.getContactList({ + $, + }); + + $.export("$summary", "Successfully retrieved contact list"); + return response; + }, +}; diff --git a/components/sendblue/actions/send-group-message/send-group-message.mjs b/components/sendblue/actions/send-group-message/send-group-message.mjs new file mode 100644 index 0000000000000..e586ec249633c --- /dev/null +++ b/components/sendblue/actions/send-group-message/send-group-message.mjs @@ -0,0 +1,81 @@ +import { ConfigurationError } from "@pipedream/platform"; +import app from "../../sendblue.app.mjs"; + +export default { + key: "sendblue-send-group-message", + name: "Send Group Message", + description: "Send a message to a group of recipients in an iMessage group", + version: "0.0.1", + type: "action", + props: { + app, + fromNumber: { + propDefinition: [ + app, + "fromNumber", + ], + }, + groupId: { + propDefinition: [ + app, + "groupId", + ], + }, + toNumbers: { + type: "string[]", + label: "To Numbers", + description: "The phone numbers of the recipients in E.164 format (e.g., `+12025551234`)", + optional: true, + propDefinition: [ + app, + "toNumber", + ], + }, + content: { + propDefinition: [ + app, + "content", + ], + }, + mediaUrl: { + propDefinition: [ + app, + "mediaUrl", + ], + }, + }, + annotations: { + readOnlyHint: false, + destructiveHint: false, + openWorldHint: true, + idempotentHint: false, + }, + async run({ $ }) { + const { + app, + fromNumber, + groupId, + toNumbers, + content, + mediaUrl, + } = this; + + if (!groupId && (!toNumbers || toNumbers.length === 0)) { + throw new ConfigurationError("At least one of **To Numbers** or **Group ID** is required"); + } + + const response = await app.sendGroupMessage({ + $, + data: { + from_number: fromNumber, + group_id: groupId, + numbers: toNumbers, + content, + media_url: mediaUrl, + }, + }); + + $.export("$summary", "Successfully sent message to group"); + return response; + }, +}; diff --git a/components/sendblue/actions/send-message/send-message.mjs b/components/sendblue/actions/send-message/send-message.mjs new file mode 100644 index 0000000000000..28e9b1b4fddd5 --- /dev/null +++ b/components/sendblue/actions/send-message/send-message.mjs @@ -0,0 +1,79 @@ +import app from "../../sendblue.app.mjs"; + +export default { + key: "sendblue-send-message", + name: "Send Message", + description: "Send an iMessage or SMS to a specific phone number. [See the documentation](https://docs.sendblue.com/api/resources/messages/methods/send)", + version: "0.0.1", + type: "action", + props: { + app, + fromNumber: { + propDefinition: [ + app, + "fromNumber", + ], + }, + toNumber: { + propDefinition: [ + app, + "toNumber", + ], + }, + content: { + propDefinition: [ + app, + "content", + ], + }, + mediaUrl: { + propDefinition: [ + app, + "mediaUrl", + ], + }, + sendStyle: { + propDefinition: [ + app, + "sendStyle", + ], + }, + statusCallback: { + propDefinition: [ + app, + "statusCallback", + ], + }, + }, + annotations: { + readOnlyHint: false, + destructiveHint: false, + openWorldHint: true, + }, + async run({ $ }) { + const { + app, + fromNumber, + toNumber, + content, + mediaUrl, + sendStyle, + statusCallback, + } = this; + + const response = await app.sendMessage({ + $, + data: { + from_number: fromNumber, + number: toNumber, + content, + media_url: mediaUrl, + send_style: sendStyle, + status_callback: statusCallback, + }, + }); + + $.export("$summary", "Successfully sent message"); + return response; + }, +}; diff --git a/components/sendblue/package.json b/components/sendblue/package.json index b257ec0646eff..646643a73b5f5 100644 --- a/components/sendblue/package.json +++ b/components/sendblue/package.json @@ -1,6 +1,6 @@ { "name": "@pipedream/sendblue", - "version": "0.0.4", + "version": "0.1.0", "description": "Pipedream Sendblue Components", "main": "sendblue.app.mjs", "keywords": [ @@ -11,5 +11,8 @@ "author": "Pipedream (https://pipedream.com/)", "publishConfig": { "access": "public" + }, + "dependencies": { + "@pipedream/platform": "^3.1.1" } } diff --git a/components/sendblue/sendblue.app.mjs b/components/sendblue/sendblue.app.mjs index 4b7925db9cb57..9300aa23dc458 100644 --- a/components/sendblue/sendblue.app.mjs +++ b/components/sendblue/sendblue.app.mjs @@ -1,11 +1,249 @@ +import { axios } from "@pipedream/platform"; + export default { type: "app", app: "sendblue", - propDefinitions: {}, + propDefinitions: { + fromNumber: { + type: "string", + label: "Origin Phone Number", + description: "The phone number to send from. Must be one of your registered **Sendblue** phone numbers in E.164 format. Without this parameter, the message will fail to send.", + }, + toNumber: { + type: "string", + label: "Recipient Phone Number", + description: "The phone number of the recipient in E.164 format (e.g., `+12025551234`)", + }, + content: { + type: "string", + label: "Message Content", + description: "The text content of the message to send", + optional: true, + }, + mediaUrl: { + type: "string", + label: "Media URL", + description: "URL of media file to send (images, videos, etc.)", + optional: true, + }, + sendStyle: { + type: "string", + label: "Send Style", + description: "The iMessage expressive message style (iMessage only)", + optional: true, + options: [ + "celebration", + "shooting_star", + "lasers", + "love", + "confetti", + "balloons", + "spotlight", + "echo", + "invisible", + "gentle", + "loud", + "slam", + "fireworks", + ], + }, + groupId: { + type: "string", + label: "Group ID", + description: "The ID of the iMessage group to send the message to", + optional: true, + }, + statusCallback: { + type: "string", + label: "Status Callback", + description: "Webhook URL for message status updates", + optional: true, + }, + accountEmail: { + type: "string", + label: "Account Email", + description: "Filter by account email", + optional: true, + }, + fromNumberFilter: { + type: "string", + label: "From Number", + description: "Filter by sender phone number", + optional: true, + }, + toNumberFilter: { + type: "string", + label: "To Number", + description: "Filter by recipient phone number", + optional: true, + }, + groupIdFilter: { + type: "string", + label: "Group ID", + description: "Filter by group ID", + optional: true, + }, + messageTypeFilter: { + type: "string", + label: "Message Type", + description: "Filter by message type", + optional: true, + options: [ + { + label: "Direct Message", + value: "message", + }, + { + label: "Group Message", + value: "group", + }, + ], + }, + serviceFilter: { + type: "string", + label: "Service Type", + description: "Filter by service type", + optional: true, + options: [ + { + label: "iMessage", + value: "iMessage", + }, + { + label: "SMS", + value: "SMS", + }, + ], + }, + statusFilter: { + type: "string", + label: "Status", + description: "Filter by message status", + optional: true, + options: [ + "REGISTERED", + "PENDING", + "SENT", + "DELIVERED", + "RECEIVED", + "QUEUED", + "ERROR", + "DECLINED", + "ACCEPTED", + "SUCCESS", + ], + }, + orderBy: { + type: "string", + label: "Order By", + description: "Field to order messages by", + optional: true, + options: [ + { + label: "Created At", + value: "createdAt", + }, + { + label: "Updated At", + value: "updatedAt", + }, + { + label: "Sent At", + value: "sentAt", + }, + ], + }, + orderDirection: { + type: "string", + label: "Order Direction", + description: "Sort order", + optional: true, + options: [ + { + label: "Ascending", + value: "asc", + }, + { + label: "Descending", + value: "desc", + }, + ], + }, + limit: { + type: "integer", + label: "Limit", + description: "Maximum number of messages to return (1-1000)", + optional: true, + default: 50, + }, + }, methods: { - // this.$auth contains connected account data - authKeys() { - console.log(Object.keys(this.$auth)); + getUrl(path) { + return `https://api.sendblue.co${path}`; + }, + getHeaders() { + const { + api_key: apiKey, + api_secret: apiSecret, + } = this.$auth; + + return { + "Content-Type": "application/json", + "sb-api-key-id": apiKey, + "sb-api-secret-key": apiSecret, + }; + }, + _makeRequest({ + $ = this, path, ...otherOpts + } = {}) { + return axios($, { + url: this.getUrl(path), + headers: this.getHeaders(), + ...otherOpts, + }); + }, + post(opts = {}) { + return this._makeRequest({ + ...opts, + method: "post", + }); + }, + sendMessage(opts = {}) { + return this.post({ + path: "/api/send-message", + ...opts, + }); + }, + sendGroupMessage(opts = {}) { + return this.post({ + path: "/api/send-group-message", + ...opts, + }); + }, + getContactList(opts = {}) { + return this._makeRequest({ + path: "/api/v2/contacts", + ...opts, + }); + }, + listMessages(opts = {}) { + return this._makeRequest({ + path: "/api/v2/messages", + ...opts, + }); + }, + addWebhook(opts = {}) { + return this.post({ + path: "/api/v2/account/webhooks", + ...opts, + }); + }, + deleteWebhook(opts = {}) { + return this._makeRequest({ + ...opts, + method: "delete", + path: "/api/v2/account/webhooks", + }); }, }, }; diff --git a/components/sendblue/sources/new-message-received-instant/new-message-received-instant.mjs b/components/sendblue/sources/new-message-received-instant/new-message-received-instant.mjs new file mode 100644 index 0000000000000..a2c94586df107 --- /dev/null +++ b/components/sendblue/sources/new-message-received-instant/new-message-received-instant.mjs @@ -0,0 +1,65 @@ +import app from "../../sendblue.app.mjs"; + +export default { + key: "sendblue-new-message-received-instant", + name: "New Message Received (Instant)", + description: "Emit new event when a new inbound message is received. [See the documentation](https://docs.sendblue.com/api/resources/webhooks/methods/create)", + version: "0.0.1", + type: "source", + dedupe: "unique", + props: { + app, + http: "$.interface.http", + }, + hooks: { + async activate() { + const { + app, + http: { endpoint: webhookUrl }, + } = this; + + await app.addWebhook({ + data: { + webhooks: [ + webhookUrl, + ], + }, + }); + }, + async deactivate() { + const { + app, + http: { endpoint: webhookUrl }, + } = this; + + await app.deleteWebhook({ + data: { + webhooks: [ + webhookUrl, + ], + }, + }); + }, + }, + methods: { + generateMeta(message) { + return { + id: message.message_handle || `${message.from_number}-${message.date_sent}`, + summary: `New message from ${message.from_number}: ${message.content?.substring(0, 50)}${ + message.content?.length > 50 + ? "..." + : "" + }`, + ts: new Date(message.date_sent).getTime(), + }; + }, + }, + async run(event) { + const message = event.body; + + if (message && message.from_number) { + const meta = this.generateMeta(message); + this.$emit(message, meta); + } + }, +}; diff --git a/components/sendblue/sources/new-message-received/new-message-received.mjs b/components/sendblue/sources/new-message-received/new-message-received.mjs new file mode 100644 index 0000000000000..35c64d4aef50b --- /dev/null +++ b/components/sendblue/sources/new-message-received/new-message-received.mjs @@ -0,0 +1,194 @@ +import { DEFAULT_POLLING_SOURCE_TIMER_INTERVAL } from "@pipedream/platform"; +import app from "../../sendblue.app.mjs"; + +export default { + key: "sendblue-new-message-received", + name: "New Message Received", + description: "Emit new event when a new inbound message is received. [See the documentation](https://docs.sendblue.com/api/resources/messages/methods/list)", + version: "0.0.1", + type: "source", + dedupe: "unique", + props: { + app, + db: "$.service.db", + timer: { + type: "$.interface.timer", + default: { + intervalSeconds: DEFAULT_POLLING_SOURCE_TIMER_INTERVAL, + }, + }, + accountEmail: { + propDefinition: [ + app, + "accountEmail", + ], + }, + fromNumberFilter: { + propDefinition: [ + app, + "fromNumberFilter", + ], + }, + toNumberFilter: { + propDefinition: [ + app, + "toNumberFilter", + ], + }, + groupIdFilter: { + propDefinition: [ + app, + "groupIdFilter", + ], + }, + messageTypeFilter: { + propDefinition: [ + app, + "messageTypeFilter", + ], + }, + serviceFilter: { + propDefinition: [ + app, + "serviceFilter", + ], + }, + statusFilter: { + propDefinition: [ + app, + "statusFilter", + ], + }, + orderBy: { + propDefinition: [ + app, + "orderBy", + ], + }, + orderDirection: { + propDefinition: [ + app, + "orderDirection", + ], + }, + limit: { + propDefinition: [ + app, + "limit", + ], + }, + }, + hooks: { + async deploy() { + await this.processEvent(25); + this._setIsFirstRun(false); + }, + }, + methods: { + _getLastTimestamp() { + return this.db.get("lastTimestamp") || 0; + }, + _setLastTimestamp(timestamp) { + this.db.set("lastTimestamp", timestamp); + }, + _getIsFirstRun() { + return this.db.get("isFirstRun") !== false; + }, + _setIsFirstRun(value) { + this.db.set("isFirstRun", value); + }, + async processEvent(max) { + const lastTimestamp = this._getLastTimestamp(); + + // Build query params from user-selected filters + const params = { + is_outbound: false, + limit: this.limit || 50, + }; + + if (this.accountEmail) { + params.account_email = this.accountEmail; + } + + if (this.fromNumberFilter) { + params.from_number = this.fromNumberFilter; + } + + if (this.toNumberFilter) { + params.to_number = this.toNumberFilter; + } + + if (this.groupIdFilter) { + params.group_id = this.groupIdFilter; + } + + if (this.messageTypeFilter) { + params.message_type = this.messageTypeFilter; + } + + if (this.serviceFilter) { + params.service = this.serviceFilter; + } + + if (this.statusFilter) { + params.status = this.statusFilter; + } + + if (this.orderBy) { + params.order_by = this.orderBy; + } + + if (this.orderDirection) { + params.order_direction = this.orderDirection; + } + + const response = await this.app.listMessages({ + params, + }); + + const messages = response.data || []; + + if (!messages.length) { + return; + } + + // Filter for messages newer than the last timestamp + // Use date_updated as the reliable timestamp field + const newMessages = messages.filter((message) => { + const dateToUse = message.date_updated || message.date_sent; + const messageTime = new Date(dateToUse).getTime(); + return messageTime > lastTimestamp; + }).slice(0, max); + + if (newMessages.length > 0) { + // Update the last timestamp to the most recent message + const mostRecentTime = Math.max(...newMessages.map((m) => { + const dateToUse = m.date_updated || m.date_sent; + return new Date(dateToUse).getTime(); + })); + this._setLastTimestamp(mostRecentTime); + } + + newMessages.forEach((message) => { + const meta = this.generateMeta(message); + this.$emit(message, meta); + }); + }, + generateMeta(message) { + const dateToUse = message.date_updated || message.date_sent; + return { + id: message.message_handle, + summary: `New message from ${message.from_number}`, + ts: new Date(dateToUse).getTime(), + }; + }, + }, + async run() { + // Skip first run since deploy hook already executed processEvent + if (this._getIsFirstRun()) { + this._setIsFirstRun(false); + return; + } + await this.processEvent(); + }, +}; diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index a89f72da8aa97..e4258a33dead6 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -2043,8 +2043,7 @@ importers: components/braintree: {} - components/brand_dev: - specifiers: {} + components/brand_dev: {} components/brandblast: {} @@ -3588,8 +3587,7 @@ importers: components/currents_api: {} - components/cursor: - specifiers: {} + components/cursor: {} components/customer_fields: dependencies: @@ -5669,8 +5667,7 @@ importers: components/funnelcockpit: {} - components/fynk: - specifiers: {} + components/fynk: {} components/gagelist: dependencies: @@ -6736,8 +6733,7 @@ importers: components/helcim: {} - components/helicone: - specifiers: {} + components/helicone: {} components/helium: dependencies: @@ -8649,8 +8645,7 @@ importers: specifier: ^1.6.8 version: 1.6.8 - components/magicalapi: - specifiers: {} + components/magicalapi: {} components/magileads: {} @@ -12280,8 +12275,7 @@ importers: specifier: ^3.1.1 version: 3.1.1 - components/relationcity: - specifiers: {} + components/relationcity: {} components/relavate: dependencies: @@ -13175,7 +13169,11 @@ importers: specifier: ^3.1.1 version: 3.1.1 - components/sendblue: {} + components/sendblue: + dependencies: + '@pipedream/platform': + specifier: ^3.1.1 + version: 3.1.1 components/sendcloud: dependencies: @@ -14054,8 +14052,7 @@ importers: components/socialkit: {} - components/socket: - specifiers: {} + components/socket: {} components/softledger: {} @@ -15438,8 +15435,7 @@ importers: components/turbohire: {} - components/turbosmtp: - specifiers: {} + components/turbosmtp: {} components/turbot_pipes: dependencies: @@ -15871,8 +15867,7 @@ importers: specifier: ^3.1.1 version: 3.1.1 - components/validemail: - specifiers: {} + components/validemail: {} components/vapi: dependencies: @@ -15976,8 +15971,7 @@ importers: components/verticalresponse: {} - components/veryfi: - specifiers: {} + components/veryfi: {} components/vestaboard: dependencies: @@ -31491,17 +31485,17 @@ packages: superagent@3.8.1: resolution: {integrity: sha512-VMBFLYgFuRdfeNQSMLbxGSLfmXL/xc+OO+BZp41Za/NRDBet/BNbkRJrYzCUu0u4GU0i/ml2dtT8b9qgkw9z6Q==} engines: {node: '>= 4.0'} - deprecated: Please upgrade to superagent v10.2.2+, see release notes at https://github.com/forwardemail/superagent/releases/tag/v10.2.2 - maintenance is supported by Forward Email @ https://forwardemail.net + deprecated: Please upgrade to v9.0.0+ as we have fixed a public vulnerability with formidable dependency. Note that v9.0.0+ requires Node.js v14.18.0+. See https://github.com/ladjs/superagent/pull/1800 for insight. This project is supported and maintained by the team at Forward Email @ https://forwardemail.net superagent@4.1.0: resolution: {integrity: sha512-FT3QLMasz0YyCd4uIi5HNe+3t/onxMyEho7C3PSqmti3Twgy2rXT4fmkTz6wRL6bTF4uzPcfkUCa8u4JWHw8Ag==} engines: {node: '>= 6.0'} - deprecated: Please upgrade to superagent v10.2.2+, see release notes at https://github.com/forwardemail/superagent/releases/tag/v10.2.2 - maintenance is supported by Forward Email @ https://forwardemail.net + deprecated: Please upgrade to v9.0.0+ as we have fixed a public vulnerability with formidable dependency. Note that v9.0.0+ requires Node.js v14.18.0+. See https://github.com/ladjs/superagent/pull/1800 for insight. This project is supported and maintained by the team at Forward Email @ https://forwardemail.net superagent@5.3.1: resolution: {integrity: sha512-wjJ/MoTid2/RuGCOFtlacyGNxN9QLMgcpYLDQlWFIhhdJ93kNscFonGvrpAHSCVjRVj++DGCglocF7Aej1KHvQ==} engines: {node: '>= 7.0.0'} - deprecated: Please upgrade to superagent v10.2.2+, see release notes at https://github.com/forwardemail/superagent/releases/tag/v10.2.2 - maintenance is supported by Forward Email @ https://forwardemail.net + deprecated: Please upgrade to v9.0.0+ as we have fixed a public vulnerability with formidable dependency. Note that v9.0.0+ requires Node.js v14.18.0+. See https://github.com/ladjs/superagent/pull/1800 for insight. This project is supported and maintained by the team at Forward Email @ https://forwardemail.net supports-color@10.2.2: resolution: {integrity: sha512-SS+jx45GF1QjgEXQx4NJZV9ImqmO2NPz5FNsIHrsDjh2YsHnawpan7SNQ1o8NuhrbHZy9AZhIoCUiCeaW/C80g==} @@ -39125,7 +39119,6 @@ snapshots: transitivePeerDependencies: - rolldown - rollup - - supports-color '@putout/operator-parens@2.0.0(rolldown@1.0.0-beta.9)(rollup@4.53.2)': dependencies: