Skip to content

Commit 3dc0120

Browse files
authored
New Components - sendbird_ai_chabot (#13898)
* new components * pnpm-lock.yaml * package.json version * update events
1 parent 7567870 commit 3dc0120

File tree

6 files changed

+219
-8
lines changed

6 files changed

+219
-8
lines changed
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
import sendbird from "../../sendbird_ai_chabot.app.mjs";
2+
3+
export default {
4+
key: "sendbird_ai_chabot-send-bot-message",
5+
name: "Send Bot Message",
6+
description: "Sends a bot message to a group channel. [See the documentation](https://sendbird.com/docs/chat/platform-api/v3/bot/sending-a-bot-message/send-a-bot-message)",
7+
version: "0.0.1",
8+
type: "action",
9+
props: {
10+
sendbird,
11+
botId: {
12+
propDefinition: [
13+
sendbird,
14+
"botId",
15+
],
16+
},
17+
channelUrl: {
18+
propDefinition: [
19+
sendbird,
20+
"channelUrl",
21+
],
22+
},
23+
message: {
24+
type: "string",
25+
label: "Message",
26+
description: "Specifies the content of the message sent by the bot",
27+
},
28+
},
29+
async run({ $ }) {
30+
const response = await this.sendbird.sendBotMessage({
31+
$,
32+
botId: this.botId,
33+
data: {
34+
channel_url: this.channelUrl,
35+
message: this.message,
36+
},
37+
});
38+
if (response?.message?.message_id) {
39+
$.export("$summary", `Successfully sent message with ID: ${response.message.message_id}`);
40+
}
41+
return response;
42+
},
43+
};

components/sendbird_ai_chabot/package.json

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@pipedream/sendbird_ai_chabot",
3-
"version": "0.0.1",
3+
"version": "0.1.0",
44
"description": "Pipedream Sendbird AI chabot Components",
55
"main": "sendbird_ai_chabot.app.mjs",
66
"keywords": [
@@ -11,5 +11,8 @@
1111
"author": "Pipedream <[email protected]> (https://pipedream.com/)",
1212
"publishConfig": {
1313
"access": "public"
14+
},
15+
"dependencies": {
16+
"@pipedream/platform": "^3.0.1"
1417
}
15-
}
18+
}
Lines changed: 88 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,94 @@
1+
import { axios } from "@pipedream/platform";
2+
const DEFAULT_LIMIT = 20;
3+
14
export default {
25
type: "app",
36
app: "sendbird_ai_chabot",
4-
propDefinitions: {},
7+
propDefinitions: {
8+
botId: {
9+
type: "string",
10+
label: "Bot ID",
11+
description: "The identifier of a bot",
12+
async options({ page }) {
13+
const { bots } = await this.listBots({
14+
params: {
15+
limit: DEFAULT_LIMIT,
16+
offset: page * DEFAULT_LIMIT,
17+
},
18+
});
19+
return bots?.map(({ bot }) => ({
20+
label: bot.bot_nickname,
21+
value: bot.bot_userid,
22+
})) || [];
23+
},
24+
},
25+
channelUrl: {
26+
type: "string",
27+
label: "Channel URL",
28+
description: "Specifies the URL of the channel",
29+
async options({ page }) {
30+
const { channels } = await this.listGroupChannels({
31+
params: {
32+
limit: DEFAULT_LIMIT,
33+
offset: page * DEFAULT_LIMIT,
34+
},
35+
});
36+
return channels?.map(({
37+
name: label, channel_url: value,
38+
}) => ({
39+
label,
40+
value,
41+
})) || [];
42+
},
43+
},
44+
},
545
methods: {
6-
// this.$auth contains connected account data
7-
authKeys() {
8-
console.log(Object.keys(this.$auth));
46+
_baseUrl() {
47+
return `https://api-${this.$auth.application_id}.sendbird.com/v3`;
48+
},
49+
_headers() {
50+
return {
51+
"Api-Token": `${this.$auth.api_token}`,
52+
};
53+
},
54+
_makeRequest({
55+
$ = this,
56+
path,
57+
...args
58+
}) {
59+
return axios($, {
60+
url: `${this._baseUrl()}${path}`,
61+
headers: this._headers(),
62+
...args,
63+
});
64+
},
65+
updateWebhook(opts = {}) {
66+
return this._makeRequest({
67+
method: "PUT",
68+
path: "/applications/settings/webhook",
69+
...opts,
70+
});
71+
},
72+
listBots(opts = {}) {
73+
return this._makeRequest({
74+
path: "/bots",
75+
...opts,
76+
});
77+
},
78+
listGroupChannels(opts = {}) {
79+
return this._makeRequest({
80+
path: "/group_channels",
81+
...opts,
82+
});
83+
},
84+
sendBotMessage({
85+
botId, ...opts
86+
}) {
87+
return this._makeRequest({
88+
method: "POST",
89+
path: `/bots/${botId}/send`,
90+
...opts,
91+
});
992
},
1093
},
11-
};
94+
};
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
export default [
2+
{
3+
value: "form:submit",
4+
label: "form submitted",
5+
},
6+
{
7+
value: "group_channel:bot_message_send",
8+
label: "bot message sent within group channel",
9+
},
10+
{
11+
value: "group_channel:message_send",
12+
label: "message sent within group channel",
13+
},
14+
];
Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
import sendbird from "../../sendbird_ai_chabot.app.mjs";
2+
import events from "../common/events.mjs";
3+
4+
export default {
5+
key: "sendbird_ai_chabot-new-event-received",
6+
name: "New Event Received (Instant)",
7+
description: "Emit new event when a new webhook event is received.",
8+
version: "0.0.1",
9+
type: "source",
10+
dedupe: "unique",
11+
props: {
12+
sendbird,
13+
http: {
14+
type: "$.interface.http",
15+
customResponse: true,
16+
},
17+
events: {
18+
type: "string[]",
19+
label: "Events",
20+
description: "The events to subscribe to",
21+
options: events,
22+
},
23+
},
24+
hooks: {
25+
async activate() {
26+
await this.sendbird.updateWebhook({
27+
data: {
28+
enabled: true,
29+
url: this.http.endpoint,
30+
enabled_events: this.events,
31+
},
32+
});
33+
},
34+
async deactivate() {
35+
await this.sendbird.updateWebhook({
36+
data: {
37+
enabled: false,
38+
url: this.http.endpoint,
39+
enabled_events: [],
40+
},
41+
});
42+
},
43+
},
44+
methods: {
45+
generateMeta(body) {
46+
const ts = Date.now();
47+
return {
48+
id: ts,
49+
summary: `New ${body.category} event`,
50+
ts,
51+
};
52+
},
53+
},
54+
async run(event) {
55+
const { body } = event;
56+
if (!body) {
57+
return;
58+
}
59+
this.http.respond({
60+
status: 200,
61+
});
62+
const meta = this.generateMeta(body);
63+
this.$emit(body, meta);
64+
},
65+
};

pnpm-lock.yaml

Lines changed: 4 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)