---
schema_version: "1"
id: 232ed49dbb6a65fc97d23f0c9acee7997acf91fb268ddba1fc6e0e4c4416fcc6
title: Start a Session
collection: developer
version: current
locale: en-us
portal_url: https://docs.salesforce.com/developer/current/en-us/bot-api/einstein-bot/guides/sdk/sdk-basic-bot-client-start-a-session.md
canonical_url: https://developer.salesforce.com/docs/service/einstein-bot-api/guide/sdk-basic-bot-client-start-a-session.html
source_site: developer.salesforce.com
content_type: documentation
content_hash: bdc17459796e113c4779cd7c1775d03b79de8ec9fff18320a42e75167ba36f52
products:
  - Einstein Bots API and SDK
  - Enstein Bot API and SDK
---
# Start a Session

To start a session with the bot, the request body from the external channel `BotSendMessageRequest` must have the type `TextMessage`. Here the customer sends a “Hello” message to the bot. The `requestId` is an optional UUID that you can provide to help track the requests.

```java
// Create the message.
AnyRequestMessage message = new TextMessage()
    .text("Hello")
    .type(TextMessage.TypeEnum.TEXT)
    .sequenceId(System.currentTimeMillis());

// Create the request body with the message.
BotSendMessageRequest botSendInitMessageRequest = BotRequest
    .withMessage(message)
    .requestId(UUID.randomUUID().toString())
    .build();
```

Then retrieve the `ExternalSessionId` from the external channel, for example, a Slack or Twitter thread ID. We’re using a random UUID for the external session ID in the sample code.

```java
ExternalSessionId externalSessionKey =
    new ExternalSessionId(UUID.randomUUID().toString());
```

Start the session using the `startChatSession()` method.

```java
BotResponse response = client
    .startChatSession(config, externalSessionKey, botSendInitMessageRequest);
```

Retrieve the bot’s session ID from the `BotResponse` object. Use this session ID to continue and end the session.

```java
String sessionId = response.getResponseEnvelope().getSessionId();
```
