Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
import app from "../../chatlayer.app.mjs";

export default {
key: "chatlayer-get-conversations",
name: "Get Conversations",
description: "Lists conversations with the specified bot. [See the documentation](https://api.chatlayer.ai/v1/docs#operation/getAllPaginatedConversationsByBotId)",
version: "0.0.1",
type: "action",
props: {
app,
botId: {
propDefinition: [
app,
"botId",
],
},
version: {
propDefinition: [
app,
"version",
],
},
},
async run({ $ }) {
const response = await this.app.getConversations({
$,
botId: this.botId,
params: {
version: this.version,
},
});
$.export("$summary", "Successfully sent the request. Retrieved " + response.data.length + " results");
return response;
},
};
46 changes: 46 additions & 0 deletions components/chatlayer/actions/get-session-data/get-session-data.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
import app from "../../chatlayer.app.mjs";

export default {
key: "chatlayer-get-session-data",
name: "Get Session Data",
description: "Gets data for the specified session. [See the documentation](https://api.chatlayer.ai/v1/docs#operation/getConversationSessionData)",
version: "0.0.1",
type: "action",
props: {
app,
botId: {
propDefinition: [
app,
"botId",
],
},
version: {
propDefinition: [
app,
"version",
],
},
sessionId: {
propDefinition: [
app,
"sessionId",
(c) => ({
botId: c.botId,
version: c.version,
}),
],
},
},
async run({ $ }) {
const response = await this.app.getSessionData({
$,
botId: this.botId,
sessionId: this.sessionId,
params: {
version: this.version,
},
});
$.export("$summary", "Successfully sent the request");
return response;
},
};
46 changes: 46 additions & 0 deletions components/chatlayer/actions/list-messages/list-messages.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
import app from "../../chatlayer.app.mjs";

export default {
key: "chatlayer-list-messages",
name: "List Messages",
description: "Lists the messages of the specified session. [See the documentation](https://api.chatlayer.ai/v1/docs#operation/getAllMessagesInConversation)",
version: "0.0.1",
type: "action",
props: {
app,
botId: {
propDefinition: [
app,
"botId",
],
},
version: {
propDefinition: [
app,
"version",
],
},
sessionId: {
propDefinition: [
app,
"sessionId",
(c) => ({
botId: c.botId,
version: c.version,
}),
],
},
},
async run({ $ }) {
const response = await this.app.listMessages({
$,
botId: this.botId,
sessionId: this.sessionId,
params: {
version: this.version,
},
});
$.export("$summary", "Successfully sent the request. Retrieved " + response.data.length + " results");
return response;
},
};
97 changes: 93 additions & 4 deletions components/chatlayer/chatlayer.app.mjs
Original file line number Diff line number Diff line change
@@ -1,11 +1,100 @@
import { axios } from "@pipedream/platform";
import constants from "./common/constants.mjs";

export default {
type: "app",
app: "chatlayer",
propDefinitions: {},
propDefinitions: {
botId: {
type: "string",
label: "Bot ID",
description: "Unique identifier of the bot",
async options() {
const response = await this.getBots();
return response.map(({
id, name,
}) => ({
value: id,
label: name,
}));
},
},
sessionId: {
type: "string",
label: "Session ID",
description: "Unique identifier of the user session",
async options({
botId, version,
}) {
const response = await this.getConversations({
botId,
params: {
version,
},
});
const sessions = response.data;
return sessions.map(({ user }) => ({
value: user.sessionId,
}));
},
},
version: {
type: "string",
label: "Version",
description: "Bot version to use",
options: constants.BOT_VERSIONS,
},
},
methods: {
// this.$auth contains connected account data
authKeys() {
console.log(Object.keys(this.$auth));
_baseUrl() {
return `${this.$auth.url}`;
},
async _makeRequest(opts = {}) {
const {
$ = this,
path,
headers,
...otherOpts
} = opts;
return axios($, {
...otherOpts,
url: this._baseUrl() + path,
headers: {
Authorization: `Bearer ${this.$auth.access_token}`,
...headers,
},
});
},

async getConversations({
botId, ...args
}) {
return this._makeRequest({
path: `/v1/bots/${botId}/conversations`,
...args,
});
},
async listMessages({
botId, sessionId, ...args
}) {
return this._makeRequest({
path: `/v1/bots/${botId}/conversations/${sessionId}/messages`,
...args,
});
},
async getSessionData({
botId, sessionId, ...args
}) {
return this._makeRequest({
path: `/v1/bots/${botId}/conversations/${sessionId}/session-data`,
...args,
});
},
async getBots(args = {}) {
return this._makeRequest({
path: "/v1/bots",
...args,
});
},
},
};
6 changes: 6 additions & 0 deletions components/chatlayer/common/constants.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
export default {
BOT_VERSIONS: [
"LIVE",
"DRAFT",
],
};
5 changes: 4 additions & 1 deletion components/chatlayer/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@pipedream/chatlayer",
"version": "0.0.1",
"version": "0.1.0",
"description": "Pipedream Chatlayer Components",
"main": "chatlayer.app.mjs",
"keywords": [
Expand All @@ -11,5 +11,8 @@
"author": "Pipedream <[email protected]> (https://pipedream.com/)",
"publishConfig": {
"access": "public"
},
"dependencies": {
"@pipedream/platform": "^3.1.0"
}
}
6 changes: 5 additions & 1 deletion pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading