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.
1// Create the message.
2AnyRequestMessage message = new TextMessage()
3 .text("Hello")
4 .type(TextMessage.TypeEnum.TEXT)
5 .sequenceId(System.currentTimeMillis());
6
7// Create the request body with the message.
8BotSendMessageRequest botSendInitMessageRequest = BotRequest
9 .withMessage(message)
10 .requestId(UUID.randomUUID().toString())
11 .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.
1ExternalSessionId externalSessionKey =
2 new ExternalSessionId(UUID.randomUUID().toString());
Start the session using the startChatSession() method.
1BotResponse response = client
2 .startChatSession(config, externalSessionKey, botSendInitMessageRequest);
Retrieve the bot’s session ID from the BotResponse object. Use this session ID to continue and end the session.
1String sessionId = response.getResponseEnvelope().getSessionId();