mirror of
https://github.com/iamxvbaba/gramsrv.git
synced 2026-11-21 06:56:47 +03:00
1b03be66ee
Closes the two single-node/TON gaps in the bot widget query path. - store: WidgetQueryStore (BotWidgetQueryPending/AnswerPush) mirroring BotCallbackRegistryStore, with a Redis implementation (redisstore.NewWidgetQueryStore: CAS put/resolve, pending delete, pub/sub answer channel). - rpc: widgetRegistry now mirrors callbackRegistry - a local waiter map plus the shared CAS, registerContext/deregisterContext/resolveContext/deliver/ sharedAnswer, and Router.RunBotWidgetQueryAnswerSubscriber. The waiter polls the shared store so a getBotWidgetQueryAnswer and the bot's setBotWidgetQueryAnswer may land on different nodes. Without a shared store it stays process-local. - deps/main: Deps.WidgetQueries, wired to the Redis store and the subscriber goroutine. - updateBotWidgetQuery now carries the querying user's wallet_card (address/balance) from WalletService.State when a wallet is bound. Tests: registry owner/deregister tests against the new API; build, rpc, redisstore and vet pass.
37 lines
1.3 KiB
Go
37 lines
1.3 KiB
Go
package store
|
|
|
|
import (
|
|
"context"
|
|
"time"
|
|
|
|
"telesrv/internal/domain"
|
|
)
|
|
|
|
// BotWidgetQueryPending is the short-lived, protocol-neutral ownership record
|
|
// for one messages.getBotWidgetQueryAnswer request. It is deliberately
|
|
// ephemeral: it only coordinates the synchronous client answer across server
|
|
// instances, mirroring BotCallbackPending.
|
|
type BotWidgetQueryPending struct {
|
|
QueryID int64
|
|
BotUserID int64
|
|
UserID int64
|
|
CreatedAt time.Time
|
|
}
|
|
|
|
type BotWidgetQueryAnswerPush struct {
|
|
QueryID int64
|
|
BotUserID int64
|
|
Answer domain.BotWidgetQueryAnswer
|
|
}
|
|
|
|
// WidgetQueryStore coordinates bot web-widget query waiters across processes.
|
|
// Implementations must make Put and Resolve atomic: query ids cannot be
|
|
// overwritten and at most one answer may win for the owning bot.
|
|
type WidgetQueryStore interface {
|
|
PutBotWidgetQueryPending(ctx context.Context, pending BotWidgetQueryPending, ttl time.Duration) (bool, error)
|
|
ResolveBotWidgetQuery(ctx context.Context, botUserID, queryID int64, answer domain.BotWidgetQueryAnswer) (bool, error)
|
|
GetBotWidgetQueryAnswer(ctx context.Context, botUserID, queryID int64) (domain.BotWidgetQueryAnswer, bool, error)
|
|
DeleteBotWidgetQueryPending(ctx context.Context, botUserID, queryID int64) error
|
|
SubscribeBotWidgetQueryAnswers(ctx context.Context, handle func(context.Context, BotWidgetQueryAnswerPush)) error
|
|
}
|