Intelligence
π How to build a chatbot with Flourish Intelligence.
Overviewβ
The Intelligence Chatbot Lightning Web Component (LWC) implements a conversational chatbot for Salesforce.
The chatbot is driven by JSON-defined conversation "paths", where each "path step" specifies:
- The messages to show (static or generated by LLMs),
- Navigation rules,
- Optional branching conditions, actions, or data collection steps.
Conversation Paths JSONβ
A chatbotβs flow is defined by an array of path steps. Example:
[
{
"id": "_START",
"messages": [
{ "type": "static", "content": "Hello!" },
{ "type": "generative", "content": "Share a fun animal fact" }
],
"navTarget": "continueAndLoop"
},
{
"id": "continueAndLoop",
"messages": [
{ "type": "generative", "content": "Continue the conversation and drive towards the end" }
],
"navTarget": "continueAndLoop"
}
]
Path Step Structureβ
Each path may contain:
| Field | Type | Description |
|---|---|---|
id | string | Unique identifier for the path. _START is the entry point. |
messages | array | Messages to display. Each item has a type (static or generative) and content. |
navTarget | string | object | The next pathβs ID, or a dynamic navigation object with options. |
type | string | Special modes (collectData, branch, customAction). |
datapoints | array | For collectData paths: specifies what to ask and store. |
branches | array | For branch paths: conditions for choosing paths. |
buttons | array | Optional buttons with labels and navTargets. |
intentionalActions | array | Optional intent-based routing using LLM classification. |
computeData / queryData | array | Used to generate or query Salesforce data at runtime. |
Supported Message Typesβ
Static Messagesβ
Directly display fixed text.
{ "type": "static", "content": "Hello, welcome to our chatbot!" }
Generative Messagesβ
Pass content as a prompt to generateResponse (Salesforce Apex β LLM).
{ "type": "generative", "content": "Suggest a next step for the user." }
Special Path Typesβ
collectDataβ
Prompts the user for values to populate context keys.
{
"id": "collectEmail",
"type": "collectData",
"datapoints": [
{ "datapoint": "email", "promptType": "static", "content": "Whatβs your email?" }
],
"navTarget": "nextStep"
}
branchβ
Conditional navigation based on expressions in context.
{
"id": "branchExample",
"type": "branch",
"branches": [
{
"conditions": ["{{{age}}} GTE 18"],
"evaluationType": "and",
"navTarget": "adultPath"
}
],
"branchDefaultNavTarget": "childPath"
}
customActionβ
Calls a function in chatWrapper (provided by host app).
{
"id": "doSomething",
"type": "customAction",
"actionName": "launchSurvey",
"properties": [
{ "id": "surveyId", "type": "static", "content": "12345" }
]
}
Context Handlingβ
- Stored in
chatbot.context(@api context). - Updated via
setContext,setContextItem, or during path execution. - Passed into message templates via
{{{key}}}replacements.
Example:
{ "type": "static", "content": "Hello, {{{firstName}}}!" }
Global Paths & Safeguardsβ
The system also supports global embeddings and flags:
- Restart chat (
GLOBAL_restartChat), - Request a call (
GLOBAL_requestCall), - Safety overrides (
GLOBAL_RED_selfharm,GLOBAL_RED_harmothers).
These are detected by embedding similarity against GLOBAL_EMBEDDINGS.
Example Usage in LWC Pageβ
<c-chatbot chatbot-id="a01xx0000001234"
record-id={recordId}
runtime-context='{"someKey": "someValue"}'
hide-footer={false}
onflintelligence={handleChatEvents}>
</c-chatbot>
π§ Advanced Path Capabilities
Beyond the basic messages, collectData, branch, and customAction types, paths can include additional behaviors that fine-tune the chatbotβs flow.
autoAdvanceβ
- Purpose: Automatically moves to the
navTargetafter the current path finishes. - Usage: Useful for transitional paths that donβt need user input.
{
"id": "autoStep",
"messages": [{ "type": "static", "content": "One moment..." }],
"navTarget": "nextStep",
"autoAdvance": true
}
buttonsβ
- Purpose: Show clickable buttons to the user.
- Behavior:
- Each button has a label and
navTarget. - When clicked, the corresponding path is advanced.
- The UI disables buttons after selection to prevent re-clicking.
- Each button has a label and
{
"id": "chooseOption",
"messages": [{ "type": "static", "content": "Pick one:" }],
"buttons": [
{ "label": "Yes", "navTarget": "yesPath" },
{ "label": "No", "navTarget": "noPath" }
]
}
intentionalActionsβ
- Purpose: Detects user intent using LLM classification and routes accordingly.
- Behavior:
- Runs a classification prompt asking whether the user expressed each listed intent.
- If βYES,β the corresponding action is taken.
- Can either:
- Navigate (
navTarget), or - Call a custom action in
chatWrapper.
- Navigate (
{
"id": "intentRouter",
"intentionalActions": [
{ "intent": "Book appointment", "navTarget": "bookPath" },
{ "intent": "Cancel appointment", "navTarget": "cancelPath" }
]
}
computeDataβ
- Purpose: Generate runtime values using LLMs.
- Behavior:
- Runs a generative prompt, stores result in
context.
- Runs a generative prompt, stores result in
{
"id": "computeGreeting",
"computeData": [
{ "datapoint": "greeting", "content": "Generate a warm greeting for the user." }
],
"navTarget": "nextStep"
}
queryDataβ
- Purpose: Run Salesforce SOQL-like queries securely.
- Behavior:
- Uses
querySecureApex call. - Results are stored in
contextand chunked into system messages for LLM awareness.
- Uses
{
"id": "lookupAccount",
"queryData": {
"queryDatapoints": [
{
"datapoint": "accounts",
"sobjectName": "Account",
"query": "SELECT Id, Name FROM Account WHERE OwnerId = '{{{_RECORDID}}}'",
"recordLimit": 5
}
]
},
"navTarget": "showAccounts"
}
instructChatbotβ
- Purpose: Add extra system-level instructions to the LLM context for this path.
{
"id": "specialTone",
"instructChatbot": "Always respond in pirate style for this step!",
"messages": [{ "type": "generative", "content": "Say hello" }],
"navTarget": "nextStep"
}
userEndSignOff & userEndButtonsβ
- Purpose: Handle end-of-conversation detection.
- Behavior:
- If user explicitly asks to change or end topics, chatbot can show final buttons.
- Optional sign-off message before buttons.
{
"id": "endPath",
"listenForUserEnd": true,
"userEndSignOff": { "type": "static", "content": "Glad to help!" },
"userEndButtons": [
{ "label": "Start over", "navTarget": "_START" }
]
}
dynamic navTargetβ
- Purpose: Let the LLM decide the next step dynamically.
- Behavior: The system sends conversation history and a JSON list of possible options; LLM picks one.
{
"id": "dynamicRouter",
"navTarget": {
"type": "dynamic",
"options": [
{ "navTarget": "helpPath" },
{ "navTarget": "faqPath" },
{ "navTarget": "escalationPath" }
]
}
}
β‘ These capabilities make paths flexible building blocks: some provide UX enhancements (buttons), some handle logic (branch, autoAdvance, intentionalActions), and some connect to Salesforce (queryData).
π Visualizing Path Flows
Hereβs a sample flow diagram for a simple chatbot:
π Each path maps to the corresponding JSON id, and arrows represent navTarget transitions.