Skip to content

Commit ee7fd7d

Browse files
authored
Merging pull request #18008
* new components * pnpm-lock.yaml
1 parent d64ace3 commit ee7fd7d

File tree

10 files changed

+337
-7
lines changed

10 files changed

+337
-7
lines changed
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
import line from "../../line_messaging_api.app.mjs";
2+
3+
export default {
4+
name: "Send Broadcast Message",
5+
description: "Sends a broadcast message to all users. [See the documentation](https://developers.line.biz/en/reference/messaging-api/#send-broadcast-message)",
6+
key: "line_messaging_api-send-broadcast-message",
7+
version: "0.0.1",
8+
type: "action",
9+
props: {
10+
line,
11+
message: {
12+
propDefinition: [
13+
line,
14+
"message",
15+
],
16+
},
17+
notificationDisabled: {
18+
propDefinition: [
19+
line,
20+
"notificationDisabled",
21+
],
22+
},
23+
},
24+
async run({ $ }) {
25+
const response = await this.line.sendBroadcastMessage({
26+
$,
27+
data: {
28+
messages: [
29+
{
30+
type: "text",
31+
text: this.message,
32+
},
33+
],
34+
notificationDisabled: this.notificationDisabled ?? false,
35+
},
36+
});
37+
$.export("$summary", "Successfully sent broadcast message");
38+
return response;
39+
},
40+
};
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
import line from "../../line_messaging_api.app.mjs";
2+
3+
export default {
4+
name: "Send Multicast Message",
5+
description: "Sends a multicast message to a list of users. [See the documentation](https://developers.line.biz/en/reference/messaging-api/#send-multicast-message)",
6+
key: "line_messaging_api-send-multicast-message",
7+
version: "0.0.1",
8+
type: "action",
9+
props: {
10+
line,
11+
to: {
12+
label: "To",
13+
type: "string[]",
14+
description: "An array of user IDs to send the message to",
15+
},
16+
message: {
17+
propDefinition: [
18+
line,
19+
"message",
20+
],
21+
},
22+
notificationDisabled: {
23+
propDefinition: [
24+
line,
25+
"notificationDisabled",
26+
],
27+
},
28+
},
29+
async run({ $ }) {
30+
const response = await this.line.sendMulticastMessage({
31+
$,
32+
data: {
33+
to: this.to,
34+
messages: [
35+
{
36+
type: "text",
37+
text: this.message,
38+
},
39+
],
40+
notificationDisabled: this.notificationDisabled ?? false,
41+
},
42+
});
43+
$.export("$summary", `Successfully sent multicast message to: ${this.to}`);
44+
return response;
45+
},
46+
};
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
import line from "../../line_messaging_api.app.mjs";
2+
3+
export default {
4+
name: "Send Push Message",
5+
description: "Sends a push message to a user. [See the documentation](https://developers.line.biz/en/reference/messaging-api/#send-push-message)",
6+
key: "line_messaging_api-send-push-message",
7+
version: "0.0.1",
8+
type: "action",
9+
props: {
10+
line,
11+
to: {
12+
label: "To",
13+
type: "string",
14+
description: "The ID of user, group, or room the message will be sent to",
15+
},
16+
message: {
17+
propDefinition: [
18+
line,
19+
"message",
20+
],
21+
},
22+
notificationDisabled: {
23+
propDefinition: [
24+
line,
25+
"notificationDisabled",
26+
],
27+
},
28+
},
29+
async run({ $ }) {
30+
const response = await this.line.sendPushMessage({
31+
$,
32+
data: {
33+
to: this.to,
34+
messages: [
35+
{
36+
type: "text",
37+
text: this.message,
38+
},
39+
],
40+
notificationDisabled: this.notificationDisabled ?? false,
41+
},
42+
});
43+
$.export("$summary", `Successfully sent push message to: ${this.to}`);
44+
return response;
45+
},
46+
};
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
import line from "../../line_messaging_api.app.mjs";
2+
3+
export default {
4+
name: "Send Reply Message",
5+
description: "Sends a reply message to a user. [See the documentation](https://developers.line.biz/en/reference/messaging-api/#send-reply-message)",
6+
key: "line_messaging_api-send-reply-message",
7+
version: "0.0.1",
8+
type: "action",
9+
props: {
10+
line,
11+
replyToken: {
12+
label: "Message Reply Token",
13+
type: "string",
14+
description: "Reply token of the received message",
15+
},
16+
message: {
17+
propDefinition: [
18+
line,
19+
"message",
20+
],
21+
},
22+
notificationDisabled: {
23+
propDefinition: [
24+
line,
25+
"notificationDisabled",
26+
],
27+
},
28+
},
29+
async run({ $ }) {
30+
const response = await this.line.sendReplyMessage({
31+
$,
32+
data: {
33+
replyToken: this.replyToken,
34+
messages: [
35+
{
36+
type: "text",
37+
text: this.message,
38+
},
39+
],
40+
notificationDisabled: this.notificationDisabled ?? false,
41+
},
42+
});
43+
$.export("$summary", `Successfully sent reply message to: ${this.replyToken}`);
44+
return response;
45+
},
46+
};
Lines changed: 70 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,77 @@
1+
import { axios } from "@pipedream/platform";
2+
13
export default {
24
type: "app",
35
app: "line_messaging_api",
4-
propDefinitions: {},
6+
propDefinitions: {
7+
message: {
8+
label: "Message Text",
9+
type: "string",
10+
description: "The text of message to send",
11+
},
12+
notificationDisabled: {
13+
label: "Disable Notification",
14+
type: "boolean",
15+
description: "The user will receive a push notification when the message is sent",
16+
default: false,
17+
optional: true,
18+
},
19+
},
520
methods: {
6-
// this.$auth contains connected account data
7-
authKeys() {
8-
console.log(Object.keys(this.$auth));
21+
_baseUrl() {
22+
return "https://api.line.me/v2/bot";
23+
},
24+
_makeRequest({
25+
$ = this, path, ...opts
26+
}) {
27+
return axios($, {
28+
url: `${this._baseUrl()}${path}`,
29+
headers: {
30+
Authorization: `Bearer ${this.$auth.long_lived_channel_access_token}`,
31+
},
32+
...opts,
33+
});
34+
},
35+
createWebhook(opts = {}) {
36+
return this._makeRequest({
37+
path: "/channel/webhook/endpoint",
38+
method: "PUT",
39+
...opts,
40+
});
41+
},
42+
getWebhook(opts = {}) {
43+
return this._makeRequest({
44+
path: "/channel/webhook/endpoint",
45+
...opts,
46+
});
47+
},
48+
sendPushMessage(opts = {}) {
49+
return this._makeRequest({
50+
path: "/message/push",
51+
method: "POST",
52+
...opts,
53+
});
54+
},
55+
sendReplyMessage(opts = {}) {
56+
return this._makeRequest({
57+
path: "/message/reply",
58+
method: "POST",
59+
...opts,
60+
});
61+
},
62+
sendMulticastMessage(opts = {}) {
63+
return this._makeRequest({
64+
path: "/message/multicast",
65+
method: "POST",
66+
...opts,
67+
});
68+
},
69+
sendBroadcastMessage(opts = {}) {
70+
return this._makeRequest({
71+
path: "/message/broadcast",
72+
method: "POST",
73+
...opts,
74+
});
975
},
1076
},
1177
};

components/line_messaging_api/package.json

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@pipedream/line_messaging_api",
3-
"version": "0.0.1",
3+
"version": "0.1.0",
44
"description": "Pipedream LINE Messaging API Components",
55
"main": "line_messaging_api.app.mjs",
66
"keywords": [
@@ -11,5 +11,8 @@
1111
"author": "Pipedream <[email protected]> (https://pipedream.com/)",
1212
"publishConfig": {
1313
"access": "public"
14+
},
15+
"dependencies": {
16+
"@pipedream/platform": "^3.1.0"
1417
}
15-
}
18+
}
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
import line from "../../line_messaging_api.app.mjs";
2+
import { ConfigurationError } from "@pipedream/platform";
3+
4+
export default {
5+
props: {
6+
line,
7+
http: "$.interface.http",
8+
},
9+
hooks: {
10+
async activate() {
11+
try {
12+
await this.line.getWebhook();
13+
await this.line.createWebhook({
14+
data: {
15+
endpoint: this.http.endpoint,
16+
},
17+
});
18+
console.log("Webhook created successfully.");
19+
console.log("If you are not receiving webhooks, please confirm you have Use Webhooks enabled in your Line Developer Console:");
20+
} catch (error) {
21+
throw new ConfigurationError("Error creating webhook. Please make sure you have enabled webhooks in your Line Developer Console.");
22+
}
23+
console.log("https://developers.line.biz/en/docs/messaging-api/building-bot/#setting-webhook-url");
24+
},
25+
},
26+
};
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
import common from "../common/base-webhook.mjs";
2+
import sampleEmit from "./test-event.mjs";
3+
4+
export default {
5+
...common,
6+
key: "line_messaging_api-new-message-received",
7+
name: "New Message Received (Instant)",
8+
description: "Emit new event for every received message in a channel",
9+
version: "0.0.1",
10+
type: "source",
11+
dedupe: "unique",
12+
methods: {
13+
...common.methods,
14+
generateMeta(event) {
15+
return {
16+
id: event.message.id,
17+
summary: event.message.text,
18+
ts: event.timestamp,
19+
};
20+
},
21+
},
22+
async run({ body }) {
23+
if (!body?.events) {
24+
return;
25+
}
26+
body.events.forEach((event) => {
27+
if (event.type === "message") {
28+
const meta = this.generateMeta(event);
29+
this.$emit(event, meta);
30+
}
31+
});
32+
},
33+
sampleEmit,
34+
};
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
export default {
2+
"type": "message",
3+
"message": {
4+
"type": "text",
5+
"id": "14353798921116",
6+
"text": "Hello, world"
7+
},
8+
"timestamp": 1625665242211,
9+
"source": {
10+
"type": "user",
11+
"userId": "U80696558e1aa831..."
12+
},
13+
"replyToken": "757913772c4646b784d4b7ce46d12671",
14+
"mode": "active",
15+
"webhookEventId": "01FZ74A0TDDPYRVKNK77XKC3ZR",
16+
"deliveryContext": {
17+
"isRedelivery": false
18+
}
19+
}

pnpm-lock.yaml

Lines changed: 5 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)