Use the Session-Managed Bot Client

This section provides code samples of running a bot session with the SessionManagedChatbotClient interface.

The SessionManagedChatbotClient adds session management capabilities on top of the BasicChatbotClient. Therefore, to create an instance of the session-managed client, pass BasicChatbotClient as a parameter to the SessionManagedChatbotClient. See Use the Basic Bot Client.

If you are running the client locally, you can use InMemoryCache(YOUR_TTL_SECONDS) instead of RedisCache(YOUR_TTL_SECONDS,YOUR_REDIS_URL) for the .cache value. The InMemoryCache is the better caching method when running the client locally but for production use RedisCache or your own distributed cache.

Then create a RequestConfig object and add the bot ID, org ID, ForceConfig Endpoint that you already set up in the Set Up the Configuration Variables section.

The session-managed client starts a new session and sends subsequent messages using the same method instead of two separate methods. A session is tracked by a combination of the external session ID, bot ID, and org ID. If the client sends a message request with a new combination of those IDs, the bot starts a new session. If the combination exists, the message is part of an active session.

The BotResponse object is the same as the one of the BasicChatbotClient so you can Retrieve the Bot’s Response the same way.

The code is the same as End a Bot Session for the BasicChatbotClient except that you pass externalSessionId instead of the bot’s internal session ID.