Closed rmasci closed 4 years ago
Hi,
There isn't a built-in feature for this but here's a couple ideas:
SetUservar
and store the timestamp of the user's last interaction.GetAllUservars()
and check users whose last contact time was older than a certain threshhold.ClearUservars()
for each of those users.Something like,
go func() {
for {
time.Sleep(5 * time.Minute)
users := bot.GetAllUservars()
for _, username := range users {
if timestamp, err := bot.GetUservar(username, "lastSeen"); err == nil {
ts, _ := time.Parse(time.RFC3339, timestamp) // like "2006-01-02T15:04:05Z"
if time.Now().Sub(ts) > (30 * time.Minute) {
// user has expired
bot.ClearUservars(username)
}
}
}
}
}()
// ...
func GetReply(username, message string) (string, error) {
reply, err := bot.Reply(username, message)
bot.SetUservar(username, "lastSeen", time.Now().Format(time.RFC3339)
return reply, err
}
Auto-expiring data is something Redis is really good at, and there's already a Redis-backed session driver for user variable storage, but it doesn't have a feature to do this yet. If you're up for it, you could add this feature to the Redis session driver and send me a pull request (assuming you'd want to use Redis at all for your bot).
That change might look like:
I put somethign like this in place where I store the date they went in to a topic, then every message I get from that user i check the time, If 5 min has gone past without a message it reverts back to no topic. Thanks!!
I have a chatbot running, and I have programming that allows a user to start a troubleshooting session, and each step is a topic. The problem is they may go away, and then come back hours later and try to ask the chatbot another question -- but they're stuck inside the topic they left on which may be a few days ago. Is there a way to time out a topic? So that ten minutes later it goes back to topic=random?