tabrza
tabrza

Reputation: 11

AWS Lex bot: Enable user to continue conversation after page refresh

I'm currently building a bot using AWS Lex. One issue I'm facing is how to store the user's session and the retrieve it in order for the bot to be able to continue the conversation (and show the previous conversation) if the user goes to a new page, refreshes the page or returns after for example a week?

e.g. 1 For example, the bot is helping the user make a buying decision while the user is checking different pages on an ecommerce site.

e.g. 2 Another example could be where the user revisits the website after a week and the bot recognises the user, shows the previous conversation history and sends a customised message?

Upvotes: 0

Views: 797

Answers (1)

Suraj
Suraj

Reputation: 1695

AWS provides LexRuntime javascript APIs for web integration. This API provides the NLP but does not store/fetch the conversation history. You have to create your own application server and store conversations into DB. You also need to manage the database of users coming to your website.

When a user visits the website, get the conversation history of the user from DB and populate it on UI. This way even a user refreshes a page he will be able to see the chat history as it is being loaded from DB.

Now the question is How does the Lex remember the user and for how long?

The Lex creates user session using the below parameters :

  • Bot name
  • Bot alias
  • User id

These parameters are sent to Lex along with user queries. Here user id can be any unique identifier that represents a user of your website. Lex uses these parameters to determine the session for the current user query. If any of these values are changed Lex will create a new session or reuse existing if available for the same set of values. By default, the session duration is 5 minutes, but you can specify any duration between 0 and 1,440 minutes (24 hours).

Using the Lex Runtime APIs you can use below two methods to send the user queries to your bot:

Both methods require botName, aliasName, and userId parameters. I hope this answers your second question.

Now coming to your first use case where

A bot is helping the user to make a buying decision while the user is checking different pages on an e-commerce site.

To achieve this, first, you have to implement the above approach. Once this is done, you can send the page URL(in which bot sits) to Lex. You can send this info as a request attribute. At the Lex console, use a lambda function to determine the response according to the page URL.

All this takes the development efforts and time. There are a lot of third-party tools available that provide the code less integration with lex. I recommend the Kommunicate. Have a look at this blog too.

Upvotes: 5

Related Questions