Documentation
¶
Overview ¶
Package notification is the facade of the notification module's Telegram bot: update handling (webhook and polling), the administrators' group and its topics, user and administrator notices, the webhook secret and the message templates other domains render. The module's email and SMS delivery is not behind this facade: providers live in internal/infra/mail and internal/infra/sms, and the queue task handlers in internal/transport/task/email and internal/transport/task/sms send through them.
Index ¶
- Constants
- func NewRepoBuilder() repository.NotificationBuilder
- func RenderTelegramMarkdown(tpl string, data map[string]string) (string, error)
- func WebhookSecret(botToken string) string
- func WebhookSecretEqual(presented, expected string) bool
- type Accounts
- type AuditLogs
- type Billing
- type Deps
- type Service
- type Subscriptions
- type Tickets
Constants ¶
const ( PurchaseNotify = telegram.PurchaseNotify RenewalNotify = telegram.RenewalNotify ResetTrafficNotify = telegram.ResetTrafficNotify RechargeNotify = telegram.RechargeNotify AdminOrderNotify = telegram.AdminOrderNotify AdminOrderDaily = telegram.AdminOrderDaily SubscribeExpireNotify = telegram.SubscribeExpireNotify )
Message templates other domains render before handing the text to the bot.
Variables ¶
This section is empty.
Functions ¶
func NewRepoBuilder ¶ added in v1.15.18
func NewRepoBuilder() repository.NotificationBuilder
NewRepoBuilder exports the module-owned repository implementations for store assembly (ADR-001 step-6 preparation).
func RenderTelegramMarkdown ¶ added in v1.15.18
RenderTelegramMarkdown renders one of the message templates below as MarkdownV2, escaping every data value. It is the only supported way to build the text for NotifyTelegramUser and the queue's bot sends: one unescaped '.' or '-' in an order number makes Telegram reject the whole message.
func WebhookSecret ¶ added in v1.20.2
WebhookSecret computes the webhook secret token for a bot token. The result is 64 hex characters, within Telegram's 1-256 length limit and its [A-Za-z0-9_-] alphabet.
func WebhookSecretEqual ¶ added in v1.20.2
WebhookSecretEqual compares a presented secret with the expected one in constant time, so the comparison leaks nothing about the expected value.
Types ¶
type Accounts ¶ added in v1.21.0
The bot's ports onto the domains it serves, declared by the bot and kept to the calls it makes; the composition root provides them.
type AuditLogs ¶ added in v1.21.0
The bot's ports onto the domains it serves, declared by the bot and kept to the calls it makes; the composition root provides them.
type Billing ¶ added in v1.21.0
The bot's ports onto the domains it serves, declared by the bot and kept to the calls it makes; the composition root provides them.
type Deps ¶
type Deps struct {
// Bot returns the current bot client; the initialize subsystem recreates
// it when the Telegram configuration changes, so it is read per call.
// nil means the bot is not configured.
Bot func() *tgbot.Bot
// GroupChatID returns the validated administrators' group chat id; zero
// means no group is available and every group feature stays off. Read
// per call for the same reason as Bot.
GroupChatID func() int64
// Topics maps forum topics in the administrators' group to the
// conversation each carries.
Topics repository.TelegramTopicRepo
Redis *redis.Client
Accounts Accounts
Tickets Tickets
Subscriptions Subscriptions
Billing Billing
AuditLogs AuditLogs
}
Deps declares everything the module needs; the composition root (internal/app) provides them.
type Service ¶
type Service interface {
// HandleTelegramUpdate processes one bot update (command dispatch,
// binding, admin actions). The polling loop calls it with the update the
// bot library already decoded.
HandleTelegramUpdate(ctx context.Context, update *models.Update)
// HandleTelegramWebhook decodes one webhook payload and processes it.
// The decode lives behind this facade so the bot library's update type
// never crosses into the HTTP layer.
HandleTelegramWebhook(ctx context.Context, payload []byte) error
// NotifyTelegramUnbind sends the best-effort unbind notice to the chat.
NotifyTelegramUnbind(ctx context.Context, userID, chatID int64) error
// NotifyTelegramUser sends already-rendered MarkdownV2 text to the
// user's bound Telegram chat; render it with RenderTelegramMarkdown so
// the data is escaped. It reports an error when the user has no binding
// or the bot is unconfigured, which callers treat as "nothing to
// deliver".
NotifyTelegramUser(ctx context.Context, userID int64, text string) error
// PublishTelegramCommands registers the command menu every user sees.
// The bot initialiser calls it once the client is ready, so the composer
// offers the commands instead of leaving users to guess them.
PublishTelegramCommands(ctx context.Context) error
// SetupTelegramGroup validates the configured administrators' group
// (forum supergroup, bot manages topics), prepares the notification
// topic and publishes the group-scoped administrator menu. A zero group
// id is a no-op; the caller disables group features when this errors.
SetupTelegramGroup(ctx context.Context) error
// NotifyAdminsTelegram posts already-rendered MarkdownV2 text (use
// RenderTelegramMarkdown) into the administrators' notification topic.
// It reports an error when the group is unavailable, which callers
// treat as "nothing to deliver".
NotifyAdminsTelegram(ctx context.Context, text string) error
// NotifyTicketCreated opens a forum topic for a new website ticket.
NotifyTicketCreated(ctx context.Context, t *ticket.Ticket) error
// NotifyTicketReplied posts a website-side ticket reply into the
// ticket's topic; tickets without a topic are skipped silently.
NotifyTicketReplied(ctx context.Context, ticketID int64, from, content string) error
// NotifyTicketStatusChanged mirrors a website-side status change onto
// the ticket's topic (close/reopen).
NotifyTicketStatusChanged(ctx context.Context, ticketID int64, status uint8) error
}
Service is the only surface other code may depend on; the implementation lives under internal/ where the compiler seals it off.
type Subscriptions ¶ added in v1.21.0
type Subscriptions = telegram.Subscriptions
The bot's ports onto the domains it serves, declared by the bot and kept to the calls it makes; the composition root provides them.
Directories
¶
| Path | Synopsis |
|---|---|
|
entity
|
|
|
telegramtopic
Package telegramtopic maps forum topics in the administrators' Telegram group to what they carry.
|
Package telegramtopic maps forum topics in the administrators' Telegram group to what they carry. |
|
internal
|
|
|
repo
Package repo holds the notification module's repository implementation: the mapping of forum topics in the administrators' Telegram group.
|
Package repo holds the notification module's repository implementation: the mapping of forum topics in the administrators' Telegram group. |
|
telegram
Package telegram implements the notification module's Telegram bot: the routing of updates, account binding and the traffic report in private chats, the administrator commands and the support and ticket topics of the administrators' group, and the MarkdownV2 message templates.
|
Package telegram implements the notification module's Telegram bot: the routing of updates, account binding and the traffic report in private chats, the administrator commands and the support and ticket topics of the administrators' group, and the MarkdownV2 message templates. |
|
transport
|
|
|
http
Package handler holds the Hertz handler of the Telegram bot webhook.
|
Package handler holds the Hertz handler of the Telegram bot webhook. |