mirror of
https://github.com/tiennm99/openai-status-bot.git
synced 2026-07-14 07:05:20 +00:00
546e6fcde2
Swap the Redis datastore for MongoDB via mongo-driver v2. New internal/mongostore mirrors the old redisstore type/constant names so consumers change only the import qualifier; document model collapses the multi-key subscriber/settings and per-event delivery sets into single-doc operations and a TTL-indexed delivery collection. Config now requires MONGODB_URI (Atlas) with MONGODB_DATABASE selecting dev vs prod on one cluster; REDIS_URL removed. Compose files run bot-only against Atlas. Default tests stay Docker-free (poller/bot use fakes, mongostore unit tests are pure-logic); a gated //go:build integration suite covers the real backend via testcontainers.
46 lines
1.4 KiB
Go
46 lines
1.4 KiB
Go
package bot
|
|
|
|
import (
|
|
"fmt"
|
|
"strconv"
|
|
"strings"
|
|
|
|
"github.com/tiennm99/openai-status-bot/internal/mongostore"
|
|
)
|
|
|
|
func formatInfo(sub mongostore.Subscriber, subscribed bool) string {
|
|
chatID := strconv.FormatInt(sub.ChatID, 10)
|
|
if sub.ThreadID != nil {
|
|
chatID = fmt.Sprintf("%s:%d", chatID, *sub.ThreadID)
|
|
}
|
|
if !subscribed {
|
|
return fmt.Sprintf("<b>Chat Info</b>\n\nChat ID: <code>%s</code>\n\nNot subscribed. Use /start to subscribe.", escape(chatID))
|
|
}
|
|
components := "all"
|
|
if len(sub.Components) > 0 {
|
|
components = strings.Join(sub.Components, ", ")
|
|
}
|
|
return fmt.Sprintf(
|
|
"<b>Chat Info</b>\n\nChat ID: <code>%s</code>\n\nTypes: <code>%s</code>\nComponents: <code>%s</code>",
|
|
escape(chatID),
|
|
escape(strings.Join(sub.Types, ", ")),
|
|
escape(components),
|
|
)
|
|
}
|
|
|
|
func formatSubscribeUsage(sub mongostore.Subscriber, subscribed bool) string {
|
|
current := "none (use /start first)"
|
|
components := "all"
|
|
if subscribed {
|
|
current = strings.Join(sub.Types, ", ")
|
|
if len(sub.Components) > 0 {
|
|
components = strings.Join(sub.Components, ", ")
|
|
}
|
|
}
|
|
return fmt.Sprintf(
|
|
"<b>Usage:</b> /subscribe <type> [component]\n\nTypes: <code>incident</code>, <code>component</code>, <code>all</code>\nComponent filter: <code>/subscribe component api</code>\nClear filter: <code>/subscribe component all</code>\n\nCurrent types: <code>%s</code>\nComponents: <code>%s</code>",
|
|
escape(current),
|
|
escape(components),
|
|
)
|
|
}
|