Skip to content

Commit 4d34511

Browse files
committed
new components
1 parent e1e3cbb commit 4d34511

File tree

5 files changed

+346
-6
lines changed

5 files changed

+346
-6
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: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -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: 146 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,146 @@
1+
export default [
2+
{
3+
value: "open_channel:create",
4+
label: "open channel created",
5+
},
6+
{
7+
value: "open_channel:remove",
8+
label: "open channel removed",
9+
},
10+
{
11+
value: "open_channel:enter",
12+
label: "user enters open channel",
13+
},
14+
{
15+
value: "open_channel:exit",
16+
label: "user exits open channel",
17+
},
18+
{
19+
value: "open_channel:message_send",
20+
label: "message sent within open channel",
21+
},
22+
{
23+
value: "open_channel:message_update",
24+
label: "message updated in open channel",
25+
},
26+
{
27+
value: "open_channel:message_delete",
28+
label: "message deleted from open channel",
29+
},
30+
{
31+
value: "group_channel:create",
32+
label: "group channel created",
33+
},
34+
{
35+
value: "group_channel:changed",
36+
label: "group information changed",
37+
},
38+
{
39+
value: "group_channel:remove",
40+
label: "group channel removed",
41+
},
42+
{
43+
value: "group_channel:invite",
44+
label: "user invites another user to group channel",
45+
},
46+
{
47+
value: "group_channel:decline_invite",
48+
label: "user declines invitation to group channel",
49+
},
50+
{
51+
value: "group_channel:join",
52+
label: "user joins group channel",
53+
},
54+
{
55+
value: "group_channel:leave",
56+
label: "user leaves group channel",
57+
},
58+
{
59+
value: "group_channel:message_send",
60+
label: "message sent within group channel",
61+
},
62+
{
63+
value: "group_channel:message_read",
64+
label: "user has no more unread messages in group channel",
65+
},
66+
{
67+
value: "group_channel:message_update",
68+
label: "message updated in group channel",
69+
},
70+
{
71+
value: "group_channel:message_delete",
72+
label: "message deleted from group channel",
73+
},
74+
{
75+
value: "group_channel:freeze_unfreeze",
76+
label: "group channel frozen or unfrozen",
77+
},
78+
{
79+
value: "group_channel:reaction_add",
80+
label: "user adds reactions to group channel message",
81+
},
82+
{
83+
value: "group_channel:reaction_delete",
84+
label: "user deletes reactions from group channel message",
85+
},
86+
{
87+
value: "user:block",
88+
label: "user blocks another user",
89+
},
90+
{
91+
value: "user:unblock",
92+
label: "user unblocks another user",
93+
},
94+
{
95+
value: "operators:register_by_operator",
96+
label: "operator registered by another operator's client app",
97+
},
98+
{
99+
value: "operators:unregister_by_operator",
100+
label: "operator registration canceled by another operator's client app",
101+
},
102+
{
103+
value: "message:report",
104+
label: "message reported by user",
105+
},
106+
{
107+
value: "user:report",
108+
label: "user reported by user",
109+
},
110+
{
111+
value: "open_channel:report",
112+
label: "open channel reported by user",
113+
},
114+
{
115+
value: "group_channel:report",
116+
label: "group channel reported by user",
117+
},
118+
{
119+
value: "alert:user_message_rate_limit_exceeded",
120+
label: "user exceeds allowed number of messages",
121+
},
122+
{
123+
value: "profanity_filter:replace",
124+
label: "explicit words replaced with asterisks (*)",
125+
},
126+
{
127+
value: "profanity_filter:block",
128+
label: "message with explicit words blocked",
129+
},
130+
{
131+
value: "profanity_filter:moderate",
132+
label: "user muted, kicked, or banned",
133+
},
134+
{
135+
value: "image_moderation:block",
136+
label: "message with explicit image blocked",
137+
},
138+
{
139+
value: "announcement:create_channels",
140+
label: "channel created for sending announcement to target users",
141+
},
142+
{
143+
value: "announcement:send_messages",
144+
label: "announcement message sent to target channels and users",
145+
},
146+
];
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+
};

0 commit comments

Comments
 (0)