Skip to content

Commit a51cce2

Browse files
authored
Merging pull request #18261
1 parent 22a43c6 commit a51cce2

File tree

7 files changed

+235
-6
lines changed

7 files changed

+235
-6
lines changed
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
import app from "../../chatlayer.app.mjs";
2+
3+
export default {
4+
key: "chatlayer-get-conversations",
5+
name: "Get Conversations",
6+
description: "Lists conversations with the specified bot. [See the documentation](https://api.chatlayer.ai/v1/docs#operation/getAllPaginatedConversationsByBotId)",
7+
version: "0.0.1",
8+
type: "action",
9+
props: {
10+
app,
11+
botId: {
12+
propDefinition: [
13+
app,
14+
"botId",
15+
],
16+
},
17+
version: {
18+
propDefinition: [
19+
app,
20+
"version",
21+
],
22+
},
23+
},
24+
async run({ $ }) {
25+
const response = await this.app.getConversations({
26+
$,
27+
botId: this.botId,
28+
params: {
29+
version: this.version,
30+
},
31+
});
32+
$.export("$summary", "Successfully sent the request. Retrieved " + response.data.length + " results");
33+
return response;
34+
},
35+
};
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
import app from "../../chatlayer.app.mjs";
2+
3+
export default {
4+
key: "chatlayer-get-session-data",
5+
name: "Get Session Data",
6+
description: "Gets data for the specified session. [See the documentation](https://api.chatlayer.ai/v1/docs#operation/getConversationSessionData)",
7+
version: "0.0.1",
8+
type: "action",
9+
props: {
10+
app,
11+
botId: {
12+
propDefinition: [
13+
app,
14+
"botId",
15+
],
16+
},
17+
version: {
18+
propDefinition: [
19+
app,
20+
"version",
21+
],
22+
},
23+
sessionId: {
24+
propDefinition: [
25+
app,
26+
"sessionId",
27+
(c) => ({
28+
botId: c.botId,
29+
version: c.version,
30+
}),
31+
],
32+
},
33+
},
34+
async run({ $ }) {
35+
const response = await this.app.getSessionData({
36+
$,
37+
botId: this.botId,
38+
sessionId: this.sessionId,
39+
params: {
40+
version: this.version,
41+
},
42+
});
43+
$.export("$summary", "Successfully sent the request");
44+
return response;
45+
},
46+
};
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
import app from "../../chatlayer.app.mjs";
2+
3+
export default {
4+
key: "chatlayer-list-messages",
5+
name: "List Messages",
6+
description: "Lists the messages of the specified session. [See the documentation](https://api.chatlayer.ai/v1/docs#operation/getAllMessagesInConversation)",
7+
version: "0.0.1",
8+
type: "action",
9+
props: {
10+
app,
11+
botId: {
12+
propDefinition: [
13+
app,
14+
"botId",
15+
],
16+
},
17+
version: {
18+
propDefinition: [
19+
app,
20+
"version",
21+
],
22+
},
23+
sessionId: {
24+
propDefinition: [
25+
app,
26+
"sessionId",
27+
(c) => ({
28+
botId: c.botId,
29+
version: c.version,
30+
}),
31+
],
32+
},
33+
},
34+
async run({ $ }) {
35+
const response = await this.app.listMessages({
36+
$,
37+
botId: this.botId,
38+
sessionId: this.sessionId,
39+
params: {
40+
version: this.version,
41+
},
42+
});
43+
$.export("$summary", "Successfully sent the request. Retrieved " + response.data.length + " results");
44+
return response;
45+
},
46+
};
Lines changed: 93 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,100 @@
1+
import { axios } from "@pipedream/platform";
2+
import constants from "./common/constants.mjs";
3+
14
export default {
25
type: "app",
36
app: "chatlayer",
4-
propDefinitions: {},
7+
propDefinitions: {
8+
botId: {
9+
type: "string",
10+
label: "Bot ID",
11+
description: "Unique identifier of the bot",
12+
async options() {
13+
const response = await this.getBots();
14+
return response.map(({
15+
id, name,
16+
}) => ({
17+
value: id,
18+
label: name,
19+
}));
20+
},
21+
},
22+
sessionId: {
23+
type: "string",
24+
label: "Session ID",
25+
description: "Unique identifier of the user session",
26+
async options({
27+
botId, version,
28+
}) {
29+
const response = await this.getConversations({
30+
botId,
31+
params: {
32+
version,
33+
},
34+
});
35+
const sessions = response.data;
36+
return sessions.map(({ user }) => ({
37+
value: user.sessionId,
38+
}));
39+
},
40+
},
41+
version: {
42+
type: "string",
43+
label: "Version",
44+
description: "Bot version to use",
45+
options: constants.BOT_VERSIONS,
46+
},
47+
},
548
methods: {
6-
// this.$auth contains connected account data
7-
authKeys() {
8-
console.log(Object.keys(this.$auth));
49+
_baseUrl() {
50+
return `${this.$auth.url}`;
51+
},
52+
async _makeRequest(opts = {}) {
53+
const {
54+
$ = this,
55+
path,
56+
headers,
57+
...otherOpts
58+
} = opts;
59+
return axios($, {
60+
...otherOpts,
61+
url: this._baseUrl() + path,
62+
headers: {
63+
Authorization: `Bearer ${this.$auth.access_token}`,
64+
...headers,
65+
},
66+
});
67+
},
68+
69+
async getConversations({
70+
botId, ...args
71+
}) {
72+
return this._makeRequest({
73+
path: `/v1/bots/${botId}/conversations`,
74+
...args,
75+
});
76+
},
77+
async listMessages({
78+
botId, sessionId, ...args
79+
}) {
80+
return this._makeRequest({
81+
path: `/v1/bots/${botId}/conversations/${sessionId}/messages`,
82+
...args,
83+
});
84+
},
85+
async getSessionData({
86+
botId, sessionId, ...args
87+
}) {
88+
return this._makeRequest({
89+
path: `/v1/bots/${botId}/conversations/${sessionId}/session-data`,
90+
...args,
91+
});
92+
},
93+
async getBots(args = {}) {
94+
return this._makeRequest({
95+
path: "/v1/bots",
96+
...args,
97+
});
998
},
1099
},
11100
};
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
export default {
2+
BOT_VERSIONS: [
3+
"LIVE",
4+
"DRAFT",
5+
],
6+
};

components/chatlayer/package.json

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@pipedream/chatlayer",
3-
"version": "0.0.1",
3+
"version": "0.1.0",
44
"description": "Pipedream Chatlayer Components",
55
"main": "chatlayer.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.1.0"
1417
}
1518
}

pnpm-lock.yaml

Lines changed: 5 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)