-
Notifications
You must be signed in to change notification settings - Fork 70
feat(webchat/guide): add render dropdown menu guide #438
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
Merged
Merged
Changes from all commits
Commits
Show all changes
14 commits
Select commit
Hold shift + click to select a range
ffae807
add render dropdown guide
chloequijano-botpress 0e32694
update wording
chloequijano-botpress 24523de
nit: workflow
chloequijano-botpress ea5cb76
Update webchat/interact/dropdown-menus.mdx
chloequijano-botpress 33966be
Update webchat/interact/dropdown-menus.mdx
chloequijano-botpress 6e61c75
Update webchat/interact/dropdown-menus.mdx
chloequijano-botpress d5a7e64
Update webchat/interact/dropdown-menus.mdx
chloequijano-botpress f338e8d
Update webchat/interact/dropdown-menus.mdx
chloequijano-botpress 697e5a8
Update webchat/interact/dropdown-menus.mdx
chloequijano-botpress 64910d9
Update webchat/interact/dropdown-menus.mdx
chloequijano-botpress d576085
Update webchat/interact/dropdown-menus.mdx
chloequijano-botpress 6b1f227
move guide to studio + link, update header
chloequijano-botpress d46dd6f
Update studio/guides/how-to/dropdown-menus.mdx
chloequijano-botpress 0d0dea7
update guide with feedback and other changes to wording
chloequijano-botpress File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,100 @@ | ||
| --- | ||
| title: Send options as a dropdown menu | ||
| --- | ||
|
|
||
| You can present options as a dropdown instead of buttons. This guide covers the built-in behaviour with [Capture Information](/studio/concepts/cards/capture-information) and an approach using code when you need a dropdown with fewer than six options. | ||
|
|
||
| <Info> | ||
| You will need: | ||
|
|
||
| - A [published bot](/get-started/quick-start) | ||
| - Familiarity with JavaScript if you use [method 2](#method-2-manual-dropdown-execute-code) | ||
| </Info> | ||
|
|
||
| <Warning> | ||
| The approach and styling in this guide are designed to work with [Webchat](/webchat/get-started/quick-start)'s choice components. If your bot is deployed on a different channel, you may need to modify the approach to work with that channel's components. Check out the [integrations](/integrations/get-started/introduction) section for more information. | ||
| </Warning> | ||
|
|
||
| ## Method 1: Automatic dropdown (Capture Information) | ||
|
|
||
| 1. Add a [Capture Information](/studio/concepts/cards/capture-information) Card to your [Workflow](/studio/concepts/workflows). Set the field type to **Single Choice** or **Multiple Choice** | ||
| 2. Add your options inside the Card under **Choices**. | ||
|
|
||
| If you add more than five options, they are shown as a dropdown (list) instead of buttons. (The exact threshold can vary slightly by channel. See [Choices](/studio/concepts/cards/capture-information#choices) on the Capture Information page.) | ||
|
|
||
| This is the simplest approach when you have enough options to trigger the dropdown UI. | ||
|
|
||
| ## Method 2: Manual dropdown (Execute Code) | ||
|
|
||
| To show a dropdown even when you have five or fewer options, or to build the option list in code, send a message with `type: 'dropdown'` from an [Execute Code](/studio/concepts/cards/execute-code) Card. | ||
|
|
||
| ### Send the dropdown message | ||
|
|
||
| ```javascript | ||
| await client.createMessage({ | ||
| userId: event.botId, | ||
| conversationId: event.conversationId, | ||
| tags: {}, | ||
| type: 'dropdown', | ||
| payload: { | ||
| text: 'Select an item:', // Shown above the control | ||
| options: [ | ||
| { label: 'Dropdown 1', value: 'dd1' }, | ||
| { label: 'Dropdown 2', value: 'dd2' }, | ||
| ], | ||
| }, | ||
| }) | ||
| ``` | ||
|
|
||
| 1. **`payload.text`**: Label or instruction shown with the control. | ||
| 2. **`payload.options`**: Each entry is `{ label: string, value: string }`. | ||
| 1. **`label`**: Text the user sees (for example, a product name). | ||
| 2. **`value`**: Value stored or matched in logic (for example, a SKU). They can match or differ. | ||
|
|
||
| <Tip> | ||
| In an Execute Code Card, you can read context from the [event object](/studio/guides/advanced/event-properties). | ||
| </Tip> | ||
|
|
||
| ### Complete the Workflow after the dropdown | ||
|
|
||
| After the dropdown is sent, the user will select an option. Here are some typical ways to handle this: | ||
|
|
||
| 1. Add a [Wait for User Input](/studio/concepts/cards/capture-information#wait-for-user-input) Card so the Workflow pauses until the user interacts | ||
|
|
||
| 2. Use an [Expression Card](/studio/concepts/cards/flow-logic#expression) (or similar) to evaluate their response by checking `event.payload.value` | ||
|
|
||
| 3. Use an **Execute Code** Card to store their choice. For example: | ||
|
|
||
| ```javascript | ||
| workflow.varName = event.payload.value | ||
| ``` | ||
|
|
||
| Remember to [create a Workflow variable](/studio/concepts/variables/scopes/workflow) (for example `varName`, type **String**) and grant access in code as needed ([variables in code](/studio/concepts/variables/in-code)). | ||
|
|
||
| Wire these cards in order in the same Node (or connected Nodes) so the bot always waits, validates, then saves before continuing. | ||
|
|
||
| ## Customize the placeholder text (CSS) | ||
|
|
||
| Classes for styling dropdowns are listed under **Use custom styles** on the [appearance settings](/webchat/get-started/configure-your-webchat#use-custom-styles) page. | ||
|
|
||
| To replace the default **Select…** style label with your own, add custom CSS under **Bot Appearance** → **Styles** in the Studio, for example: | ||
|
|
||
| ```css | ||
| /* Hide the original "Select..." text */ | ||
| .bpMessageBlocksDropdownButtonText { | ||
| font-size: 0; | ||
| color: transparent; | ||
| } | ||
|
|
||
| .bpMessageBlocksDropdownButtonText::before { | ||
| content: "Choose an option..."; | ||
| font-size: 0.8rem; | ||
| color: #7e7c7c; | ||
| } | ||
| ``` | ||
|
|
||
| Adjust `content`, `font-size`, and `color` to match your brand. | ||
|
|
||
| <Check> | ||
| You can rely on **Capture Information** for dropdowns when you have more than five choices, or use `createMessage` with `type: 'dropdown'` in an Execute Code Card whenever you need a dropdown with fewer options or custom `label` and `value` pairs. | ||
| </Check> | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.