How to handle user inactivity in a WhatsApp chatbot with Redis

I’m building a WhatsApp chatbot using n8n, and I’m trying to manage user inactivity.

Currently, I’m storing some user data in a Redis instance, and I have a flow that removes the keys using TTL. The issue is that the Redis Push node doesn’t have a TTL option.

What I’d like to do is detect user inactivity — for example, based on the last message received by the WhatsApp trigger — and automatically delete the keys related to that user or flow when they’ve been inactive for a certain amount of time.

Does anyone know a good approach to handle this kind of inactivity logic in n8n?
There is a good pattern for cleaning up inactive users when using Redis with WhatsApp flows?

Thanks in advance for your help!

Please share your workflow

Information on your n8n setup

  • n8n version: 1.106.3
  • Running n8n via (Docker, npm, n8n cloud, desktop app): Cloud
  • Operating system: Windows

If you store last user activity timestamp to your database, you can filter users by using a Filter node: If {{ $json.userActivityTimestamp + 3600 }} is type:date equals {{ $now }} Here I used 3600 which normally equals sixty minutes, but it depends on your timestamp value. Using this filter, you will discard users who were inactive for sixty minutes. However, make sure to update(reset) this value if the user sends a message.

You can also use an IF node, if you want to route into two branches instead.

1 Like

Thanks you!

1 Like