Skip to content

Commit 1e54be1

Browse files
authored
New Components - landbot (#16804)
* new components * pnpm-lock.yaml
1 parent 3465789 commit 1e54be1

File tree

7 files changed

+315
-0
lines changed

7 files changed

+315
-0
lines changed
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
import landbot from "../../landbot.app.mjs";
2+
3+
export default {
4+
key: "landbot-send-image",
5+
name: "Send Image",
6+
description: "Send an image to a customer via Landbot. [See the docs](https://api.landbot.io/#api-Customers-PostHttpsApiLandbotIoV1CustomersCustomer_idSend_image)",
7+
version: "0.0.1",
8+
type: "action",
9+
props: {
10+
landbot,
11+
customerId: {
12+
propDefinition: [
13+
landbot,
14+
"customerId",
15+
],
16+
},
17+
imageUrl: {
18+
type: "string",
19+
label: "Image URL",
20+
description: "The URL of the image to send",
21+
},
22+
caption: {
23+
type: "string",
24+
label: "Caption",
25+
description: "Optional caption for the image",
26+
optional: true,
27+
},
28+
},
29+
async run({ $ }) {
30+
const response = await this.landbot.sendImageMessage({
31+
$,
32+
customerId: this.customerId,
33+
data: {
34+
url: this.imageUrl,
35+
caption: this.caption,
36+
},
37+
});
38+
$.export("$summary", `Successfully sent image to Customer ID: ${this.customerId}`);
39+
return response;
40+
},
41+
};
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
import landbot from "../../landbot.app.mjs";
2+
3+
export default {
4+
key: "landbot-send-text-message",
5+
name: "Send Text Message",
6+
description: "Send a text message to a customer. [See the documentation](https://api.landbot.io/#api-Customers-PostHttpsApiLandbotIoV1CustomersCustomer_idSend_text)",
7+
version: "0.0.1",
8+
type: "action",
9+
props: {
10+
landbot,
11+
customerId: {
12+
propDefinition: [
13+
landbot,
14+
"customerId",
15+
],
16+
},
17+
message: {
18+
type: "string",
19+
label: "Message",
20+
description: "The message to send to the customer",
21+
},
22+
},
23+
async run({ $ }) {
24+
const response = await this.landbot.sendTextMessage({
25+
$,
26+
customerId: this.customerId,
27+
data: {
28+
message: this.message,
29+
},
30+
});
31+
$.export("$summary", `Successfully sent message to Customer ID: ${this.customerId}`);
32+
return response;
33+
},
34+
};

components/landbot/landbot.app.mjs

Lines changed: 107 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,107 @@
1+
import { axios } from "@pipedream/platform";
2+
const DEFAULT_LIMIT = 20;
3+
4+
export default {
5+
type: "app",
6+
app: "landbot",
7+
propDefinitions: {
8+
customerId: {
9+
type: "string",
10+
label: "Customer ID",
11+
description: "The ID of the customer to message",
12+
async options({ page }) {
13+
const { customers } = await this.listCustomers({
14+
params: {
15+
limit: DEFAULT_LIMIT,
16+
offset: page * DEFAULT_LIMIT,
17+
},
18+
});
19+
return customers.map((customer) => ({
20+
label: customer.name,
21+
value: customer.id,
22+
}));
23+
},
24+
},
25+
channelId: {
26+
type: "string",
27+
label: "Channel ID",
28+
description: "The ID of the channel to create a webhook for",
29+
async options({ page }) {
30+
const { channels } = await this.listChannels({
31+
params: {
32+
limit: DEFAULT_LIMIT,
33+
offset: page * DEFAULT_LIMIT,
34+
},
35+
});
36+
return channels.map((channel) => ({
37+
label: channel.name,
38+
value: channel.id,
39+
}));
40+
},
41+
},
42+
},
43+
methods: {
44+
_baseUrl() {
45+
return "https://api.landbot.io/v1";
46+
},
47+
_makeRequest({
48+
$ = this, path, ...opts
49+
}) {
50+
return axios($, {
51+
url: `${this._baseUrl()}${path}`,
52+
headers: {
53+
Authorization: `Token ${this.$auth.api_token}`,
54+
},
55+
...opts,
56+
});
57+
},
58+
createWebhook({
59+
channelId, ...opts
60+
}) {
61+
return this._makeRequest({
62+
path: `/channels/${channelId}/message_hooks/`,
63+
method: "POST",
64+
...opts,
65+
});
66+
},
67+
deleteWebhook({
68+
channelId, webhookId, ...opts
69+
}) {
70+
return this._makeRequest({
71+
path: `/channels/${channelId}/message_hooks/${webhookId}/`,
72+
method: "DELETE",
73+
...opts,
74+
});
75+
},
76+
listCustomers(opts = {}) {
77+
return this._makeRequest({
78+
path: "/customers/",
79+
...opts,
80+
});
81+
},
82+
listChannels(opts = {}) {
83+
return this._makeRequest({
84+
path: "/channels/",
85+
...opts,
86+
});
87+
},
88+
sendTextMessage({
89+
customerId, ...opts
90+
}) {
91+
return this._makeRequest({
92+
path: `/customers/${customerId}/send_text/`,
93+
method: "POST",
94+
...opts,
95+
});
96+
},
97+
sendImageMessage({
98+
customerId, ...opts
99+
}) {
100+
return this._makeRequest({
101+
path: `/customers/${customerId}/send_image/`,
102+
method: "POST",
103+
...opts,
104+
});
105+
},
106+
},
107+
};

components/landbot/package.json

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
{
2+
"name": "@pipedream/landbot",
3+
"version": "0.0.1",
4+
"description": "Pipedream Landbot Components",
5+
"main": "landbot.app.mjs",
6+
"keywords": [
7+
"pipedream",
8+
"landbot"
9+
],
10+
"author": "Pipedream <[email protected]> (https://pipedream.com/)",
11+
"publishConfig": {
12+
"access": "public"
13+
},
14+
"dependencies": {
15+
"@pipedream/platform": "^3.0.3"
16+
}
17+
}
Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
import landbot from "../../landbot.app.mjs";
2+
import sampleEmit from "./test-event.mjs";
3+
4+
export default {
5+
key: "landbot-new-message-in-channel",
6+
name: "New Message in Channel (Instant)",
7+
description: "Emit new events when a new message is sent in a channel. [See the documentation](https://api.landbot.io/#api-MessageHooks-PostHttpsApiLandbotIoV1ChannelsChannel_idMessage_hooks)",
8+
version: "0.0.1",
9+
type: "source",
10+
dedupe: "unique",
11+
props: {
12+
landbot,
13+
db: "$.service.db",
14+
http: "$.interface.http",
15+
channelId: {
16+
propDefinition: [
17+
landbot,
18+
"channelId",
19+
],
20+
},
21+
},
22+
hooks: {
23+
async activate() {
24+
const { hook } = await this.landbot.createWebhook({
25+
channelId: this.channelId,
26+
data: {
27+
url: this.http.endpoint,
28+
},
29+
});
30+
this._setHookId(hook.id);
31+
},
32+
async deactivate() {
33+
const webhookId = this._getHookId();
34+
if (webhookId) {
35+
await this.landbot.deleteWebhook({
36+
channelId: this.channelId,
37+
webhookId,
38+
});
39+
}
40+
},
41+
},
42+
methods: {
43+
_getHookId() {
44+
return this.db.get("hookId");
45+
},
46+
_setHookId(hookId) {
47+
this.db.set("hookId", hookId);
48+
},
49+
generateMeta(message) {
50+
return {
51+
id: message.timestamp,
52+
summary: `New ${message.type} message in channel`,
53+
ts: message.timestamp,
54+
};
55+
},
56+
},
57+
async run(event) {
58+
const { body } = event;
59+
if (!body || !body.messages) {
60+
return;
61+
}
62+
for (const message of body.messages) {
63+
const meta = this.generateMeta(message);
64+
this.$emit(message, meta);
65+
}
66+
},
67+
sampleEmit,
68+
};
69+
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
export default {
2+
"_raw": {
3+
"uuid": "f00627c8-394f-493b-b8a5-e9cd44b5c319",
4+
"extra": {},
5+
"chat": 473716610,
6+
"ui_key": null,
7+
"type": "text",
8+
"channel": 2955840,
9+
"timestamp": 1747943104.006807,
10+
"author_type": "agent",
11+
"author_uuid": "ce8013ec-ddd2-4711-849a-a5b91cf69ada",
12+
"read": false,
13+
"seq": null,
14+
"samurai": 794028,
15+
"message": "hello world",
16+
"rich_text": null
17+
},
18+
"type": "text",
19+
"data": {
20+
"body": "hello world"
21+
},
22+
"timestamp": 1747943104.006807,
23+
"sender": {
24+
"id": 794028,
25+
"name": "",
26+
"type": "agent"
27+
},
28+
"customer": {
29+
"agent_id": 794028,
30+
"name": "",
31+
"country": "United States",
32+
"url": "https://landbot.site/v3/H-2955840-YBOL4P79UNIGME5S/index.html",
33+
"id": 473548616,
34+
"archived": false
35+
},
36+
"channel": {
37+
"id": 2955840,
38+
"name": "New bot",
39+
"type": "landbot"
40+
}
41+
}

pnpm-lock.yaml

Lines changed: 6 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)