# Create a Sample Einstein Bot

To help your customers efficiently set up an Einstein Bot with Bring Your Own Channel for CCaaS, create a sample Einstein Bot and associated Omni-Channel Flows and include them in your managed package.

In this example, we create an outbound Omni-Channnel Flow that routes from a bot to a rep. We then set up a sample Einstein Bot that uses this outbound flow and automatically generates a corresponding inbound flow that sends conversations to the bot. For your package, we recommend creating a flow and bot configuration that reflects the expected business logic of your customers.

## Create a Flow

Follow steps in Salesforce Help to create an Omni-Channel flow to [Route Work Items to a Specific Agent](https://help.salesforce.com/s/articleView?id=service.omnichannel_route_to_specific_agent.htm). This sample outbound flow transfers the Messaging end user from an Einstein Bot to a rep.

You need this flow to select it as the **Outbound Omni-Channel Flow** during Einstein Bot setup.

## Create an Einstein Bot

1. From Setup, in the Quick Find box, enter `Einstein Bots`, and then select **Einstein Bots**.
2. Enable Einstein Bots if it’s not already enabled.
3. Launch the guided setup from the Einstein Bots main page. For your first bot, click **Create a New Bot**. Otherwise, click **New**.
4. Select **Enhanced Bot**, and then click **Next**.
5. To create an Einstein bot from scratch, select **Start from Scratch**, and then click **Next**.
6. Personalize your sample bot.
   - Enter a bot name, select a primary language, and then click **Next**.
   - Modify the welcome message, but don’t customize the menu items. Your customers adjust them when they clone your sample Einstein Bot. When you’re done, click **Next**.
7. On the Link to deployment page of the guided setup, select **Create an inbound Omni-Channel flow for my bot**, and then from **Outbound Omni-Channel Flow** dropdown, select the flow that you created.
8. Click **Proceed** to start the bot creation process, and then click **Finish** to confirm when it’s done.

When the system has finished creating the bot, Einstein Bot Builder opens.

### Configure the Bot

Configure the Einstein Bot to trigger the sample flow that transfers a Messaging session from the bot to a rep.

1. If you aren’t already in Einstein Bot Builder, from Setup, enter `Einstein Bots` in the Quick Find box, and then select **Einstein Bots**. In the My Bots section, select the name of the bot that you created.
2. In Einstein Bot Builder, from the Bot Builder menu, click **Dialogs**.
3. In the Dialogs panel, click **New**.
4. Give the dialog a name, such as `Get help from a representative`. Enter an API name and optional description, and save.
5. In the Dialogs panel, select the newly created dialog.
6. Click **Next Step**. From the Step Properties panel, select **Transfer to an agent**.
   ![Dialog with Transfer to an agent selected as Next Step](https://a.sfdcstatic.com/developer-website/sfdocs/service-cloud/media/messaging-byoc-ccaas/byoc-ccaas-einstein-bot-get-help-from-agent-dialog.png)
7. Save the dialog.
8. In the Dialogs panel, select **Main Menu**.
9. Click **Next Step**. From the Step Properties panel, select **Show a menu** and add the `Get help from an agent` dialog you created previously as one of the menu items.
   ![Main Menu Dialog with Get help from an agent included as a menu item](https://a.sfdcstatic.com/developer-website/sfdocs/service-cloud/media/messaging-byoc-ccaas/byoc-ccaas-einstein-bot-main-menu-dialog.png)
10. Save your work.

## Include the Sample Einstein Bot and Flows in Your Managed Package

When you [create the managed package](/docs/service/messaging-byoc-ccaas/guide/create-managed-package.md) for your integration, add these components to the managed package.

- The sample Einstein Bot that you created
- The sample Omni-Channel outbound flow that you created
- The inbound Omni-Channel flow that the system automatically created

## Handle Partner-Owned Routing

If `routingOwner` is `Partner` in the Conversation Channel Definition record, partners handle routing for the messaging session to and from the Einstein Bot. If `routingOwner` is `Salesforce`, partners don’t need to handle routing to or from the Einsten Bot. Salesforce handles this automatically.

### Handle Partner Routing to an Einstein Bot

Perform the API calls in the order listed to handle routing for the inbound Omni-Channel flow that connects a messaging end user to an Einstein Bot.

- Call the Interaction API (`POST /api/v1/interactions`) to create a conversation messaging session and a messagingEndUser record. This API execution returns a `conversationIdentifier` value used in the next step.
- Call the Route API (`POST /api/v1/route`) with `routingType` set to `initial` and `conversationIdentifier` set to the `conversationIdentifier` value returned from the previous step. This executes the inbound Omni-Channel flow that’s associated with the messaging channel.
  - In the Route API payload, pass in the ID of `flowDefinitionView`for the `flowId` field. For the `queueId` field, pass in the ID of `fallbackQueue`. The customer provides these values.
  - The Route API response includes the `salesforceBotId` and `psrId`.

The Einstein Bot is added to the conversation and sends a welcome message to the end user.

### Handle Partner Routing to Escalate from an Einstein Bot to a Rep

Perform the API calls in the order listed to handle routing for the outbound Omni-Channel flow that transfers a messaging end user from an Einstein Bot to a rep.

- A routing request event provides the flow ID of the outbound Omni-Channel flow. The flow can be customer-configured.
- Call the Route API (`POST /api/v1/route`) with `routingType` set to `transfer` to execute the flow ID provided by the routing request event. Alternatively, transfer to the `fallbackQueueId` if the transfer to the outbound Omni-Channel flow fails.
- The Omni-Channel flow uses the logic in the flow to route the conversation to a rep or queue. The flow returns the `psrId` with the `userId` (agent) or `queueId` (queue).
- Call the agentWork API (`POST /api/v1/agentWork`) to create an AgentWork record when the system finds a potential rep or queue to handle the work item.
- After routing completes, call the routingResult API (`POST /api/v1/routingResult`) to notify Salesforce whether the conversation succeeded or failed.

**See Also**

- *Salesforce Help*: [Set Up an Einstein Bot for Bring Your Own Channel](https://help.salesforce.com/s/articleView?id=service.byoc_ccaas_einstein_bot.htm)
- *Salesforce Help*: [Route Conversations to and from Your Enhanced Bot](https://help.salesforce.com/s/articleView?id=service.bots_service_enhanced_route.htm)
- *Salesforce Help*: [Add a Dialog](https://help.salesforce.com/s/articleView?id=service.bots_service_new_dialog.htm)
- *Salesforce Help*: [Set Up a Dialog](https://help.salesforce.com/s/articleView?id=service.bots_service_new_dialog.htm)
- [Interaction Service API](https://developer.salesforce.com/docs/service/interaction-service-api/guide/get-started.md)
- *GitHub*: [Interaction Service APIs](https://github.com/salesforce-misc/interaction-service-apis)
