-
Notifications
You must be signed in to change notification settings - Fork 5.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
New Components - sendbird_ai_chabot (#13898)
* new components * pnpm-lock.yaml * package.json version * update events
- Loading branch information
1 parent
7567870
commit 3dc0120
Showing
6 changed files
with
219 additions
and
8 deletions.
There are no files selected for viewing
43 changes: 43 additions & 0 deletions
43
components/sendbird_ai_chabot/actions/send-bot-message/send-bot-message.mjs
This file contains 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 sendbird from "../../sendbird_ai_chabot.app.mjs"; | ||
|
||
export default { | ||
key: "sendbird_ai_chabot-send-bot-message", | ||
name: "Send Bot Message", | ||
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)", | ||
version: "0.0.1", | ||
type: "action", | ||
props: { | ||
sendbird, | ||
botId: { | ||
propDefinition: [ | ||
sendbird, | ||
"botId", | ||
], | ||
}, | ||
channelUrl: { | ||
propDefinition: [ | ||
sendbird, | ||
"channelUrl", | ||
], | ||
}, | ||
message: { | ||
type: "string", | ||
label: "Message", | ||
description: "Specifies the content of the message sent by the bot", | ||
}, | ||
}, | ||
async run({ $ }) { | ||
const response = await this.sendbird.sendBotMessage({ | ||
$, | ||
botId: this.botId, | ||
data: { | ||
channel_url: this.channelUrl, | ||
message: this.message, | ||
}, | ||
}); | ||
if (response?.message?.message_id) { | ||
$.export("$summary", `Successfully sent message with ID: ${response.message.message_id}`); | ||
} | ||
return response; | ||
}, | ||
}; |
This file contains 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,6 +1,6 @@ | ||
{ | ||
"name": "@pipedream/sendbird_ai_chabot", | ||
"version": "0.0.1", | ||
"version": "0.1.0", | ||
"description": "Pipedream Sendbird AI chabot Components", | ||
"main": "sendbird_ai_chabot.app.mjs", | ||
"keywords": [ | ||
|
@@ -11,5 +11,8 @@ | |
"author": "Pipedream <[email protected]> (https://pipedream.com/)", | ||
"publishConfig": { | ||
"access": "public" | ||
}, | ||
"dependencies": { | ||
"@pipedream/platform": "^3.0.1" | ||
} | ||
} | ||
} |
This file contains 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,94 @@ | ||
import { axios } from "@pipedream/platform"; | ||
const DEFAULT_LIMIT = 20; | ||
|
||
export default { | ||
type: "app", | ||
app: "sendbird_ai_chabot", | ||
propDefinitions: {}, | ||
propDefinitions: { | ||
botId: { | ||
type: "string", | ||
label: "Bot ID", | ||
description: "The identifier of a bot", | ||
async options({ page }) { | ||
const { bots } = await this.listBots({ | ||
params: { | ||
limit: DEFAULT_LIMIT, | ||
offset: page * DEFAULT_LIMIT, | ||
}, | ||
}); | ||
return bots?.map(({ bot }) => ({ | ||
label: bot.bot_nickname, | ||
value: bot.bot_userid, | ||
})) || []; | ||
}, | ||
}, | ||
channelUrl: { | ||
type: "string", | ||
label: "Channel URL", | ||
description: "Specifies the URL of the channel", | ||
async options({ page }) { | ||
const { channels } = await this.listGroupChannels({ | ||
params: { | ||
limit: DEFAULT_LIMIT, | ||
offset: page * DEFAULT_LIMIT, | ||
}, | ||
}); | ||
return channels?.map(({ | ||
name: label, channel_url: value, | ||
}) => ({ | ||
label, | ||
value, | ||
})) || []; | ||
}, | ||
}, | ||
}, | ||
methods: { | ||
// this.$auth contains connected account data | ||
authKeys() { | ||
console.log(Object.keys(this.$auth)); | ||
_baseUrl() { | ||
return `https://api-${this.$auth.application_id}.sendbird.com/v3`; | ||
}, | ||
_headers() { | ||
return { | ||
"Api-Token": `${this.$auth.api_token}`, | ||
}; | ||
}, | ||
_makeRequest({ | ||
$ = this, | ||
path, | ||
...args | ||
}) { | ||
return axios($, { | ||
url: `${this._baseUrl()}${path}`, | ||
headers: this._headers(), | ||
...args, | ||
}); | ||
}, | ||
updateWebhook(opts = {}) { | ||
return this._makeRequest({ | ||
method: "PUT", | ||
path: "/applications/settings/webhook", | ||
...opts, | ||
}); | ||
}, | ||
listBots(opts = {}) { | ||
return this._makeRequest({ | ||
path: "/bots", | ||
...opts, | ||
}); | ||
}, | ||
listGroupChannels(opts = {}) { | ||
return this._makeRequest({ | ||
path: "/group_channels", | ||
...opts, | ||
}); | ||
}, | ||
sendBotMessage({ | ||
botId, ...opts | ||
}) { | ||
return this._makeRequest({ | ||
method: "POST", | ||
path: `/bots/${botId}/send`, | ||
...opts, | ||
}); | ||
}, | ||
}, | ||
}; | ||
}; |
This file contains 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 @@ | ||
export default [ | ||
{ | ||
value: "form:submit", | ||
label: "form submitted", | ||
}, | ||
{ | ||
value: "group_channel:bot_message_send", | ||
label: "bot message sent within group channel", | ||
}, | ||
{ | ||
value: "group_channel:message_send", | ||
label: "message sent within group channel", | ||
}, | ||
]; |
65 changes: 65 additions & 0 deletions
65
components/sendbird_ai_chabot/sources/new-event-received/new-event-received.mjs
This file contains 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,65 @@ | ||
import sendbird from "../../sendbird_ai_chabot.app.mjs"; | ||
import events from "../common/events.mjs"; | ||
|
||
export default { | ||
key: "sendbird_ai_chabot-new-event-received", | ||
name: "New Event Received (Instant)", | ||
description: "Emit new event when a new webhook event is received.", | ||
version: "0.0.1", | ||
type: "source", | ||
dedupe: "unique", | ||
props: { | ||
sendbird, | ||
http: { | ||
type: "$.interface.http", | ||
customResponse: true, | ||
}, | ||
events: { | ||
type: "string[]", | ||
label: "Events", | ||
description: "The events to subscribe to", | ||
options: events, | ||
}, | ||
}, | ||
hooks: { | ||
async activate() { | ||
await this.sendbird.updateWebhook({ | ||
data: { | ||
enabled: true, | ||
url: this.http.endpoint, | ||
enabled_events: this.events, | ||
}, | ||
}); | ||
}, | ||
async deactivate() { | ||
await this.sendbird.updateWebhook({ | ||
data: { | ||
enabled: false, | ||
url: this.http.endpoint, | ||
enabled_events: [], | ||
}, | ||
}); | ||
}, | ||
}, | ||
methods: { | ||
generateMeta(body) { | ||
const ts = Date.now(); | ||
return { | ||
id: ts, | ||
summary: `New ${body.category} event`, | ||
ts, | ||
}; | ||
}, | ||
}, | ||
async run(event) { | ||
const { body } = event; | ||
if (!body) { | ||
return; | ||
} | ||
this.http.respond({ | ||
status: 200, | ||
}); | ||
const meta = this.generateMeta(body); | ||
this.$emit(body, meta); | ||
}, | ||
}; |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.