-
Notifications
You must be signed in to change notification settings - Fork 5.5k
New Components - botstar #16757
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 - botstar #16757
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
70d46c2
new components
michelle0927 e85cbe0
pnpm-lock.yaml
michelle0927 4cd36f2
pnpm-lock.yaml
michelle0927 7efe34f
package.json
michelle0927 339ca63
Merge remote-tracking branch 'origin/master' into issue-13214
michelle0927 6cff12e
pnpm-lock.yaml
michelle0927 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,37 @@ | ||
| import botstar from "../../botstar.app.mjs"; | ||
|
|
||
| export default { | ||
| key: "botstar-send-message", | ||
| name: "Send Message", | ||
| description: "Send a message to a user via BotStar. [See the docs](https://apis.botstar.com/docs/#/Messages/post_messages)", | ||
| version: "0.0.1", | ||
| type: "action", | ||
| props: { | ||
| botstar, | ||
| recipientId: { | ||
| type: "string", | ||
| label: "Recipient ID", | ||
| description: "The user ID to send the message to. To find a user ID, login to app.botstar.com > Report & Insight > Audience > click on a chat user The User ID is displayed under the information on the left of the screen", | ||
| }, | ||
| message: { | ||
| type: "string", | ||
| label: "Message", | ||
| description: "The text message to send", | ||
| }, | ||
| }, | ||
| async run({ $ }) { | ||
| const response = await this.botstar.sendMessage({ | ||
| $, | ||
| data: { | ||
| recipient: { | ||
| id: this.recipientId, | ||
| }, | ||
| message: { | ||
| text: this.message, | ||
| }, | ||
| }, | ||
| }); | ||
| $.export("$summary", `Sent message to user ${this.recipientId}`); | ||
| 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,107 @@ | ||
| import { axios } from "@pipedream/platform"; | ||
|
|
||
| export default { | ||
| type: "app", | ||
| app: "botstar", | ||
| propDefinitions: {}, | ||
| propDefinitions: { | ||
| botId: { | ||
| type: "string", | ||
| label: "Bot ID", | ||
| description: "The ID of the bot to use for the request", | ||
| async options() { | ||
| const bots = await this.listBots(); | ||
| return bots?.map(({ | ||
| id: value, name: label, | ||
| }) => ({ | ||
| label, | ||
| value, | ||
| })) || []; | ||
| }, | ||
| }, | ||
| entityId: { | ||
| type: "string", | ||
| label: "CMS Entity ID", | ||
| description: "The ID of the CMS entity to use for the request", | ||
| async options({ botId }) { | ||
| const cmsEntities = await this.listCmsEntities({ | ||
| botId, | ||
| }); | ||
| return cmsEntities?.map(({ | ||
| id: value, name: label, | ||
| }) => ({ | ||
| label, | ||
| value, | ||
| })) || []; | ||
| }, | ||
| }, | ||
| }, | ||
| methods: { | ||
| // this.$auth contains connected account data | ||
| authKeys() { | ||
| console.log(Object.keys(this.$auth)); | ||
| _baseUrl() { | ||
| return "https://apis.botstar.com/v1"; | ||
| }, | ||
| _makeRequest({ | ||
| $ = this, path, ...opts | ||
| }) { | ||
| return axios($, { | ||
| url: `${this._baseUrl()}${path}`, | ||
| headers: { | ||
| Authorization: `Bearer ${this.$auth.access_token}`, | ||
| }, | ||
| ...opts, | ||
| }); | ||
michelle0927 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| }, | ||
| listBots(opts = {}) { | ||
| return this._makeRequest({ | ||
| path: "/bots", | ||
| ...opts, | ||
| }); | ||
| }, | ||
| listCmsEntities({ | ||
| botId, ...opts | ||
| }) { | ||
| return this._makeRequest({ | ||
| path: `/bots/${botId}/cms_entities`, | ||
| ...opts, | ||
| }); | ||
| }, | ||
| listCmsEntityItems({ | ||
| botId, entityId, ...opts | ||
| }) { | ||
| return this._makeRequest({ | ||
| path: `/bots/${botId}/cms_entities/${entityId}/items`, | ||
| ...opts, | ||
| }); | ||
| }, | ||
michelle0927 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| sendMessage(opts = {}) { | ||
| return this._makeRequest({ | ||
| method: "POST", | ||
| path: "/messages", | ||
| ...opts, | ||
| }); | ||
| }, | ||
| async *paginate({ | ||
| fn, args, max, | ||
| }) { | ||
| args = { | ||
| ...args, | ||
| params: { | ||
| ...args?.params, | ||
| page: 1, | ||
| limit: 100, | ||
| }, | ||
| }; | ||
| let total, count = 1; | ||
| do { | ||
| const items = await fn(args); | ||
| for (const item of items) { | ||
| yield item; | ||
| if (max && ++count >= max) { | ||
| return; | ||
| } | ||
| } | ||
| total = items?.length; | ||
| args.params.page++; | ||
| } while (total === args.params.limit); | ||
| }, | ||
| }, | ||
| }; | ||
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
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,14 @@ | ||
| import botstar from "../../botstar.app.mjs"; | ||
| import { DEFAULT_POLLING_SOURCE_TIMER_INTERVAL } from "@pipedream/platform"; | ||
|
|
||
| export default { | ||
| props: { | ||
| botstar, | ||
| timer: { | ||
| type: "$.interface.timer", | ||
| default: { | ||
| intervalSeconds: DEFAULT_POLLING_SOURCE_TIMER_INTERVAL, | ||
| }, | ||
| }, | ||
| }, | ||
| }; |
29 changes: 29 additions & 0 deletions
29
components/botstar/sources/new-bot-created/new-bot-created.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,29 @@ | ||
| import common from "../common/base.mjs"; | ||
| import sampleEmit from "./test-event.mjs"; | ||
|
|
||
| export default { | ||
| ...common, | ||
| key: "botstar-new-bot-created", | ||
| name: "New Bot Created", | ||
| description: "Emit new event when a new bot is created in BotStar. [See the documentation](https://apis.botstar.com/docs/#/Bots/get_bots_)", | ||
| version: "0.0.1", | ||
| type: "source", | ||
| dedupe: "unique", | ||
| methods: { | ||
| generateMeta(bot) { | ||
| return { | ||
| id: bot.id, | ||
| summary: `New Bot: ${bot.name}`, | ||
| ts: Date.now(), | ||
| }; | ||
| }, | ||
| }, | ||
| async run() { | ||
| const bots = await this.botstar.listBots(); | ||
| for (const bot of bots) { | ||
| const meta = this.generateMeta(bot); | ||
| this.$emit(bot, meta); | ||
| } | ||
| }, | ||
| sampleEmit, | ||
| }; |
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,5 @@ | ||
| export default { | ||
| "id": "s13d855e0-366f-11f0-8b00-d5c347dbdc20", | ||
| "name": "Sample Tutorial Bot", | ||
| "team_name": "Team" | ||
| } |
43 changes: 43 additions & 0 deletions
43
components/botstar/sources/new-cms-entity-created/new-cms-entity-created.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,43 @@ | ||
| import common from "../common/base.mjs"; | ||
| import sampleEmit from "./test-event.mjs"; | ||
|
|
||
| export default { | ||
| ...common, | ||
| key: "botstar-new-cms-entity-created", | ||
| name: "New CMS Entity Created", | ||
| description: "Emit new event when a new CMS entity is created in a BotStar bot. [See the documentation](https://apis.botstar.com/docs/#/CMS%20Entities/get_bots__botId__cms_entities)", | ||
| version: "0.0.1", | ||
| type: "source", | ||
| dedupe: "unique", | ||
| props: { | ||
| ...common.props, | ||
| botId: { | ||
| propDefinition: [ | ||
| common.props.botstar, | ||
| "botId", | ||
| ], | ||
| }, | ||
| }, | ||
| methods: { | ||
| generateMeta(entity) { | ||
| return { | ||
| id: entity.id, | ||
| summary: `New CMS Entity: ${entity.name}`, | ||
| ts: Date.now(), | ||
| }; | ||
| }, | ||
| }, | ||
| async run() { | ||
| const entities = await this.botstar.listCmsEntities({ | ||
| botId: this.botId, | ||
| }); | ||
| if (!entities?.length) { | ||
| return; | ||
| } | ||
| for (const entity of entities.reverse()) { | ||
| const meta = this.generateMeta(entity); | ||
| this.$emit(entity, meta); | ||
| } | ||
| }, | ||
| sampleEmit, | ||
| }; |
26 changes: 26 additions & 0 deletions
26
components/botstar/sources/new-cms-entity-created/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,26 @@ | ||
| export default { | ||
| "id": "s13d85634-366f-11f0-8b00-d5c347dbdc20", | ||
| "name": "Coffee", | ||
| "fields": [ | ||
| { | ||
| "unique_name": "name", | ||
| "name": "Name", | ||
| "data_type": "text" | ||
| }, | ||
| { | ||
| "unique_name": "status", | ||
| "name": "Status", | ||
| "data_type": "single_option" | ||
| }, | ||
| { | ||
| "unique_name": "short_description", | ||
| "name": "Short Description", | ||
| "data_type": "free_text" | ||
| }, | ||
| { | ||
| "unique_name": "photo", | ||
| "name": "Photo", | ||
| "data_type": "image" | ||
| } | ||
| ] | ||
| } |
53 changes: 53 additions & 0 deletions
53
components/botstar/sources/new-cms-entity-item-created/new-cms-entity-item-created.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,53 @@ | ||
| import common from "../common/base.mjs"; | ||
| import sampleEmit from "./test-event.mjs"; | ||
|
|
||
| export default { | ||
| ...common, | ||
| key: "botstar-new-cms-entity-item-created", | ||
| name: "New CMS Entity Item Created", | ||
| description: "Emit new event when a new item is created in a CMS entity in BotStar. [See the documentation](https://apis.botstar.com/docs/#/CMS%20Entity%20Items/get_bots__botId__cms_entities__entityId__items)", | ||
| version: "0.0.1", | ||
| type: "source", | ||
| dedupe: "unique", | ||
| props: { | ||
| ...common.props, | ||
| botId: { | ||
| propDefinition: [ | ||
| common.props.botstar, | ||
| "botId", | ||
| ], | ||
| }, | ||
| entityId: { | ||
| propDefinition: [ | ||
| common.props.botstar, | ||
| "entityId", | ||
| (c) => ({ | ||
| botId: c.botId, | ||
| }), | ||
| ], | ||
| }, | ||
| }, | ||
| methods: { | ||
| generateMeta(item) { | ||
| return { | ||
| id: item._id, | ||
| summary: `New CMS Entity Item: ${item.name || item.id}`, | ||
| ts: Date.now(), | ||
| }; | ||
| }, | ||
| }, | ||
| async run() { | ||
| const results = this.botstar.paginate({ | ||
| fn: this.botstar.listCmsEntityItems, | ||
| args: { | ||
| botId: this.botId, | ||
| entityId: this.entityId, | ||
| }, | ||
| }); | ||
| for await (const item of results) { | ||
| const meta = this.generateMeta(item); | ||
| this.$emit(item, meta); | ||
| } | ||
| }, | ||
| sampleEmit, | ||
| }; |
8 changes: 8 additions & 0 deletions
8
components/botstar/sources/new-cms-entity-item-created/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,8 @@ | ||
| export default { | ||
| "name": "Cappuccino", | ||
| "status": "enabled", | ||
| "entity_id": "s13d85634-366f-11f0-8b00-d5c347dbdc20", | ||
| "_id": "s13d85632-366f-11f0-8b00-d5c347dbdc20", | ||
| "short_description": "Cappuccino Coffee", | ||
| "photo": "https://app-upload-assets.cdn.botstar.com/d72e0570-bfdb-11e7-affb-8b31a0f64612/image/1517097658980/cappuccino.jpg" | ||
| } |
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.