-
Notifications
You must be signed in to change notification settings - Fork 5.5k
Line Messaging API - new/migrated components #18008
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
Merged
Merged
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
40 changes: 40 additions & 0 deletions
40
components/line_messaging_api/actions/send-broadcast-message/send-broadcast-message.mjs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -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; | ||
| }, | ||
| }; |
46 changes: 46 additions & 0 deletions
46
components/line_messaging_api/actions/send-multicast-message/send-multicast-message.mjs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -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; | ||
| }, | ||
| }; | ||
46 changes: 46 additions & 0 deletions
46
components/line_messaging_api/actions/send-push-message/send-push-message.mjs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -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; | ||
| }, | ||
| }; |
46 changes: 46 additions & 0 deletions
46
components/line_messaging_api/actions/send-reply-message/send-reply-message.mjs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -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; | ||
| }, | ||
| }; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -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, | ||
| }); | ||
| }, | ||
| }, | ||
| }; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -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 <[email protected]> (https://pipedream.com/)", | ||
| "publishConfig": { | ||
| "access": "public" | ||
| }, | ||
| "dependencies": { | ||
| "@pipedream/platform": "^3.1.0" | ||
| } | ||
| } | ||
| } | ||
26 changes: 26 additions & 0 deletions
26
components/line_messaging_api/sources/common/base-webhook.mjs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -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"); | ||
| }, | ||
| }, | ||
| }; |
34 changes: 34 additions & 0 deletions
34
components/line_messaging_api/sources/new-message-received/new-message-received.mjs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -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, | ||
| }; |
19 changes: 19 additions & 0 deletions
19
components/line_messaging_api/sources/new-message-received/test-event.mjs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -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 | ||
| } | ||
| } |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.