Skip to content

feat: add Einstein Bots plugin to enable/disable Einstein Bots#735

Open
diego-ploche-ef wants to merge 1 commit intoamtrack:mainfrom
diego-ploche-ef:feature/einstein-bots-plugin
Open

feat: add Einstein Bots plugin to enable/disable Einstein Bots#735
diego-ploche-ef wants to merge 1 commit intoamtrack:mainfrom
diego-ploche-ef:feature/einstein-bots-plugin

Conversation

@diego-ploche-ef
Copy link

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 Bots
  • apply() - Enables or disables Einstein Bots based on configuration
  • Handles the confirmation dialog that appears when disabling Einstein Bots

Configuration

Enable Einstein Bots:

{
  "settings": {
    "einsteinBots": {
      "enabled": true
    }
  }
}

Disable Einstein Bots:

{
  "settings": {
    "einsteinBots": {
      "enabled": false
    }
  }
}

Testing

  • Unit tests pass (npm test)
  • Manual testing: Enable works in headless mode
  • Manual testing: Disable works in headless mode (handles confirmation dialog)
  • E2E test spec included

Checklist

  • Follows existing plugin patterns
  • Includes schema.json for config validation
  • Includes example config files (enable.json, disable.json)
  • Includes e2e test spec
  • Exported in src/plugins/index.ts
  • Referenced in src/plugins/schema.json

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
Copy link
Owner

@amtrack amtrack left a comment

Choose a reason for hiding this comment

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

@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 terms
    • button.nextButton // "Try Einstein"
    • page.waitForResponse(/ChatbotSetup.setPrefs=1/)

Comment on lines +14 to +18
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(),
};
Copy link
Owner

Choose a reason for hiding this comment

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

Suggested change
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);
Copy link
Owner

Choose a reason for hiding this comment

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

Sleeping is not a good practice.
Consider something like this:

Suggested change
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 });
Copy link
Owner

Choose a reason for hiding this comment

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

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))

Comment on lines +8 to +9
"title": "Einstein Bots",
"description": "Enable or disable Einstein Bots. Setup -> Einstein Bots -> Einstein Bots toggle.",
Copy link
Owner

Choose a reason for hiding this comment

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

Please include the reason why this is necessary.

Suggested change
"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.",

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