-
Notifications
You must be signed in to change notification settings - Fork 5.5k
[Components] chatlayer #11573 #18261
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
WalkthroughAdds three new ChatLayer action modules (get conversations, list messages, get session data), introduces an HTTP client and propDefinitions in the ChatLayer app for bots/sessions/version, adds a constants module for bot versions, and updates package metadata with a version bump and a new dependency. Changes
Sequence Diagram(s)sequenceDiagram
autonumber
actor User
participant Action as Action Module
participant App as chatlayer.app
participant API as ChatLayer API
User->>Action: Trigger action (props: app, botId, version[, sessionId])
Action->>App: Call method (getConversations | listMessages | getSessionData)
App->>API: HTTP request (GET) with Authorization and params
API-->>App: Response (data)
App-->>Action: Return response
Action-->>User: Export $summary and data
note over Action,App: Errors propagate without explicit handling
sequenceDiagram
autonumber
participant UI as UI (Props Options)
participant App as chatlayer.app
participant API as ChatLayer API
UI->>App: options(botId)
App->>API: GET /v1/bots
API-->>App: bots[]
App-->>UI: { value: bot.id, label: bot.name }
UI->>App: options(sessionId) with { botId, version }
App->>API: GET /v1/bots/:botId/conversations?version=...
API-->>App: conversations[]
App-->>UI: { value: user.sessionId }
note over UI: version options from constants.BOT_VERSIONS
Estimated code review effort🎯 4 (Complex) | ⏱️ ~45 minutes Poem
✨ Finishing Touches
🧪 Generate unit tests
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. 🪧 TipsChatThere are 3 ways to chat with CodeRabbit:
SupportNeed help? Create a ticket on our support page for assistance with any issues or questions. CodeRabbit Commands (Invoked using PR/Issue comments)Type Other keywords and placeholders
CodeRabbit Configuration File (
|
|
The latest updates on your projects. Learn more about Vercel for GitHub. 2 Skipped Deployments
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 2
🧹 Nitpick comments (12)
components/chatlayer/common/constants.mjs (1)
1-6: Optional: prevent accidental mutation of shared constants.
Freezing avoids accidental runtime edits.-export default { - BOT_VERSIONS: [ - "LIVE", - "DRAFT", - ], -}; +export default Object.freeze({ + BOT_VERSIONS: Object.freeze([ + "LIVE", + "DRAFT", + ]), +});components/chatlayer/package.json (1)
1-18: Optional: declare runtime Node version.
Pipedream runs on Node 18+. Declaring engines helps tooling."publishConfig": { "access": "public" }, + "engines": { + "node": ">=18" + }, "dependencies": { "@pipedream/platform": "^3.1.0" }components/chatlayer/actions/get-conversations/get-conversations.mjs (3)
5-6: Nit: consider “List Conversations” for consistency with “List Messages”.
Keeps action names parallel.
24-33: Harden summary to avoid crashes if response shape changes.
Guard against non-array data and still provide a useful summary.}); - $.export("$summary", "Successfully sent the request. Retrieved " + response.data.length + " results"); - return response; + const count = Array.isArray(response?.data) + ? response.data.length + : (Array.isArray(response?.data?.results) ? response.data.results.length : undefined); + $.export("$summary", `Successfully sent the request${typeof count === "number" ? `. Retrieved ${count} results` : ""}`); + return response.data ?? response;
9-23: Expose pagination controls (page / size) and forward them.
Prevents large responses and lets users control result size.props: { app, botId: { propDefinition: [ app, "botId", ], }, version: { propDefinition: [ app, "version", ], }, + page: { + type: "integer", + label: "Page", + description: "Page number to retrieve.", + optional: true, + }, + size: { + type: "integer", + label: "Page Size", + description: "Number of items per page.", + optional: true, + }, },And forward when present:
const response = await this.app.getConversations({ $, botId: this.botId, params: { - version: this.version, + version: this.version, + ...(this.page != null && { page: this.page }), + ...(this.size != null && { size: this.size }), }, });Please confirm the exact pagination param names per Chatlayer docs (e.g., page/size vs page/limit).
components/chatlayer/actions/get-session-data/get-session-data.mjs (1)
43-45: More informative summary and return data payload.
Small UX improvement and a lighter return shape.- $.export("$summary", "Successfully sent the request"); - return response; + $.export("$summary", `Successfully retrieved session ${this.sessionId}`); + return response.data ?? response;components/chatlayer/actions/list-messages/list-messages.mjs (2)
34-44: Harden summary; don’t assumedatais an array.
Same pattern as Get Conversations to avoid runtime errors.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; + const count = Array.isArray(response?.data) + ? response.data.length + : (Array.isArray(response?.data?.results) ? response.data.results.length : undefined); + $.export("$summary", `Successfully sent the request${typeof count === "number" ? `. Retrieved ${count} results` : ""}`); + return response.data ?? response;
9-32: Expose pagination controls (page / size) and forward them.
Align with Conversations action; helps with large sessions.props: { app, botId: { propDefinition: [ app, "botId", ], }, version: { propDefinition: [ app, "version", ], }, sessionId: { propDefinition: [ app, "sessionId", (c) => ({ botId: c.botId, version: c.version, }), ], }, + page: { + type: "integer", + label: "Page", + description: "Page number to retrieve.", + optional: true, + }, + size: { + type: "integer", + label: "Page Size", + description: "Number of items per page.", + optional: true, + }, },And forward:
params: { version: this.version, + ...(this.page != null && { page: this.page }), + ...(this.size != null && { size: this.size }), },Please confirm the pagination parameter names in the Chatlayer Messages endpoint.
components/chatlayer/chatlayer.app.mjs (4)
52-67: Safer URL joining and add a sensible default timeout.Prevent double-slash URL issues and set a default timeout to avoid hanging requests.
Apply this diff:
- return axios($, { - ...otherOpts, - url: this._baseUrl() + path, - headers: { - Authorization: `Bearer ${this.$auth.access_token}`, - ...headers, - }, - }); + const url = new URL(path, this._baseUrl()).toString(); + return axios($, { + ...otherOpts, + url, + timeout: otherOpts.timeout ?? 10000, + headers: { + Accept: "application/json", + Authorization: `Bearer ${this.$auth.access_token}`, + ...headers, + }, + });
69-76: URL-encode path params.Protect against special characters in
botId.Apply this diff:
- path: `/v1/bots/${botId}/conversations`, + path: `/v1/bots/${encodeURIComponent(botId)}/conversations`,
77-84: URL-encode path params for messages endpoint.Encode both
botIdandsessionId.Apply this diff:
- path: `/v1/bots/${botId}/conversations/${sessionId}/messages`, + path: `/v1/bots/${encodeURIComponent(botId)}/conversations/${encodeURIComponent(sessionId)}/messages`,
85-92: URL-encode path params for session-data endpoint.Encode both
botIdandsessionId.Apply this diff:
- path: `/v1/bots/${botId}/conversations/${sessionId}/session-data`, + path: `/v1/bots/${encodeURIComponent(botId)}/conversations/${encodeURIComponent(sessionId)}/session-data`,
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
💡 Knowledge Base configuration:
- MCP integration is disabled by default for public repositories
- Jira integration is disabled by default for public repositories
- Linear integration is disabled by default for public repositories
You can enable these sources in your CodeRabbit configuration.
⛔ Files ignored due to path filters (1)
pnpm-lock.yamlis excluded by!**/pnpm-lock.yaml
📒 Files selected for processing (6)
components/chatlayer/actions/get-conversations/get-conversations.mjs(1 hunks)components/chatlayer/actions/get-session-data/get-session-data.mjs(1 hunks)components/chatlayer/actions/list-messages/list-messages.mjs(1 hunks)components/chatlayer/chatlayer.app.mjs(1 hunks)components/chatlayer/common/constants.mjs(1 hunks)components/chatlayer/package.json(2 hunks)
🧰 Additional context used
🧠 Learnings (1)
📚 Learning: 2024-12-12T19:23:09.039Z
Learnt from: jcortes
PR: PipedreamHQ/pipedream#14935
File: components/sailpoint/package.json:15-18
Timestamp: 2024-12-12T19:23:09.039Z
Learning: When developing Pipedream components, do not add built-in Node.js modules like `fs` to `package.json` dependencies, as they are native modules provided by the Node.js runtime.
Applied to files:
components/chatlayer/package.json
🧬 Code graph analysis (4)
components/chatlayer/actions/get-conversations/get-conversations.mjs (3)
components/chatlayer/actions/get-session-data/get-session-data.mjs (1)
response(35-42)components/chatlayer/actions/list-messages/list-messages.mjs (1)
response(35-42)components/chatlayer/chatlayer.app.mjs (2)
response(13-13)response(29-34)
components/chatlayer/actions/list-messages/list-messages.mjs (3)
components/chatlayer/actions/get-conversations/get-conversations.mjs (1)
response(25-31)components/chatlayer/actions/get-session-data/get-session-data.mjs (1)
response(35-42)components/chatlayer/chatlayer.app.mjs (2)
response(13-13)response(29-34)
components/chatlayer/chatlayer.app.mjs (3)
components/chatlayer/actions/get-conversations/get-conversations.mjs (1)
response(25-31)components/chatlayer/actions/get-session-data/get-session-data.mjs (1)
response(35-42)components/chatlayer/actions/list-messages/list-messages.mjs (1)
response(35-42)
components/chatlayer/actions/get-session-data/get-session-data.mjs (3)
components/chatlayer/actions/get-conversations/get-conversations.mjs (1)
response(25-31)components/chatlayer/actions/list-messages/list-messages.mjs (1)
response(35-42)components/chatlayer/chatlayer.app.mjs (2)
response(13-13)response(29-34)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (3)
- GitHub Check: Lint Code Base
- GitHub Check: Publish TypeScript components
- GitHub Check: Verify TypeScript components
🔇 Additional comments (9)
components/chatlayer/common/constants.mjs (2)
1-6: LGTM: Centralized BOT_VERSIONS constant looks good.
2-5: Valid values and query parameter confirmed BOT_VERSIONS correctly includes "LIVE" and "DRAFT", and the API usesversionas the query parameter.components/chatlayer/package.json (2)
3-3: Semver bump makes sense.
New actions justify 0.1.0.
15-17: No additionalaxiosdependency needed
The importimport { axios } from "@pipedream/platform";incomponents/chatlayer/chatlayer.app.mjsuses Pipedream’s HTTP helper, so you don’t need to addaxiostodependencies.components/chatlayer/actions/get-session-data/get-session-data.mjs (1)
23-32: Nice: dependent sessionId options on botId + version.
This keeps the UX tight and avoids invalid sessions.components/chatlayer/chatlayer.app.mjs (4)
1-2: LGTM on importsUsing the platform axios and local constants is appropriate.
41-46: Version prop looks good.Using shared constants for options is clean and maintainable.
93-97: Bots endpoint wrapper looks good.Straightforward pass-through to the HTTP client.
12-19: No axios response shape inconsistencies detected. The@pipedream/platformaxios wrapper returns only the HTTP response body (thedataproperty) on success, and each app method and action correctly consume that shape based on their respective Chatlayer API endpoints (pipedream.com).
GTFalcao
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please check the CodeRabbit comments, and ensure all requests use the same pattern (extracting .data from the response), or just confirm that the API returns different request formats
|
Hey @GTFalcao, I checked and is everything following the docs, thanks! |
GTFalcao
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM!
WHY
Summary by CodeRabbit
New Features
Chores