-
Notifications
You must be signed in to change notification settings - Fork 5.5k
New Components - landbot #16804
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
New Components - landbot #16804
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
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,41 @@ | ||
| import landbot from "../../landbot.app.mjs"; | ||
|
|
||
| export default { | ||
| key: "landbot-send-image", | ||
| name: "Send Image", | ||
| description: "Send an image to a customer via Landbot. [See the docs](https://api.landbot.io/#api-Customers-PostHttpsApiLandbotIoV1CustomersCustomer_idSend_image)", | ||
| version: "0.0.1", | ||
| type: "action", | ||
| props: { | ||
| landbot, | ||
| customerId: { | ||
| propDefinition: [ | ||
| landbot, | ||
| "customerId", | ||
| ], | ||
| }, | ||
| imageUrl: { | ||
| type: "string", | ||
| label: "Image URL", | ||
| description: "The URL of the image to send", | ||
| }, | ||
| caption: { | ||
| type: "string", | ||
| label: "Caption", | ||
| description: "Optional caption for the image", | ||
| optional: true, | ||
| }, | ||
| }, | ||
| async run({ $ }) { | ||
| const response = await this.landbot.sendImageMessage({ | ||
| $, | ||
| customerId: this.customerId, | ||
| data: { | ||
| url: this.imageUrl, | ||
| caption: this.caption, | ||
| }, | ||
| }); | ||
| $.export("$summary", `Successfully sent image to Customer ID: ${this.customerId}`); | ||
| return response; | ||
| }, | ||
michelle0927 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| }; | ||
34 changes: 34 additions & 0 deletions
34
components/landbot/actions/send-text-message/send-text-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,34 @@ | ||
| import landbot from "../../landbot.app.mjs"; | ||
|
|
||
| export default { | ||
| key: "landbot-send-text-message", | ||
| name: "Send Text Message", | ||
| description: "Send a text message to a customer. [See the documentation](https://api.landbot.io/#api-Customers-PostHttpsApiLandbotIoV1CustomersCustomer_idSend_text)", | ||
| version: "0.0.1", | ||
| type: "action", | ||
| props: { | ||
| landbot, | ||
| customerId: { | ||
| propDefinition: [ | ||
| landbot, | ||
| "customerId", | ||
| ], | ||
| }, | ||
| message: { | ||
| type: "string", | ||
| label: "Message", | ||
| description: "The message to send to the customer", | ||
| }, | ||
| }, | ||
| async run({ $ }) { | ||
| const response = await this.landbot.sendTextMessage({ | ||
| $, | ||
| customerId: this.customerId, | ||
| data: { | ||
| message: this.message, | ||
| }, | ||
| }); | ||
| $.export("$summary", `Successfully sent message to Customer ID: ${this.customerId}`); | ||
| 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 |
|---|---|---|
| @@ -0,0 +1,107 @@ | ||
| import { axios } from "@pipedream/platform"; | ||
| const DEFAULT_LIMIT = 20; | ||
|
|
||
| export default { | ||
| type: "app", | ||
| app: "landbot", | ||
| propDefinitions: { | ||
| customerId: { | ||
| type: "string", | ||
| label: "Customer ID", | ||
| description: "The ID of the customer to message", | ||
| async options({ page }) { | ||
| const { customers } = await this.listCustomers({ | ||
| params: { | ||
| limit: DEFAULT_LIMIT, | ||
| offset: page * DEFAULT_LIMIT, | ||
| }, | ||
| }); | ||
| return customers.map((customer) => ({ | ||
| label: customer.name, | ||
| value: customer.id, | ||
| })); | ||
| }, | ||
| }, | ||
| channelId: { | ||
| type: "string", | ||
| label: "Channel ID", | ||
| description: "The ID of the channel to create a webhook for", | ||
| async options({ page }) { | ||
| const { channels } = await this.listChannels({ | ||
| params: { | ||
| limit: DEFAULT_LIMIT, | ||
| offset: page * DEFAULT_LIMIT, | ||
| }, | ||
| }); | ||
| return channels.map((channel) => ({ | ||
| label: channel.name, | ||
| value: channel.id, | ||
| })); | ||
| }, | ||
| }, | ||
| }, | ||
| methods: { | ||
| _baseUrl() { | ||
| return "https://api.landbot.io/v1"; | ||
| }, | ||
| _makeRequest({ | ||
| $ = this, path, ...opts | ||
| }) { | ||
| return axios($, { | ||
| url: `${this._baseUrl()}${path}`, | ||
| headers: { | ||
| Authorization: `Token ${this.$auth.api_token}`, | ||
| }, | ||
| ...opts, | ||
| }); | ||
| }, | ||
michelle0927 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| createWebhook({ | ||
| channelId, ...opts | ||
| }) { | ||
| return this._makeRequest({ | ||
| path: `/channels/${channelId}/message_hooks/`, | ||
| method: "POST", | ||
| ...opts, | ||
| }); | ||
| }, | ||
| deleteWebhook({ | ||
| channelId, webhookId, ...opts | ||
| }) { | ||
| return this._makeRequest({ | ||
| path: `/channels/${channelId}/message_hooks/${webhookId}/`, | ||
| method: "DELETE", | ||
| ...opts, | ||
| }); | ||
| }, | ||
| listCustomers(opts = {}) { | ||
| return this._makeRequest({ | ||
| path: "/customers/", | ||
| ...opts, | ||
| }); | ||
| }, | ||
| listChannels(opts = {}) { | ||
| return this._makeRequest({ | ||
| path: "/channels/", | ||
| ...opts, | ||
| }); | ||
| }, | ||
| sendTextMessage({ | ||
| customerId, ...opts | ||
| }) { | ||
| return this._makeRequest({ | ||
| path: `/customers/${customerId}/send_text/`, | ||
| method: "POST", | ||
| ...opts, | ||
| }); | ||
| }, | ||
| sendImageMessage({ | ||
| customerId, ...opts | ||
| }) { | ||
| return this._makeRequest({ | ||
| path: `/customers/${customerId}/send_image/`, | ||
| 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 |
|---|---|---|
| @@ -0,0 +1,17 @@ | ||
| { | ||
| "name": "@pipedream/landbot", | ||
| "version": "0.0.1", | ||
| "description": "Pipedream Landbot Components", | ||
| "main": "landbot.app.mjs", | ||
| "keywords": [ | ||
| "pipedream", | ||
| "landbot" | ||
| ], | ||
| "author": "Pipedream <support@pipedream.com> (https://pipedream.com/)", | ||
| "publishConfig": { | ||
| "access": "public" | ||
| }, | ||
| "dependencies": { | ||
| "@pipedream/platform": "^3.0.3" | ||
| } | ||
| } |
69 changes: 69 additions & 0 deletions
69
components/landbot/sources/new-message-in-channel/new-message-in-channel.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,69 @@ | ||
| import landbot from "../../landbot.app.mjs"; | ||
| import sampleEmit from "./test-event.mjs"; | ||
|
|
||
| export default { | ||
| key: "landbot-new-message-in-channel", | ||
| name: "New Message in Channel (Instant)", | ||
| 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)", | ||
| version: "0.0.1", | ||
| type: "source", | ||
| dedupe: "unique", | ||
| props: { | ||
| landbot, | ||
| db: "$.service.db", | ||
| http: "$.interface.http", | ||
| channelId: { | ||
| propDefinition: [ | ||
| landbot, | ||
| "channelId", | ||
| ], | ||
| }, | ||
| }, | ||
| hooks: { | ||
| async activate() { | ||
| const { hook } = await this.landbot.createWebhook({ | ||
| channelId: this.channelId, | ||
| data: { | ||
| url: this.http.endpoint, | ||
| }, | ||
| }); | ||
| this._setHookId(hook.id); | ||
| }, | ||
| async deactivate() { | ||
| const webhookId = this._getHookId(); | ||
| if (webhookId) { | ||
| await this.landbot.deleteWebhook({ | ||
| channelId: this.channelId, | ||
| webhookId, | ||
| }); | ||
| } | ||
| }, | ||
| }, | ||
| methods: { | ||
| _getHookId() { | ||
| return this.db.get("hookId"); | ||
| }, | ||
| _setHookId(hookId) { | ||
| this.db.set("hookId", hookId); | ||
| }, | ||
| generateMeta(message) { | ||
| return { | ||
| id: message.timestamp, | ||
| summary: `New ${message.type} message in channel`, | ||
| ts: message.timestamp, | ||
| }; | ||
| }, | ||
michelle0927 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| }, | ||
| async run(event) { | ||
| const { body } = event; | ||
| if (!body || !body.messages) { | ||
| return; | ||
| } | ||
| for (const message of body.messages) { | ||
| const meta = this.generateMeta(message); | ||
| this.$emit(message, meta); | ||
| } | ||
| }, | ||
| sampleEmit, | ||
| }; | ||
|
|
||
41 changes: 41 additions & 0 deletions
41
components/landbot/sources/new-message-in-channel/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,41 @@ | ||
| export default { | ||
| "_raw": { | ||
| "uuid": "f00627c8-394f-493b-b8a5-e9cd44b5c319", | ||
| "extra": {}, | ||
| "chat": 473716610, | ||
| "ui_key": null, | ||
| "type": "text", | ||
| "channel": 2955840, | ||
| "timestamp": 1747943104.006807, | ||
| "author_type": "agent", | ||
| "author_uuid": "ce8013ec-ddd2-4711-849a-a5b91cf69ada", | ||
| "read": false, | ||
| "seq": null, | ||
| "samurai": 794028, | ||
| "message": "hello world", | ||
| "rich_text": null | ||
| }, | ||
| "type": "text", | ||
| "data": { | ||
| "body": "hello world" | ||
| }, | ||
| "timestamp": 1747943104.006807, | ||
| "sender": { | ||
| "id": 794028, | ||
| "name": "", | ||
| "type": "agent" | ||
| }, | ||
| "customer": { | ||
| "agent_id": 794028, | ||
| "name": "", | ||
| "country": "United States", | ||
| "url": "https://landbot.site/v3/H-2955840-YBOL4P79UNIGME5S/index.html", | ||
| "id": 473548616, | ||
| "archived": false | ||
| }, | ||
| "channel": { | ||
| "id": 2955840, | ||
| "name": "New bot", | ||
| "type": "landbot" | ||
| } | ||
| } |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
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.