EDIT singleflight to work with messages if AI is taking long

This commit is contained in:
maximo tejeda 2025-02-23 09:56:34 -04:00
parent 0f2762d53c
commit 01585ea59b

View File

@ -39,6 +39,17 @@ func SingleFlight(next bot.HandlerFunc) bot.HandlerFunc {
} }
defer sf.Delete(key) defer sf.Delete(key)
next(ctx, b, update) next(ctx, b, update)
}else if update.Message != nil {
key := update.Message.From.ID
if _, loaded := sf.LoadOrStore(key, struct{}{}); loaded{
log.Debug("key alredy loaded", "key", key)
b.SendMessage(ctx, &bot.SendMessageParams{ChatID: update.Message.From.ID, Text: "IA esta aun procesando su respuesta, por favor espere!!!"})
return
}else{
log.Debug("key not loaded", "key", key)
}
defer sf.Delete(key)
next(ctx, b, update)
} }
} }
} }