Skip to content
Merged
Show file tree
Hide file tree
Changes from 3 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
37 changes: 37 additions & 0 deletions components/botstar/actions/send-message/send-message.mjs
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;
},
};
104 changes: 100 additions & 4 deletions components/botstar/botstar.app.mjs
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,
});
},
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,
});
},
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);
},
},
};
2 changes: 1 addition & 1 deletion components/botstar/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@pipedream/botstar",
"version": "0.6.0",
"version": "0.7.0",
"description": "Pipedream botstar Components",
"main": "botstar.app.mjs",
"keywords": [
Expand Down
14 changes: 14 additions & 0 deletions components/botstar/sources/common/base.mjs
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 components/botstar/sources/new-bot-created/new-bot-created.mjs
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,
};
5 changes: 5 additions & 0 deletions components/botstar/sources/new-bot-created/test-event.mjs
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"
}
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 components/botstar/sources/new-cms-entity-created/test-event.mjs
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"
}
]
}
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,
};
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"
}
8 changes: 0 additions & 8 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading