Documentation
¶
Index ¶
- Constants
- func AllUsers() ([]string, error)
- func CheckChurrosDatabaseHealth() error
- func CheckFirebaseHealth() error
- func CheckNATSHealth() error
- func CheckRedisHealth() error
- func ClearInMemorySchedule()
- func ClearSavedSchedule()
- func ConnectToDababase() error
- func DisplaySchedule()
- func NatsReceiver(m jetstream.Msg) error
- func Receivers(message Message) ([]string, error)
- func RestoreSchedule(eager bool) error
- func SaveSchedule()
- func StartHealthCheckEndpoint(port int)
- func StartScheduler()
- func UnscheduleAllForObject(objectId string, ofType ...Event)
- type ChurrosId
- type Configuration
- type Event
- type HealthResponse
- type Message
- func (msg Message) Channel() db.NotificationChannel
- func (msg Message) CreateInDatabaseNotifications(groupId string, subs []Subscription)
- func (msg Message) FirebaseMessage(groupId string) messaging.MulticastMessage
- func (msg Message) Group() (string, error)
- func (job Message) IsScheduled() bool
- func (msg Message) JSONBytes() []byte
- func (msg Message) JSONString() string
- func (msg Message) Run() error
- func (job Message) Schedule()
- func (msg Message) SendToFirebase(groupId string, subs []Subscription) error
- func (msg Message) SendWebPush(groupId string, subs []Subscription) error
- func (msg Message) ShouldRun() bool
- func (msg Message) ShouldSendTo() (subs []Subscription, userIds []string, err error)
- func (msg Message) String() string
- func (job Message) Unschedule()
- func (msg Message) WebPush(groupId string) WebPushNotification
- type Schedule
- type Subscription
- type SubscriptionOwner
- type WebPushNotification
Constants ¶
const ConsumerName = "NotellaConsumer"
const MaxTokensPerRequest = 490
const StreamName = "notella:stream"
const SubjectName = "notella:notification"
Variables ¶
This section is empty.
Functions ¶
func AllUsers ¶ added in v0.2.0
AllUsers returns all the users in the database that have at least one notification subscription
func ClearInMemorySchedule ¶ added in v0.7.0
func ClearInMemorySchedule()
func ClearSavedSchedule ¶ added in v0.7.0
func ClearSavedSchedule()
func DisplaySchedule ¶ added in v0.7.0
func DisplaySchedule()
func Receivers ¶ added in v0.2.0
Receivers determines which users to send the notification to
func RestoreSchedule ¶ added in v0.7.0
RestoreSchedule restores the scheduled messages from Redis to memory
func SaveSchedule ¶ added in v0.7.0
func SaveSchedule()
SaveSchedule saves the in-memory scheduled messages to Redis
func StartScheduler ¶
func StartScheduler()
StartScheduler starts the scheduler loop, which runs forever TODO instead of having a in-memory scheduler, use jetstream: 1. Get the message 2. job.ShouldRun? if yes, run it 3. otherwise, put it back at then end of the stream this means that we'll have to do a lot of json marshalling/unmarshalling though, since we'll have to decode the message to check if we need to run it... is there a better way?
Types ¶
type ChurrosId ¶
type Configuration ¶ added in v0.2.0
type Configuration struct { ChurrosDatabaseURL string `env:"DATABASE_URL"` RedisURL string `env:"REDIS_URL"` NatsURL string `env:"NATS_URL" envDefault:"nats://localhost:4222"` VapidPublicKey string `env:"PUBLIC_VAPID_KEY"` VapidPrivateKey string `env:"VAPID_PRIVATE_KEY"` ContactEmail string `env:"CONTACT_EMAIL"` FirebaseServiceAccount string `env:"FIREBASE_SERVICE_ACCOUNT"` StartupScheduleRestoration string `env:"STARTUP_SCHEDULE_RESTORATION" envDefault:"enabled"` AppPackageId string `env:"APP_PACKAGE_ID" envDefault:"app.churros"` HealthCheckPort int `env:"HEALTH_CHECK_PORT" envDefault:"8080"` DryRunMode bool `env:"DRY_RUN" envDefault:"false"` DryRunExceptions []string `env:"DRY_RUN_EXCEPTIONS"` }
func LoadConfiguration ¶ added in v0.2.0
func LoadConfiguration() (Configuration, error)
func (Configuration) HasValidFirebaseServiceAccount ¶ added in v0.2.0
func (config Configuration) HasValidFirebaseServiceAccount() bool
type Event ¶
type Event string
const ( EventClearStoredSchedule Event = "clear_stored_schedule" EventShowScheduledJobs Event = "show_scheduled_jobs" EventSaveSchedule Event = "save_schedule" EventRestoreSchedule Event = "restore_schedule" // Like restore_schedule, but also re-schedules events that have send_at in the past EventRestoreScheduleEager Event = "restore_schedule_eager" EventClearSchedule Event = "clear_schedule" EventNewPost Event = "new_post" EventGodchildRequest Event = "godchild_request" EventCustom Event = "custom" EventTest Event = "test" EventGodchildAccepted Event = "godchild_accepted" EventGodchildRejected Event = "godchild_rejected" EventPendingSignup Event = "pending_signup" EventLoginStuck Event = "login_stuck" EventBookingPaid Event = "booking_paid" EventContributionPaid Event = "contribution_paid" EventShotgunOpensSoon Event = "shotgun_opens_soon" EventShotgunClosesSoon Event = "shotgun_closes_soon" )
type HealthResponse ¶ added in v0.8.0
type HealthResponse struct { Redis bool `json:"redis"` NATS bool `json:"nats"` ChurrosDatabase bool `json:"churros_db"` Firebase bool `json:"firebase"` }
func CheckHealth ¶ added in v0.15.3
func CheckHealth() HealthResponse
func (HealthResponse) AllGood ¶ added in v0.15.3
func (r HealthResponse) AllGood() bool
type Message ¶ added in v0.2.0
type Message struct { // Unique ID for the notification scheduling request. Id string `json:"id"` // When to push the notification SendAt time.Time `json:"send_at"` // Clear scheduled jobs for the given event types on the object_id before scheduling notifications // TODO: generate jsonschema annotation ClearScheduleFor []Event `json:"clear_schedule_for"` // Type of event that triggered the notification // next-line-generate event-enum-jsonschema-values Event Event `` /* 397-byte string literal not displayed */ // Churros ID of the ressource (the ticket, the post, the comment, etc) // Used to determine to whom the notification should be sent // For godchild_request, this is not a user id, but a godparent request id. ChurrosObjectId string `json:"object_id"` // Notification title Title string `json:"title"` // Notification body Body string `json:"body"` // URL to go to when the notification is clicked Action string `json:"action"` // Additional action buttons Actions []struct { // Label of the action button Label string `json:"label"` // URL to go to when the action button is clicked Action string `json:"action"` } `json:"actions,omitempty"` // URL to an image to display in the notification Image string `json:"image,omitempty"` }
func (Message) Channel ¶ added in v0.2.0
func (msg Message) Channel() db.NotificationChannel
func (Message) CreateInDatabaseNotifications ¶ added in v0.7.0
func (msg Message) CreateInDatabaseNotifications(groupId string, subs []Subscription)
func (Message) FirebaseMessage ¶ added in v0.2.0
func (msg Message) FirebaseMessage(groupId string) messaging.MulticastMessage
func (Message) Group ¶ added in v0.2.0
Group returns the Churros group ID responsible for the notification
func (Message) SendToFirebase ¶ added in v0.2.0
func (msg Message) SendToFirebase(groupId string, subs []Subscription) error
func (Message) SendWebPush ¶ added in v0.2.0
func (msg Message) SendWebPush(groupId string, subs []Subscription) error
func (Message) ShouldSendTo ¶ added in v0.10.6
func (msg Message) ShouldSendTo() (subs []Subscription, userIds []string, err error)
func (Message) WebPush ¶ added in v0.2.0
func (msg Message) WebPush(groupId string) WebPushNotification
type Schedule ¶ added in v0.7.0
type Schedule struct { cmap.ConcurrentMap[string, Message] }
type Subscription ¶
type Subscription struct { Webpush webpush.Subscription `json:"webpush"` Owner SubscriptionOwner `json:"owner"` }
func FindSubscriptionByNativeToken ¶ added in v0.7.0
func FindSubscriptionByNativeToken(token string, subs []Subscription) (Subscription, bool)
func SubscriptionFromDatabase ¶ added in v0.10.6
func SubscriptionFromDatabase(sub db.NotificationSubscriptionModel) Subscription
func (Subscription) Destroy ¶ added in v0.7.0
func (sub Subscription) Destroy() error
func (Subscription) FirebaseToken ¶ added in v0.2.0
func (sub Subscription) FirebaseToken() string
func (Subscription) IsNative ¶ added in v0.2.0
func (sub Subscription) IsNative() bool
func (Subscription) IsWebpush ¶ added in v0.2.0
func (sub Subscription) IsWebpush() bool
type SubscriptionOwner ¶
type WebPushNotification ¶ added in v0.2.0
type WebPushNotification struct { Title string `json:"title"` Actions []webpushAction `json:"actions"` Badge string `json:"badge"` Icon string `json:"icon"` Image string `json:"image"` Body string `json:"body"` Renotify bool `json:"renotify"` RequireInteraction bool `json:"requireInteraction"` Silent bool `json:"silent"` Tag string `json:"tag"` Timestamp int64 `json:"timestamp"` Vibrate []int `json:"vibrate"` Data webpushNotificationData `json:"data"` }