This repo contains the Tightknit TDX Demo app for an LWC on Salesforce Experience Cloud sites that syncs chat messages with Slack.
Within the salesforce-app
directory is a Metadata API package that contains the following items:
ChatConversation__c
: custom object that represents a chat conversationChatMessage__c
: custom object that represents an individual chat message in a conversationChatController.cls
: custom Apex class for retrievingChatMessage__c
recordsKnowledgeArticleSearch.cls
: custom Apex class for searching a given search term in the org's Knowledge ArticlesquestionAndEscalation
("Question And Escalation" component): LWC custom component for Experience Cloud sites that offers users to search articles for their questions or talk to a customer support agent (on the Slack side)
The questionAndEscalation
component initially presents the user with a question box in which they can enter a search term. The component performs a search through the org's Knowledge Articles and presents the deflection results.
The user may click "Talk to Support" and switch to a chat window. Each time the user enters a message, the component sends a POST request to the companion Slack app's webhook URL, as well as creates a ChatMessage__c
record in Salesforce. The companion Slack app will be creating ChatMessage__c
records in Salesforce as well. The questionAndEscalation
component constantly polls Salesforce for all of the ChatMessage__c
records for the conversation and updates the chat window accordingly. Thus, the ChatMessage__c
records serve as the backend source of truth for the chat.
To be transparent, most of the manual setup listed here could be migrated into the actual Metadata API package in order to be deployed programmatically. But we ran out of time. Thus, this area is ripe for update if you would like to contribute! 😀
- Create an LWR Experience cloud site (instructions). The recommended template is Build Your Own (LWR).
- Allowlist the URLs related to the companion Slack app (i.e. CSP of site, Trusted Sites, or Remote Site Settings), including:
- the webhook URL of the Receive a message Slack trigger
- domain(s) that Slack profile images may be hosted on, e.g. https://avatars.slack-edge.com
- Open the Experience Builder > add the "Question And Escalation" custom component to your desired page.
- Configure the "Slack App Webhook URL" property of the component to use the Receive a message webhook URL of the companion Slack app.
To support non-authenticated users on the site, you will need to grant permissions to the site's Guest user to use the objects in this package.
- In the Guest user's profile, enable CRUD access to the custom objects in this package (instructions):
ChatConversation__c
ChatMessage__c
- In the Guest user's profile, enable access to the FLS of all fields of the custom objects (profile > Custom Field-Level Security section > click "View" next to the object name):
ChatConversation__c
ChatMessage__c
- In the Guest user's profile, enable CRUD access to the custom Apex classes in this package (instructions):
ChatController.cls
KnowledgeArticleSearch.cls
Guest User profile needs access to the FLS of all fields on the custom objects
The demo app contains a feature where a Slack user can trigger a workflow to save AI-generated text content into a new Salesforce Knowledge Article record. This is the last part of the demo flow and is not necessarily required for the app to function.
Follow the the Enable and Configure Lightning Knowledge trailhead to enable Lightning Knowledge for your Salesforce org. The basic steps are also outlined here:
- Enable Admin as a Knowledge user: Edit the Admin user object > enable as "Knowledge User"
- Enable Lightning Knowledge in the org: Go to Settings > Knowledge Settings > Enable Knowledge
- Enable Lightning Knowledge
- Turn on “Use standard Salesforce sharing”. Or if you prefer Data Category-based visibility permissions, you must configure DCs separately from these instructions.
- Configure Knowledge object and page layout: Go to Settings > Object Manager > Knowledge
- Page Layouts > edit Knowledge Layout > add “Visible in Public Knowledge Base” to the layout > Save (this is already visible in Salesforce Classic)
- Fields & Relationships > New > create the field that will contain your article body, e.g. Rich Text Area. Text-based fields are automatically included in searches against the object. Our demo app assumes a rich text field called
Description__c
.
Guide: https://help.salesforce.com/s/articleView?id=sf.knowledge_article_create.htm&type=5
Click on the App Launcher > Knowledge > click the New button > create the article > check “Visible In Public Knowledge Base” if you want the article visible to guest users > Save > Publish.
- Grant access to Knowledge object: Open the site guest user’s profile
- Click Edit > grant READ permissions for the Knowledge Base object
- Field-Level Security > click “View” for Knowledge > Edit > give Read access for your custom field that holds the article body (for this field to be visible in API responses)
- Grant access to Knowledge article records: Sharing Settings > Knowledge Sharing Rules > New > select “Guest user access, based on criteria” > create criteria that will apply to articles of your choice. For testing purposes you could create a rule that applies to all articles, such as
Created By ID - not equal to - 123456
). Select your site’s guest user > click Save.
- Open the Experience Builder
- Create the Knowledge object pages: click the
+ New Page
button > select "Object Pages" > select "Knowledge" - Open the Knowledge Detail Page > add the Knowledge Article component to the page
- Create the Knowledge object pages: click the
- Open the Workspaces view
- Select Administration > Preferences > check “Allow guest users to access public APIs” > click Save
Guide: https://developer.salesforce.com/docs/atlas.en-us.sfdx_dev.meta/sfdx_dev/sfdx_dev_intro.htm
Open a new VS Code window at this directory.
Download the following VS Code extensions:
- Salesforce Extension Pack
- Salesforce CLI Integration
Open Command Palette (Ctrl+Shift+P):
- Select "> SFDX: Authorize an Org"
- Log in to the org to authorize
Right-click any directory of the Salesforce project in the Explorer and select "SFDX: Deploy Source to Org".
Alternatively, you can use the Salesforce CLI:
# authorize the org
sfdx org:login:web --alias <ALIAS> --set-default
# set it as the default
sfdx force:config:set defaultusername=<USERNAME>
# confirm your orgs
sfdx force:org:list
# the -u is optional for default org
sfdx force:source:convert -d mdapioutput/
sfdx force:mdapi:deploy -d mdapioutput/ -w 100 -u <USERNAME>