-
Notifications
You must be signed in to change notification settings - Fork 14
feat: Chatwoot Integration #229
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
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.
Pull request overview
This PR introduces a new Chatwoot integration for Botpress, enabling HITL (Human-in-the-Loop) support and a messaging channel for bot conversations through Chatwoot's platform.
Key Changes:
- Implements HITL functionality allowing human agents to take over bot conversations
- Adds a messaging channel for direct bot-to-user communication via Chatwoot
- Provides webhook handling for bidirectional message synchronization
Reviewed changes
Copilot reviewed 52 out of 54 changed files in this pull request and generated 6 comments.
Show a summary per file
| File | Description |
|---|---|
| integration.definition.ts | Defines integration schema with channels, actions, events, and configuration for Chatwoot API |
| src/index.ts | Main entry point exporting the integration with setup handlers and channels |
| src/setup/register.ts | Validates Chatwoot credentials and stores account configuration during registration |
| src/setup/handler.ts | Processes webhook events from Chatwoot for messages and conversation status changes |
| src/actions/hitl.ts | Implements HITL actions: createUser, startHitl, and stopHitl |
| src/client.ts | Provides API client functions for interacting with Chatwoot's REST API |
| src/channels.ts | Handles message sending for both HITL and messaging channels |
| package.json | Declares dependencies including Botpress SDK, axios, and form-data |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
This reverts commit e001969.
…d update logging messages
…te chatwoot integration build process
…ns, update chatwoot integration build process" This reverts commit 542b6ae.
…ionally run bp add for local bpDependencies
…n local bpDependencies and SDK version
…press/cli versions in package.json for chatwoot and hitl integrations
…ns with userId support
SimonNRisk
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.
question: should we add this new integration to the pnpm workspace?
ptrckbp
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.
I have a few questions. There are a lot of fallback behaviors that seem like they could sometimes cause problems.
| }, | ||
| }).extend(hitl, (self) => ({ | ||
| entities: { | ||
| hitlSession: self.entities.ticket, |
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.
question: what does this do exactly?
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.
it implements the standard hitl interface allowing it be compatible with the botpress hitl features
…d simplify account retrieval logic
| } | ||
|
|
||
| try { | ||
| const accountId = await getAccountId(client, ctx) |
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.
question: Why not just ctx.configuration.accountId
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.
it was part of adresing one of the previous comments, but reverted to using ctx.ocnfig.accountid
| logger.forBot().info(`Created new conversation: ${chatwootConvId}`) | ||
| } | ||
|
|
||
| if (description) { |
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.
issue: description will never be falsy, this check is redundant
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.
done, removed check
integrations/chatwoot/src/client.ts
Outdated
| const response = await axios.post( | ||
| `${BASE_URL}/accounts/${accountId}/contacts`, | ||
| { email: email, name: email, inbox_id: inboxId }, | ||
| { headers: { api_access_token: apiAccessToken } } |
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.
nit: Next time you can create a function that wraps axios call and includes auth token and base url, so you don't have to pass them in every time
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.
i made a chatwootClient that returns an AxiosInstance with the baseURL and the access token
integrations/chatwoot/src/client.ts
Outdated
| const response = await axios.get(`${BASE_URL}/profile`, { | ||
| headers: { api_access_token: apiAccessToken }, | ||
| }) | ||
| if (response.status !== 200) { |
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.
issue: This check will never run as axios throws an exception on non 200. You can just omit it or handle it with try/catch
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.
handled all with try/catch
Chatwoot integration for HITL and messaging channel