diff --git a/components/line_messaging_api/actions/send-broadcast-message/send-broadcast-message.mjs b/components/line_messaging_api/actions/send-broadcast-message/send-broadcast-message.mjs new file mode 100644 index 0000000000000..e3e950d61e6e7 --- /dev/null +++ b/components/line_messaging_api/actions/send-broadcast-message/send-broadcast-message.mjs @@ -0,0 +1,40 @@ +import line from "../../line_messaging_api.app.mjs"; + +export default { + name: "Send Broadcast Message", + description: "Sends a broadcast message to all users. [See the documentation](https://developers.line.biz/en/reference/messaging-api/#send-broadcast-message)", + key: "line_messaging_api-send-broadcast-message", + version: "0.0.1", + type: "action", + props: { + line, + message: { + propDefinition: [ + line, + "message", + ], + }, + notificationDisabled: { + propDefinition: [ + line, + "notificationDisabled", + ], + }, + }, + async run({ $ }) { + const response = await this.line.sendBroadcastMessage({ + $, + data: { + messages: [ + { + type: "text", + text: this.message, + }, + ], + notificationDisabled: this.notificationDisabled ?? false, + }, + }); + $.export("$summary", "Successfully sent broadcast message"); + return response; + }, +}; diff --git a/components/line_messaging_api/actions/send-multicast-message/send-multicast-message.mjs b/components/line_messaging_api/actions/send-multicast-message/send-multicast-message.mjs new file mode 100644 index 0000000000000..2d8eb33d4f433 --- /dev/null +++ b/components/line_messaging_api/actions/send-multicast-message/send-multicast-message.mjs @@ -0,0 +1,46 @@ +import line from "../../line_messaging_api.app.mjs"; + +export default { + name: "Send Multicast Message", + description: "Sends a multicast message to a list of users. [See the documentation](https://developers.line.biz/en/reference/messaging-api/#send-multicast-message)", + key: "line_messaging_api-send-multicast-message", + version: "0.0.1", + type: "action", + props: { + line, + to: { + label: "To", + type: "string[]", + description: "An array of user IDs to send the message to", + }, + message: { + propDefinition: [ + line, + "message", + ], + }, + notificationDisabled: { + propDefinition: [ + line, + "notificationDisabled", + ], + }, + }, + async run({ $ }) { + const response = await this.line.sendMulticastMessage({ + $, + data: { + to: this.to, + messages: [ + { + type: "text", + text: this.message, + }, + ], + notificationDisabled: this.notificationDisabled ?? false, + }, + }); + $.export("$summary", `Successfully sent multicast message to: ${this.to}`); + return response; + }, +}; diff --git a/components/line_messaging_api/actions/send-push-message/send-push-message.mjs b/components/line_messaging_api/actions/send-push-message/send-push-message.mjs new file mode 100644 index 0000000000000..20f11b77df96d --- /dev/null +++ b/components/line_messaging_api/actions/send-push-message/send-push-message.mjs @@ -0,0 +1,46 @@ +import line from "../../line_messaging_api.app.mjs"; + +export default { + name: "Send Push Message", + description: "Sends a push message to a user. [See the documentation](https://developers.line.biz/en/reference/messaging-api/#send-push-message)", + key: "line_messaging_api-send-push-message", + version: "0.0.1", + type: "action", + props: { + line, + to: { + label: "To", + type: "string", + description: "The ID of user, group, or room the message will be sent to", + }, + message: { + propDefinition: [ + line, + "message", + ], + }, + notificationDisabled: { + propDefinition: [ + line, + "notificationDisabled", + ], + }, + }, + async run({ $ }) { + const response = await this.line.sendPushMessage({ + $, + data: { + to: this.to, + messages: [ + { + type: "text", + text: this.message, + }, + ], + notificationDisabled: this.notificationDisabled ?? false, + }, + }); + $.export("$summary", `Successfully sent push message to: ${this.to}`); + return response; + }, +}; diff --git a/components/line_messaging_api/actions/send-reply-message/send-reply-message.mjs b/components/line_messaging_api/actions/send-reply-message/send-reply-message.mjs new file mode 100644 index 0000000000000..f7e247e28fdd7 --- /dev/null +++ b/components/line_messaging_api/actions/send-reply-message/send-reply-message.mjs @@ -0,0 +1,46 @@ +import line from "../../line_messaging_api.app.mjs"; + +export default { + name: "Send Reply Message", + description: "Sends a reply message to a user. [See the documentation](https://developers.line.biz/en/reference/messaging-api/#send-reply-message)", + key: "line_messaging_api-send-reply-message", + version: "0.0.1", + type: "action", + props: { + line, + replyToken: { + label: "Message Reply Token", + type: "string", + description: "Reply token of the received message", + }, + message: { + propDefinition: [ + line, + "message", + ], + }, + notificationDisabled: { + propDefinition: [ + line, + "notificationDisabled", + ], + }, + }, + async run({ $ }) { + const response = await this.line.sendReplyMessage({ + $, + data: { + replyToken: this.replyToken, + messages: [ + { + type: "text", + text: this.message, + }, + ], + notificationDisabled: this.notificationDisabled ?? false, + }, + }); + $.export("$summary", `Successfully sent reply message to: ${this.replyToken}`); + return response; + }, +}; diff --git a/components/line_messaging_api/line_messaging_api.app.mjs b/components/line_messaging_api/line_messaging_api.app.mjs index e003d37a606a0..f1ca6dae47aca 100644 --- a/components/line_messaging_api/line_messaging_api.app.mjs +++ b/components/line_messaging_api/line_messaging_api.app.mjs @@ -1,11 +1,77 @@ +import { axios } from "@pipedream/platform"; + export default { type: "app", app: "line_messaging_api", - propDefinitions: {}, + propDefinitions: { + message: { + label: "Message Text", + type: "string", + description: "The text of message to send", + }, + notificationDisabled: { + label: "Disable Notification", + type: "boolean", + description: "The user will receive a push notification when the message is sent", + default: false, + optional: true, + }, + }, methods: { - // this.$auth contains connected account data - authKeys() { - console.log(Object.keys(this.$auth)); + _baseUrl() { + return "https://api.line.me/v2/bot"; + }, + _makeRequest({ + $ = this, path, ...opts + }) { + return axios($, { + url: `${this._baseUrl()}${path}`, + headers: { + Authorization: `Bearer ${this.$auth.long_lived_channel_access_token}`, + }, + ...opts, + }); + }, + createWebhook(opts = {}) { + return this._makeRequest({ + path: "/channel/webhook/endpoint", + method: "PUT", + ...opts, + }); + }, + getWebhook(opts = {}) { + return this._makeRequest({ + path: "/channel/webhook/endpoint", + ...opts, + }); + }, + sendPushMessage(opts = {}) { + return this._makeRequest({ + path: "/message/push", + method: "POST", + ...opts, + }); + }, + sendReplyMessage(opts = {}) { + return this._makeRequest({ + path: "/message/reply", + method: "POST", + ...opts, + }); + }, + sendMulticastMessage(opts = {}) { + return this._makeRequest({ + path: "/message/multicast", + method: "POST", + ...opts, + }); + }, + sendBroadcastMessage(opts = {}) { + return this._makeRequest({ + path: "/message/broadcast", + method: "POST", + ...opts, + }); }, }, }; diff --git a/components/line_messaging_api/package.json b/components/line_messaging_api/package.json index 7e7318fc77310..f4462a6878bf5 100644 --- a/components/line_messaging_api/package.json +++ b/components/line_messaging_api/package.json @@ -1,6 +1,6 @@ { "name": "@pipedream/line_messaging_api", - "version": "0.0.1", + "version": "0.1.0", "description": "Pipedream LINE Messaging API Components", "main": "line_messaging_api.app.mjs", "keywords": [ @@ -11,5 +11,8 @@ "author": "Pipedream (https://pipedream.com/)", "publishConfig": { "access": "public" + }, + "dependencies": { + "@pipedream/platform": "^3.1.0" } -} \ No newline at end of file +} diff --git a/components/line_messaging_api/sources/common/base-webhook.mjs b/components/line_messaging_api/sources/common/base-webhook.mjs new file mode 100644 index 0000000000000..1ad79b9c6141d --- /dev/null +++ b/components/line_messaging_api/sources/common/base-webhook.mjs @@ -0,0 +1,26 @@ +import line from "../../line_messaging_api.app.mjs"; +import { ConfigurationError } from "@pipedream/platform"; + +export default { + props: { + line, + http: "$.interface.http", + }, + hooks: { + async activate() { + try { + await this.line.getWebhook(); + await this.line.createWebhook({ + data: { + endpoint: this.http.endpoint, + }, + }); + console.log("Webhook created successfully."); + console.log("If you are not receiving webhooks, please confirm you have Use Webhooks enabled in your Line Developer Console:"); + } catch (error) { + throw new ConfigurationError("Error creating webhook. Please make sure you have enabled webhooks in your Line Developer Console."); + } + console.log("https://developers.line.biz/en/docs/messaging-api/building-bot/#setting-webhook-url"); + }, + }, +}; diff --git a/components/line_messaging_api/sources/new-message-received/new-message-received.mjs b/components/line_messaging_api/sources/new-message-received/new-message-received.mjs new file mode 100644 index 0000000000000..76a53a3ae71ef --- /dev/null +++ b/components/line_messaging_api/sources/new-message-received/new-message-received.mjs @@ -0,0 +1,34 @@ +import common from "../common/base-webhook.mjs"; +import sampleEmit from "./test-event.mjs"; + +export default { + ...common, + key: "line_messaging_api-new-message-received", + name: "New Message Received (Instant)", + description: "Emit new event for every received message in a channel", + version: "0.0.1", + type: "source", + dedupe: "unique", + methods: { + ...common.methods, + generateMeta(event) { + return { + id: event.message.id, + summary: event.message.text, + ts: event.timestamp, + }; + }, + }, + async run({ body }) { + if (!body?.events) { + return; + } + body.events.forEach((event) => { + if (event.type === "message") { + const meta = this.generateMeta(event); + this.$emit(event, meta); + } + }); + }, + sampleEmit, +}; diff --git a/components/line_messaging_api/sources/new-message-received/test-event.mjs b/components/line_messaging_api/sources/new-message-received/test-event.mjs new file mode 100644 index 0000000000000..a8312d7c0505e --- /dev/null +++ b/components/line_messaging_api/sources/new-message-received/test-event.mjs @@ -0,0 +1,19 @@ +export default { + "type": "message", + "message": { + "type": "text", + "id": "14353798921116", + "text": "Hello, world" + }, + "timestamp": 1625665242211, + "source": { + "type": "user", + "userId": "U80696558e1aa831..." + }, + "replyToken": "757913772c4646b784d4b7ce46d12671", + "mode": "active", + "webhookEventId": "01FZ74A0TDDPYRVKNK77XKC3ZR", + "deliveryContext": { + "isRedelivery": false + } +} \ No newline at end of file diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 950c7460ce692..f6485133c4d7a 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -7837,7 +7837,11 @@ importers: specifier: ^6.11.1 version: 6.13.1 - components/line_messaging_api: {} + components/line_messaging_api: + dependencies: + '@pipedream/platform': + specifier: ^3.1.0 + version: 3.1.0 components/linear: dependencies: @@ -8774,8 +8778,7 @@ importers: components/minerstat: {} - components/minform: - specifiers: {} + components/minform: {} components/minio: {} @@ -9960,8 +9963,7 @@ importers: specifier: ^1.2.0 version: 1.6.6 - components/outlign: - specifiers: {} + components/outlign: {} components/outline: {} @@ -12180,8 +12182,7 @@ importers: components/sap_s_4hana_cloud: {} - components/sap_s_4hana_cloud_sandbox: - specifiers: {} + components/sap_s_4hana_cloud_sandbox: {} components/sapling: {}