Skip to content

Conversation

@josiasmaceda
Copy link

@josiasmaceda josiasmaceda commented Sep 9, 2025

Does not trigger webhook for Typebot status change events (TYPEBOT_CHANGE_STATUS)

  • Issue found from the commit:

refactor(chatbot): unify keywordFinish type and enhance session handling
f9567fb

Related to issues:
Status de alteração do Typebot
#1382

Update Typebot Status (http request) session closed or deleted
#1390

Summary by Sourcery

Integrate TYPEBOT_CHANGE_STATUS webhook events into the chatbot flow by emitting session status changes (opened, closed, deleted, paused) from both the Typebot service and the base controller.

New Features:

  • Emit TYPEBOT_CHANGE_STATUS webhook from TypebotService on session open, close, delete, and finish actions
  • Forward TYPEBOT_CHANGE_STATUS webhook from BaseChatbotController for Typebot when handling delete and paused statuses

@sourcery-ai
Copy link
Contributor

sourcery-ai bot commented Sep 9, 2025

Reviewer's Guide

This PR hooks into Typebot session lifecycle events to emit TYPEBOT_CHANGE_STATUS webhooks by importing the new Events enum, constructing a standardized payload, and invoking sendDataWebhook in both the service and controller layers.

Sequence diagram for Typebot status change webhook emission

sequenceDiagram
participant TypebotService
participant WAMonitoringService
participant waInstance
participant Webhook

TypebotService->>WAMonitoringService: On session open/close/delete
WAMonitoringService->>waInstance: sendDataWebhook(TYPEBOT_CHANGE_STATUS, typebotData)
waInstance->>Webhook: Emit webhook with status change
Loading

Class diagram for updated TypebotService and BaseChatbotController

classDiagram
class TypebotService {
  -openaiService: OpenaiService
  +constructor(waMonitor, configService, prismaRepository, openaiService)
  +sendDataWebhook(Events.TYPEBOT_CHANGE_STATUS, typebotData)
}
class BaseChatbotController {
  -integrationName: string
  +sendDataWebhook(Events.TYPEBOT_CHANGE_STATUS, typebotData)
}
TypebotService --|> BaseChatbotService
BaseChatbotController <|-- ChatbotController
TypebotService o-- WAMonitoringService
TypebotService o-- OpenaiService
TypebotService o-- prismaRepository
BaseChatbotController o-- WAMonitoringService
BaseChatbotController o-- sessionRepository
BaseChatbotController o-- settingsRepository
Loading

File-Level Changes

Change Details Files
Emit TYPEBOT_CHANGE_STATUS webhooks from TypebotService
  • Import Events enum
  • Build typebotData payload with remoteJid, status and session
  • Invoke sendDataWebhook on various flows: initial open, session close or delete, keywordFinish handlers
src/api/integrations/chatbot/typebot/services/typebot.service.ts
Forward TYPEBOT_CHANGE_STATUS within BaseChatbotController
  • Import Events enum
  • Detect Typebot integrationName in incoming handlers
  • Retrieve session and build typebotData
  • Call sendDataWebhook for status and paused events
src/api/integrations/chatbot/base-chatbot.controller.ts

Possibly linked issues


Tips and commands

Interacting with Sourcery

  • Trigger a new review: Comment @sourcery-ai review on the pull request.
  • Continue discussions: Reply directly to Sourcery's review comments.
  • Generate a GitHub issue from a review comment: Ask Sourcery to create an
    issue from a review comment by replying to it. You can also reply to a
    review comment with @sourcery-ai issue to create an issue from it.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull
    request title to generate a title at any time. You can also comment
    @sourcery-ai title on the pull request to (re-)generate the title at any time.
  • Generate a pull request summary: Write @sourcery-ai summary anywhere in
    the pull request body to generate a PR summary at any time exactly where you
    want it. You can also comment @sourcery-ai summary on the pull request to
    (re-)generate the summary at any time.
  • Generate reviewer's guide: Comment @sourcery-ai guide on the pull
    request to (re-)generate the reviewer's guide at any time.
  • Resolve all Sourcery comments: Comment @sourcery-ai resolve on the
    pull request to resolve all Sourcery comments. Useful if you've already
    addressed all the comments and don't want to see them anymore.
  • Dismiss all Sourcery reviews: Comment @sourcery-ai dismiss on the pull
    request to dismiss all existing Sourcery reviews. Especially useful if you
    want to start fresh with a new review - don't forget to comment
    @sourcery-ai review to trigger a new review!

Customizing Your Experience

Access your dashboard to:

  • Enable or disable review features such as the Sourcery-generated pull request
    summary, the reviewer's guide, and others.
  • Change the review language.
  • Add, remove or edit custom review instructions.
  • Adjust other review settings.

Getting Help

Copy link
Contributor

@sourcery-ai sourcery-ai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey there - I've reviewed your changes - here's some feedback:

  • You’re repeating the same TYPEBOT_CHANGE_STATUS webhook emission logic in multiple branches—consider extracting it into a shared helper or method to DRY up the code.
  • Avoid hardcoding status values across the service and controller; centralize them as constants or an enum to ensure consistency and prevent typos.
Prompt for AI Agents
Please address the comments from this code review:
## Overall Comments
- You’re repeating the same TYPEBOT_CHANGE_STATUS webhook emission logic in multiple branches—consider extracting it into a shared helper or method to DRY up the code.
- Avoid hardcoding status values across the service and controller; centralize them as constants or an enum to ensure consistency and prevent typos.

Sourcery is free for open source - if you like our reviews please consider sharing them ✨
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.


const remoteJid = data.remoteJid;
const status = data.status;
const status = data.status;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

suggestion (code-quality): Prefer object destructuring when accessing and using properties. (use-object-destructuring)

Suggested change
const status = data.status;
const {status} = data;


ExplanationObject destructuring can often remove an unnecessary temporary reference, as well as making your code more succinct.

From the Airbnb Javascript Style Guide

@DavidsonGomes DavidsonGomes changed the base branch from main to develop September 9, 2025 16:53
@DavidsonGomes
Copy link
Collaborator

Please fix the lint with npm run lint

@DavidsonGomes DavidsonGomes merged commit 5015cfb into EvolutionAPI:develop Sep 9, 2025
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants