Search code examples
botframework

How do I clean up the botstate db in Cosmos DB


I'd like to periodically clean up old conversations/user states, e.g. older than 30 days. Is there a script that can do that?


Solution

  • There is no direct way of achieving this currently through the framework.

    I have been able to achieve this in one simple way.

    Assuming you are using CosmosDB(SQL) for your state management, you could set the TTL for that container. This will help deleting the documents that are 30days since the last update done to them.

    Setting the TTL at container level

    You could also do the same by setting the TTL, when you first create the container through your Bot SDK, that way you wouldnt need to manually change it on portal.