notella

package module
v0.17.0 Latest Latest
Warning

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

Go to latest
Published: Feb 19, 2025 License: AGPL-3.0 Imports: 25 Imported by: 0

README

churros/notella

Notification queue server for Churros.

Installation

# generate prisma client
just genprisma
# start
just

Documentation

Index

Constants

View Source
const ConsumerName = "NotellaConsumer"
View Source
const MaxTokensPerRequest = 490
View Source
const StreamName = "notella:stream"
View Source
const SubjectName = "notella:notification"

Variables

This section is empty.

Functions

func AllUsers added in v0.2.0

func AllUsers() ([]string, error)

AllUsers returns all the users in the database that have at least one notification subscription

func CheckChurrosDatabaseHealth added in v0.8.0

func CheckChurrosDatabaseHealth() error

func CheckFirebaseHealth added in v0.8.0

func CheckFirebaseHealth() error

func CheckNATSHealth added in v0.8.0

func CheckNATSHealth() error

func CheckRedisHealth added in v0.8.0

func CheckRedisHealth() error

func ClearInMemorySchedule added in v0.7.0

func ClearInMemorySchedule()

func ClearSavedSchedule added in v0.7.0

func ClearSavedSchedule()

func ConnectToDababase added in v0.2.0

func ConnectToDababase() error

func DisplaySchedule added in v0.7.0

func DisplaySchedule()

func NatsReceiver added in v0.2.0

func NatsReceiver(m jetstream.Msg) error

func Receivers added in v0.2.0

func Receivers(message Message) ([]string, error)

Receivers determines which users to send the notification to

func RestoreSchedule added in v0.7.0

func RestoreSchedule(eager bool) error

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 StartHealthCheckEndpoint added in v0.8.0

func StartHealthCheckEndpoint(port int)

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?

func UnscheduleAllForObject added in v0.5.0

func UnscheduleAllForObject(objectId string, ofType ...Event)

UnscheduleAllForObject unschedules all jobs for a given object ID. If any ofType is provided, only events of the types given will be unscheduled

Types

type ChurrosId

type ChurrosId struct {
	Type    string
	LocalID string
}

func ParseChurrosId

func ParseChurrosId(churrosId string) (ChurrosId, error)

func (ChurrosId) String

func (id ChurrosId) String() string

func (*ChurrosId) UnmarshalText

func (id *ChurrosId) UnmarshalText(text []byte) error

UnmarshalText implements the encoding.TextUnmarshaler interface for 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

func (msg Message) Group() (string, error)

Group returns the Churros group ID responsible for the notification

func (Message) IsScheduled added in v0.2.0

func (job Message) IsScheduled() bool

func (Message) JSONBytes added in v0.6.0

func (msg Message) JSONBytes() []byte

func (Message) JSONString added in v0.2.0

func (msg Message) JSONString() string

func (Message) Run added in v0.2.0

func (msg Message) Run() error

func (Message) Schedule added in v0.2.0

func (job Message) Schedule()

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) ShouldRun added in v0.2.0

func (msg Message) ShouldRun() bool

func (Message) ShouldSendTo added in v0.10.6

func (msg Message) ShouldSendTo() (subs []Subscription, userIds []string, err error)

func (Message) String added in v0.17.0

func (msg Message) String() string

func (Message) Unschedule added in v0.2.0

func (job Message) Unschedule()

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 SubscriptionOwner struct {
	Id        string `json:"id"`
	Uid       string `json:"uid"`
	FirstName string `json:"firstName"`
	LastName  string `json:"lastName"`
}

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"`
}

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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