2026-04-01 07:23:36 +00:00
|
|
|
package bus
|
|
|
|
|
|
|
|
|
|
import "strings"
|
|
|
|
|
|
2026-04-01 12:56:48 +00:00
|
|
|
// NewOutboundContext builds the minimal normalized addressing context required
|
|
|
|
|
// to deliver an outbound text message or reply.
|
|
|
|
|
func NewOutboundContext(channel, chatID, replyToMessageID string) InboundContext {
|
2026-04-01 07:23:36 +00:00
|
|
|
return normalizeInboundContext(InboundContext{
|
2026-04-01 12:56:48 +00:00
|
|
|
Channel: strings.TrimSpace(channel),
|
|
|
|
|
ChatID: strings.TrimSpace(chatID),
|
|
|
|
|
ReplyToMessageID: strings.TrimSpace(replyToMessageID),
|
2026-04-01 07:23:36 +00:00
|
|
|
})
|
|
|
|
|
}
|
|
|
|
|
|
2026-04-01 12:56:48 +00:00
|
|
|
// NormalizeOutboundMessage ensures Context is normalized and keeps convenience
|
|
|
|
|
// mirrors in sync for runtime consumers.
|
2026-04-01 07:23:36 +00:00
|
|
|
func NormalizeOutboundMessage(msg OutboundMessage) OutboundMessage {
|
2026-04-01 12:56:48 +00:00
|
|
|
msg.Context = normalizeInboundContext(msg.Context)
|
|
|
|
|
msg.Channel = msg.Context.Channel
|
|
|
|
|
msg.ChatID = msg.Context.ChatID
|
|
|
|
|
if msg.Context.ReplyToMessageID == "" {
|
|
|
|
|
msg.Context.ReplyToMessageID = strings.TrimSpace(msg.ReplyToMessageID)
|
2026-04-01 07:23:36 +00:00
|
|
|
}
|
2026-04-01 12:56:48 +00:00
|
|
|
msg.ReplyToMessageID = msg.Context.ReplyToMessageID
|
2026-04-01 07:23:36 +00:00
|
|
|
return msg
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// NormalizeOutboundMediaMessage ensures media outbound messages also carry a
|
2026-04-01 12:56:48 +00:00
|
|
|
// normalized context while keeping convenience mirrors in sync.
|
2026-04-01 07:23:36 +00:00
|
|
|
func NormalizeOutboundMediaMessage(msg OutboundMediaMessage) OutboundMediaMessage {
|
2026-04-01 12:56:48 +00:00
|
|
|
msg.Context = normalizeInboundContext(msg.Context)
|
|
|
|
|
msg.Channel = msg.Context.Channel
|
|
|
|
|
msg.ChatID = msg.Context.ChatID
|
2026-04-01 07:23:36 +00:00
|
|
|
return msg
|
|
|
|
|
}
|