feat: add Einstein Bots plugin to enable/disable Einstein Bots#735
feat: add Einstein Bots plugin to enable/disable Einstein Bots#735diego-ploche-ef wants to merge 1 commit intoamtrack:mainfrom
Conversation
Add new plugin to toggle Einstein Bots feature in Salesforce Setup. - Implements retrieve() to check current enabled state - Implements apply() to enable or disable Einstein Bots - Handles confirmation dialog when disabling - Includes e2e test spec and example config files
There was a problem hiding this comment.
@diego-ploche-ef Thank you for your contribution.
Unfortunately neither enabling nor disabling worked in my tests.
Please make sure the E2E tests are passing
- for a newly created scratch org
- as well as multiple times for an existing scratch org
Actually we only need browser automation to accept the terms.
After the terms have been accepted, we can deploy the BotSettings metadata.
So my idea would be to use metadata.read in retrieve() and metadata.update in apply().
If the update fails via metadata.update, we know that we need to accept the terms via browser automation.
div#setupComponent lightning-primitive-input-toggle:has(input[role="switch"]:not(:disabled))Einstein Bots toggle- In
div[role="dialog"]input[type="checkbox"][name="agreedterms"]// I’m authorized by my company to accept these termsbutton.nextButton// "Try Einstein"page.waitForResponse(/ChatbotSetup.setPrefs=1/)
| await using page = await this.browserforce.openPage(BASE_PATH); | ||
| await page.locator(TOGGLE_INPUT_SELECTOR).waitFor(); | ||
| const response = { | ||
| enabled: await page.locator(TOGGLE_INPUT_SELECTOR).isChecked(), | ||
| }; |
There was a problem hiding this comment.
| await using page = await this.browserforce.openPage(BASE_PATH); | |
| await page.locator(TOGGLE_INPUT_SELECTOR).waitFor(); | |
| const response = { | |
| enabled: await page.locator(TOGGLE_INPUT_SELECTOR).isChecked(), | |
| }; | |
| const botSettings = await this.browserforce.connection.metadata.read('BotSettings', 'BotSettings'); | |
| const response = { | |
| enabled: botSettings.enableBots, | |
| }; |
| } | ||
|
|
||
| // Wait for the save to complete | ||
| await page.waitForTimeout(2000); |
There was a problem hiding this comment.
Sleeping is not a good practice.
Consider something like this:
| await page.waitForTimeout(2000); | |
| await page.waitForResponse(/ChatbotSetup\.setPrefs=1/) |
| if (currentState !== config.enabled) { | ||
| if (!config.enabled) { | ||
| // When disabling, click the toggle and wait for the confirmation dialog | ||
| await page.locator(TOGGLE_INPUT_SELECTOR).click({ force: true }); |
There was a problem hiding this comment.
I assume the click event on the input is not working.
Please consider clicking on the parent lightning-primitive-input-toggle element:
div#setupComponent lightning-primitive-input-toggle:has(input[role="switch"]:not(:disabled))
| "title": "Einstein Bots", | ||
| "description": "Enable or disable Einstein Bots. Setup -> Einstein Bots -> Einstein Bots toggle.", |
There was a problem hiding this comment.
Please include the reason why this is necessary.
| "title": "Einstein Bots", | |
| "description": "Enable or disable Einstein Bots. Setup -> Einstein Bots -> Einstein Bots toggle.", | |
| "title": "Enable or disable Einstein Bots. Setup -> Einstein Bots -> Einstein Bots toggle.", | |
| "Although the Metadata API has a BotSettings.enableBots field, it is not possible to enable this setting using an API. Error: Legal Terms acceptance and/or necessary feature dependencies required to enable Bot Settings.", |
Summary
Add a new plugin to enable/disable Einstein Bots in Salesforce Setup.
Description
This plugin automates the Einstein Bots toggle found at Setup → Einstein Bots → Einstein Bots toggle.
Features
retrieve()- Checks the current enabled/disabled state of Einstein Botsapply()- Enables or disables Einstein Bots based on configurationConfiguration
Enable Einstein Bots:
{ "settings": { "einsteinBots": { "enabled": true } } }Disable Einstein Bots:
{ "settings": { "einsteinBots": { "enabled": false } } }Testing
npm test)Checklist