Documentation
¶
Index ¶
- Variables
- func CleanupOldRecords(retentionHours int) error
- func EnqueueNotification(recipientUserID, conversationID int) error
- func GetUnreadMessageCount(userID int) (int, error)
- func Init() error
- func IsBlockedError(err error) bool
- func IsOptedOut(phoneNumber string) bool
- func MarkProcessed(id int) error
- func MarkSuppressed(id int) error
- func SendMessage(phoneE64, message string) error
- func SetMessageStatus(messageSid string, status SMSStatus)
- func ShouldSuppressSMS(recipientUserID int) (bool, error)
- func StartSMSWorker()
- func UpdateLastSMSSent(userID int) error
- func UpdatePhoneNumberWebhook() error
- func VerifyTwilioSignature(c *fiber.Ctx) bool
- type MessageTracker
- type Notification
- type QueueEntry
- type QueueStats
- type SMSStatus
- type SMSWebhookData
Constants ¶
This section is empty.
Variables ¶
var ErrBlockedNumber = fmt.Errorf("phone number blocked")
ErrBlockedNumber indicates the phone number is blocked/opted out at Twilio
Functions ¶
func CleanupOldRecords ¶
CleanupOldRecords deletes processed/suppressed records older than retention period
func EnqueueNotification ¶
EnqueueNotification adds a notification to the queue
func GetUnreadMessageCount ¶
GetUnreadMessageCount returns the count of unread messages across all conversations
func Init ¶
func Init() error
Init validates Twilio configuration and initializes SMS service Validates format and completeness of Twilio environment variables This should be called at application startup Returns an error if configuration is invalid, nil if SMS is ready or disabled
func IsBlockedError ¶
IsBlockedError checks if an error indicates the phone number is blocked/opted out
func IsOptedOut ¶
IsOptedOut checks if a phone number's user has opted out
func MarkProcessed ¶
MarkProcessed marks a notification as processed
func MarkSuppressed ¶
MarkSuppressed marks a notification as suppressed
func SendMessage ¶
SendMessage sends an SMS message and tracks delivery
func SetMessageStatus ¶
SetMessageStatus sets the status of a message
func ShouldSuppressSMS ¶
ShouldSuppressSMS checks if SMS should be suppressed for a recipient Returns true if: - Recipient account is deleted - Last SMS was sent within the suppression window (10 minutes) - User has read all conversations (no unread messages)
func StartSMSWorker ¶
func StartSMSWorker()
StartSMSWorker starts the background worker that processes SMS notifications
func UpdateLastSMSSent ¶
UpdateLastSMSSent updates the last_sms_sent_at timestamp for a user
func UpdatePhoneNumberWebhook ¶
func UpdatePhoneNumberWebhook() error
UpdatePhoneNumberWebhook updates the Twilio phone number's incoming message webhook URL This should be called at startup to automatically configure the webhook based on PUBLIC_SITE_URL Only called from Init() after validation passes, so no need for defensive checks
func VerifyTwilioSignature ¶
VerifyTwilioSignature verifies that the webhook request is authentic from Twilio using the official Twilio SDK's RequestValidator
Types ¶
type MessageTracker ¶
MessageTracker tracks the status and metadata of an SMS message
type Notification ¶
type Notification struct {
ID int
RecipientUserID int
ConversationID int
CreatedAt time.Time
ProcessedAt *time.Time
Status string
}
Notification represents a queued SMS notification
func DequeuePendingNotifications ¶
func DequeuePendingNotifications(limit int) ([]Notification, error)
DequeuePendingNotifications retrieves pending notifications
type QueueEntry ¶
type QueueEntry struct {
ID int
RecipientUserID int
ConversationID int
AdTitle string
Status string
CreatedAt time.Time
ProcessedAt *time.Time
}
QueueEntry represents a queue entry for admin display
func GetQueueEntries ¶
func GetQueueEntries(status string, limit, offset int) ([]QueueEntry, error)
GetQueueEntries retrieves queue entries for admin display
type QueueStats ¶
QueueStats represents queue statistics
func GetQueueStats ¶
func GetQueueStats() (QueueStats, error)
GetQueueStats returns queue statistics
type SMSWebhookData ¶
type SMSWebhookData struct {
MessageSid string `form:"MessageSid"`
MessageStatus string `form:"MessageStatus"`
To string `form:"To"`
From string `form:"From"`
Body string `form:"Body"`
ErrorCode string `form:"ErrorCode"`
ErrorMessage string `form:"ErrorMessage"`
}
SMSWebhookData represents the data sent by Twilio webhooks
func ParseWebhook ¶
func ParseWebhook(c *fiber.Ctx) (*SMSWebhookData, error)
ParseWebhook parses webhook data from Fiber context