sms

package
v0.0.13 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Oct 27, 2026 License: MIT Imports: 17 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrBlockedNumber = fmt.Errorf("phone number blocked")

ErrBlockedNumber indicates the phone number is blocked/opted out at Twilio

Functions

func CleanupOldRecords

func CleanupOldRecords(retentionHours int) error

CleanupOldRecords deletes processed/suppressed records older than retention period

func EnqueueNotification

func EnqueueNotification(recipientUserID, conversationID int) error

EnqueueNotification adds a notification to the queue

func GetUnreadMessageCount

func GetUnreadMessageCount(userID int) (int, error)

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

func IsBlockedError(err error) bool

IsBlockedError checks if an error indicates the phone number is blocked/opted out

func IsOptedOut

func IsOptedOut(phoneNumber string) bool

IsOptedOut checks if a phone number's user has opted out

func MarkProcessed

func MarkProcessed(id int) error

MarkProcessed marks a notification as processed

func MarkSuppressed

func MarkSuppressed(id int) error

MarkSuppressed marks a notification as suppressed

func SendMessage

func SendMessage(phoneE64, message string) error

SendMessage sends an SMS message and tracks delivery

func SetMessageStatus

func SetMessageStatus(messageSid string, status SMSStatus)

SetMessageStatus sets the status of a message

func ShouldSuppressSMS

func ShouldSuppressSMS(recipientUserID int) (bool, error)

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

func UpdateLastSMSSent(userID int) error

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

func VerifyTwilioSignature(c *fiber.Ctx) bool

VerifyTwilioSignature verifies that the webhook request is authentic from Twilio using the official Twilio SDK's RequestValidator

Types

type MessageTracker

type MessageTracker struct {
	Status      SMSStatus
	SentTime    time.Time
	PhoneNumber string
}

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

type QueueStats struct {
	Pending    int
	Processed  int
	Suppressed int
}

QueueStats represents queue statistics

func GetQueueStats

func GetQueueStats() (QueueStats, error)

GetQueueStats returns queue statistics

type SMSStatus

type SMSStatus string

SMSStatus represents the status of an SMS message

const (
	SMSStatusDelivered   SMSStatus = "delivered"
	SMSStatusFailed      SMSStatus = "failed"
	SMSStatusUndelivered SMSStatus = "undelivered"
	SMSStatusSent        SMSStatus = "sent"
)

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

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL