Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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;
},
};
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;
},
};
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;
},
};
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;
},
};
74 changes: 70 additions & 4 deletions components/line_messaging_api/line_messaging_api.app.mjs
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,
});
},
},
};
7 changes: 5 additions & 2 deletions components/line_messaging_api/package.json
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": [
Expand All @@ -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 components/line_messaging_api/sources/common/base-webhook.mjs
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");
},
},
};
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,
};
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
}
}
Loading
Loading