Note
Access to this page requires authorization. You can try signing in or changing directories.
Access to this page requires authorization. You can try changing directories.
This document provides step-by-step instructions on how to create and connect an Einstein Bot to a Copilot Studio agent. This integration allows you to use the capabilities of both platforms to enhance your agent experience.
Prerequisites
Before you begin, ensure that you have the following prerequisites in place:
- An active Salesforce account with Einstein Bots enabled.
- A Copilot Studio account.
- Admin or developer access to both Salesforce and Microsoft Power Platform.
Step 1: Retrieve Direct Line secret for your agent
- Retrieve your Direct LinesSecret.
Step 2: Configure Salesforce remote site settings
Sign in to your Salesforce account.
In Salesforce, navigate to Setup.
In the Quick Find box, type Remote Site Settings and select Remote Site Settings.
Add a new remote site, then fill in Remote Site Name as Copilot Studio and Remote Site URL as https://directline.botframework.com
Select Save.
Note
For other regions use the appropriate URL for the DirectLine API URL
Step 3: Create Apex Classes to connect to DirectLine API
Sign in to your Salesforce account.
In Salesforce, navigate to Setup.
In the Quick Find box, type Apex Classes.
Create three new classes with the following details:
DL_GetConversation
- Inputs: None
- Outputs:
conversationId
(String),responseCode
(Integer),errorMessage
(String) InvocableMethod getConversationID
: Use your DirectLine Secret to make an HTTP call to the DirectLine endpoint starting a conversation.
DL_PostActivity
- Inputs:
conversationId
(String),userMessage
(String) - Outputs:
responseCode
(Integer),errorMessage
(String),watermark
(String) InvocableMethod postActivity
: Execute an HTTP call to the post activity DirectLine API using theconversationId
in the URL anduserMessage
.
DL_GetActivity
- Inputs:
conversationId
(String),watermark
(String) - Outputs:
message
(String),watermark
(String),responseCode
(Integer),errorMessage
(String) InvocableMethod getActivity
: Execute an HTTP call to thegetActivity
DirectLine API, using theconversationId
andwatermark
to retrieve and parse the activity object for the message to send back to the user.
Step 4: Setup Einstein bot
Sign in to your Salesforce account.
In Salesforce, navigate to Setup.
In the Quick Find box, type Einstein and select Einstein Bots.
Create a new Einstein bot following the steps within the Salesforce Einstein Documentation.
Step 5: Connect Einstein Bot to PVA with Apex classes
In the Einstein Bot, to have the bot reach out on each utterance outside of Einstein topics you can add references to the previously created Apex classes:
In the Welcome topic, add an Apex class action referencing the
DL_GetConversation
class and assign the response variables appropriately.In the Confused topic, add an Apex class action referencing the
DL_PostActivity
class, passing theconversationId
and last user input. Be sure to set the response variables to other variables.Create a condition to check the Response Code from the DL_PostActivity Apex action, if the code is 200 or 204 you can continue, otherwise display the Error Message.
Add another Apex class action to DL_GetActivity, setting the
conversationId
fromGetConversation
and thewatermark
from thePostActivity
, and assigning the response variables.
Note
You may want to create GetActivity
as a separate topic. You might need to loop on DL_GetActivity
to get the actual response, if it takes longer to fetch.
Create a condition to check the response code and that the return message is set, if so, then go to a message node to output the response.
The last step in the flow should remain as "Wait for Customer Input."
Step 6: Handle Agent Hand off
When accessing an agent from Einstein, the agent is only used in a request/response model: based on the user's query, an agent fetches the most appropriate KB, and summarizes the answer.
Because you can continue to configure your Einstein bot, you can implement any other topic triggers or escalation triggers in Einstein. This extra configuration allows your users to escalate to the appropriate Salesforce Live Agent queues.
For more information, see the Salesforce documentation Route Conversations from an Enhanced Bot.