Skip to content

Commit e0d423e

Browse files
New Components - chatfly (#11931)
* chatfly init * [Components] chatfly #11730 Actions - SendMessage * pnpm update * Update components/chatfly/chatfly.app.mjs * fix description --------- Co-authored-by: Leo Vu <18277920+vunguyenhung@users.noreply.github.com>
1 parent 85482fc commit e0d423e

File tree

5 files changed

+139
-8
lines changed

5 files changed

+139
-8
lines changed
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
import chatfly from "../../chatfly.app.mjs";
2+
3+
export default {
4+
key: "chatfly-send-message",
5+
name: "Send Message",
6+
description: "Dispatches a text message to a specified group or individual in Chatfly.",
7+
version: "0.0.1",
8+
type: "action",
9+
props: {
10+
chatfly,
11+
botId: {
12+
propDefinition: [
13+
chatfly,
14+
"botId",
15+
],
16+
},
17+
sessionId: {
18+
propDefinition: [
19+
chatfly,
20+
"sessionId",
21+
({ botId }) => ({
22+
botId,
23+
}),
24+
],
25+
},
26+
message: {
27+
propDefinition: [
28+
chatfly,
29+
"message",
30+
],
31+
},
32+
},
33+
async run({ $ }) {
34+
const response = await this.chatfly.dispatchMessage({
35+
$,
36+
data: {
37+
bot_id: this.botId,
38+
message: this.message,
39+
session_id: this.sessionId,
40+
},
41+
});
42+
$.export("$summary", "Message dispatched successfully");
43+
return response;
44+
},
45+
};

components/chatfly/chatfly.app.mjs

Lines changed: 80 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,86 @@
1+
import { axios } from "@pipedream/platform";
2+
import { prepareSessionLabel } from "./common/utils.mjs";
3+
14
export default {
25
type: "app",
36
app: "chatfly",
4-
propDefinitions: {},
7+
propDefinitions: {
8+
botId: {
9+
type: "string",
10+
label: "Bot ID",
11+
description: "The ID of the bot to send the message to.",
12+
async options() {
13+
const data = await this.listBots();
14+
15+
return data.map(({
16+
id: value, bot_name: label,
17+
}) => ({
18+
label,
19+
value,
20+
}));
21+
},
22+
},
23+
message: {
24+
type: "string",
25+
label: "Message",
26+
description: "The message to send.",
27+
},
28+
sessionId: {
29+
type: "string",
30+
label: "Session ID",
31+
description: "The session ID for the message. To initiate a new session, use a unique string in a Custom Expression, for example: `8g12h`",
32+
async options({ botId }) {
33+
const data = await this.listSessions({
34+
params: {
35+
bot_id: botId,
36+
},
37+
});
38+
39+
return data.map(({
40+
session_id: value, chat_history_response,
41+
}) => ({
42+
label: prepareSessionLabel(chat_history_response),
43+
value,
44+
}));
45+
},
46+
},
47+
},
548
methods: {
6-
// this.$auth contains connected account data
7-
authKeys() {
8-
console.log(Object.keys(this.$auth));
49+
_baseUrl() {
50+
return "https://backend.chatfly.co/api";
51+
},
52+
_headers() {
53+
return {
54+
"CHATFLY-API-KEY": `${this.$auth.api_key}`,
55+
};
56+
},
57+
_makeRequest({
58+
$ = this, path = "/", ...opts
59+
}) {
60+
return axios($, {
61+
url: this._baseUrl() + path,
62+
headers: this._headers(),
63+
...opts,
64+
});
65+
},
66+
dispatchMessage(opts = {}) {
67+
return this._makeRequest({
68+
method: "POST",
69+
path: "/chat/get-streaming-response",
70+
...opts,
71+
});
72+
},
73+
listBots(opts = {}) {
74+
return this._makeRequest({
75+
path: "/bot",
76+
...opts,
77+
});
78+
},
79+
listSessions(opts = {}) {
80+
return this._makeRequest({
81+
path: "/chat/history",
82+
...opts,
83+
});
984
},
1085
},
11-
};
86+
};
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
export const prepareSessionLabel = (messages) => {
2+
return `${messages[messages.length - 1].content.substring(0, 60)} ${(messages[messages.length - 1].content.length > 60)
3+
? "..."
4+
: ""}`;
5+
};

components/chatfly/package.json

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@pipedream/chatfly",
3-
"version": "0.0.1",
3+
"version": "0.1.0",
44
"description": "Pipedream ChatFly Components",
55
"main": "chatfly.app.mjs",
66
"keywords": [
@@ -11,5 +11,8 @@
1111
"author": "Pipedream <support@pipedream.com> (https://pipedream.com/)",
1212
"publishConfig": {
1313
"access": "public"
14+
},
15+
"dependencies": {
16+
"@pipedream/platform": "^1.6.5"
1417
}
15-
}
18+
}

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)