yao/agent/robot/events/integrations/weixin/typing_cache.go
Max 09af247a7c feat(robot): add Weixin integration and enhance existing adapters
- Introduced Weixin integration support with new configuration options for WeChat iLink Bot.
- Updated existing adapters (DingTalk, Discord, Feishu, Telegram) to include sender_id and app_id in message metadata for improved context handling.
- Enhanced dispatcher logic to accommodate the new Weixin adapter and ensure proper initialization and shutdown processes.
- Improved message handling across integrations to support typing indicators, providing a more interactive user experience.
2026-03-23 23:47:25 +08:00

43 lines
753 B
Go

package weixin
import (
"sync"
"time"
)
const ticketTTL = 20 * time.Hour
type ticketEntry struct {
ticket string
expiresAt time.Time
}
type typingTicketCache struct {
mu sync.RWMutex
items map[string]*ticketEntry
}
func newTypingTicketCache() *typingTicketCache {
return &typingTicketCache{
items: make(map[string]*ticketEntry),
}
}
func (c *typingTicketCache) Get(userID string) string {
c.mu.RLock()
defer c.mu.RUnlock()
entry, ok := c.items[userID]
if !ok || time.Now().After(entry.expiresAt) {
return ""
}
return entry.ticket
}
func (c *typingTicketCache) Set(userID, ticket string) {
c.mu.Lock()
defer c.mu.Unlock()
c.items[userID] = &ticketEntry{
ticket: ticket,
expiresAt: time.Now().Add(ticketTTL),
}
}