'AWS Lex - Clear Session

Is there a way to clear/close a session in AWS Lex through the API call (boto3).

Say, the user is conversing with Lex bot which serves multiple intents. At some point, the user gives a negative answer to a prompt from the bot to abort the current intent. I am able to recognize that the user wants to talk about some other intent of the bot. I want a way to clear the current session through API call (Boto3) so that the bot is not expecting input for the closed intent.

Thanks.



Solution 1:[1]

There is no published API call for resetting the slot data and attributes of a Lex session, but you can always switch to a brand-new session. This is what the Console does when you click on "Clear chat history" in the "Test bot" interface. The abandoned session will time out in 5 min by default.

You can open a new session by submitting a new userId in the next call to PostText. This is one way to do it – every call will start a new session:

import uuid
boto3.client('lex-runtime').post_text(
    botName='mybot',
    botAlias = 'alphathree',
    userId=uuid.uuid4().hex,
    inputText="I want to order 5 gallons of ice cream")

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Veliander