Skip to content

Conversation

IlyaMatsuev
Copy link
Owner

What does this PR do?

This PR changes the way Bot Webhook events are handled.

How it works now:

  • The updates are received via the Force.com Site as a guest user
  • The platform event is fired, to allow handling the update as an Automated Process instead
  • The user, chat, and messages are upserted synchronously accordingly based on the incoming update
  • The queueable job is scheduled after that, to handle the update with an Apex handler from the Bot__c record

How it will work:

  • The updates are received via the Force.com Site as a guest user (no changes)
  • The new background flow is launched under the guest user in the System Context mode (Access All Data)
  • The user, chat, and messages are upserted asynchronously using the platform event
  • The Bot__c handler implementation is executed in the same transaction

This change will greatly speed up the processing of the Webhook updates since we avoid two asynchronous executions (one for the platform event, and the second for the queuable job).

Cons:

  • Even when running in System Context via the flow, if an Apex class used for handling the updates has the with sharing option, the guest user won't be able to perform CRUD operations on sObjects (read only).
  • The Bot__c handler implementation is running in the same transaction, so all the transaction limits are also shared with this framework's implementation.

The new way of handling the webhooks will be enabled by ticking the ShareHandlingTransaction__c setting under the Bot Setting custom metadata type, which is false by default.

The PR fulfills these requirements:

  • Tests for the proposed changes have been added/updated.
  • The documentation has been updated according to the introduced/changed components.
  • ApexDoc comments have been attached to all global classes, fields, properties and methods.

@IlyaMatsuev IlyaMatsuev self-assigned this May 22, 2025
@IlyaMatsuev IlyaMatsuev added enhancement New feature or request release labels May 22, 2025
@codecov
Copy link

codecov bot commented May 22, 2025

Codecov Report

Attention: Patch coverage is 96.00000% with 2 lines in your changes missing coverage. Please review.

Project coverage is 97.56%. Comparing base (3b15cc4) to head (940de55).
Report is 1 commits behind head on main.

Files with missing lines Patch % Lines
src/main/default/classes/api/BotUpdateApi.cls 75.00% 2 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main      #35      +/-   ##
==========================================
+ Coverage   97.52%   97.56%   +0.04%     
==========================================
  Files         153      154       +1     
  Lines        3916     3941      +25     
==========================================
+ Hits         3819     3845      +26     
+ Misses         97       96       -1     
Flag Coverage Δ
Apex 97.56% <96.00%> (+0.04%) ⬆️
unittests 97.56% <96.00%> (+0.04%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@IlyaMatsuev IlyaMatsuev merged commit be57f5c into main May 22, 2025
4 of 5 checks passed
@IlyaMatsuev IlyaMatsuev deleted the release-v2 branch May 22, 2025 23:19
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request release

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant