go_notifier_core

package module
v1.0.3 Latest Latest
Warning

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

Go to latest
Published: Jul 26, 2023 License: MIT Imports: 12 Imported by: 0

README

Go Notifier Core

This is a sdk for handling notification and emails.
This package is taken idea from sendportal.io.

Installation

Use this command to get package :

go get github.com/milito-78/go-notifier-core
Examples

You can check examples folder. There are examples about how migrations, seeder, handler and workers run.

Documentation

Index

Constants

View Source
const (
	MysqlDriver    = iota + 1 // Constant representing the MySQL database driver.
	PostgresDriver            // Constant representing the PostgresSQL database driver.
)
View Source
const (
	NotifierEmailServiceSES = iota + 1
	NotifierEmailServiceSendGrid
	NotifierEmailServiceMailgun
	NotifierEmailServicePostmark
	NotifierEmailServiceMailjet
	NotifierEmailServicePostal
	NotifierEmailServiceSMTP

	NotifierEmailServiceSESType      = "SES"
	NotifierEmailServiceSendGridType = "SendGrid"
	NotifierEmailServiceMailgunType  = "MailGun"
	NotifierEmailServicePostmarkType = "Postmark"
	NotifierEmailServiceMailjetType  = "Mailjet"
	NotifierEmailServicePostalType   = "Postal"
	NotifierEmailServiceSMTPType     = "SMPT"
)
View Source
const (
	NotifierEmailStatusDraft = iota + 1
	NotifierEmailStatusQueued
	NotifierEmailStatusSending
	NotifierEmailStatusSent
	NotifierEmailStatusCanceled
	NotifierEmailStatusFailed
)
View Source
const (
	NotifierEmailUnsubBounce = iota + 1
	NotifierEmailUnsubComplaint
	NotifierEmailUnsubManualByAdmin
	NotifierEmailUnsubManualBySubscriber
)

Email Subscriber models

View Source
const (
	NotifierMobileServiceKavehNegarType = "KavehNegar" //Iranian provider
)
View Source
const (
	NotifierNotificationServiceFirebaseType = "Firebase"
)

Variables

This section is empty.

Functions

func AssignTagsToEmail

func AssignTagsToEmail(email string, tags []string, createTag bool) error

func AssignTagsToMobile

func AssignTagsToMobile(mobile string, tags []string, createTag bool) error

func AssignTagsToToken

func AssignTagsToToken(token string, tags []string, createTag bool) error

func CheckEmailMessageExists

func CheckEmailMessageExists(message *NotifierEmailMessage) error

func CreateEmailMessage

func CreateEmailMessage(message *NotifierEmailMessage) error

func DeleteEmailCampaign

func DeleteEmailCampaign(campaign uint64) error

func DeleteEmailTemplate

func DeleteEmailTemplate(id uint64) error

func DeleteTagByName

func DeleteTagByName(name string) error

func DetachTagsForCampaign

func DetachTagsForCampaign(campaign uint64) error

func Initialize

func Initialize(config DbConfig)

func Migrate

func Migrate(config DbConfig)

func MigrateRollback

func MigrateRollback(config DbConfig)

func RemoveTagsFromEmail

func RemoveTagsFromEmail(email string, tags []string) error

func RemoveTagsFromMobile

func RemoveTagsFromMobile(mobile string, tags []string) error

func RemoveTagsFromToken

func RemoveTagsFromToken(token string, tags []string) error

func RemoveToken

func RemoveToken(token string) error

func Seed

func Seed() error

func UnSubscribeEmail

func UnSubscribeEmail(email string, unsubId uint64) error

func UnSubscribeMobile

func UnSubscribeMobile(mobile string, unsubId uint64) error

func UpdateEmailCampaign

func UpdateEmailCampaign(campaign *NotifierEmailCampaign) error

func UpdateEmailCampaignWithId

func UpdateEmailCampaignWithId(cmpId uint64, data *EmailCampaignUpdateData) error

func UpdateEmailMessage

func UpdateEmailMessage(message *NotifierEmailMessage) error

func WorkerStart

func WorkerStart(config WorkersList)

WorkerStart starts cronjob workers

Types

type DbConfig

type DbConfig struct {
	Username string
	Password string
	Driver   int
	Host     string
	Port     string
	Name     string
	DB       string
}

type EmailCampaignCreateData

type EmailCampaignCreateData struct {
	EmailServiceId uint64
	ScheduledAt    *time.Time
	TemplateId     uint64
	StatusId       uint64
	FromEmail      string
	FromName       string
	Subject        string
	Name           string
	Tags           []uint64
}

type EmailCampaignUpdateData

type EmailCampaignUpdateData struct {
	EmailServiceId uint64
	ScheduledAt    *time.Time
	TemplateId     uint64
	StatusId       uint64
	FromEmail      string
	FromName       string
	Subject        string
	Name           string
	Tags           []uint64
}

type EmailWorker

type EmailWorker struct {
}

func (EmailWorker) Run

func (e EmailWorker) Run()

type IEmailCampaignRepository

type IEmailCampaignRepository interface {
	IRepository[NotifierEmailCampaign]
	AssignTagsToCampaign(cmpId uint64, tagsId []uint64) error
	DeleteAllTagsForCampaign(cmpId uint64) error
	GetLatestCampaign() (*NotifierEmailCampaign, error)
	GetCampaignTags(cmpId uint64) []NotifierTag
}

func NewGormEmailCampaignRepository

func NewGormEmailCampaignRepository(db *gorm.DB) IEmailCampaignRepository

type IEmailMessageRepository

type IEmailMessageRepository interface {
	IRepository[NotifierEmailMessage]
	CheckMessageExists(message *NotifierEmailMessage) error
}

func NewGormEmailMessageRepository

func NewGormEmailMessageRepository(db *gorm.DB) IEmailMessageRepository

type IEmailServiceRepository

type IEmailServiceRepository interface {
	IRepository[NotifierEmailService]
}

func NewGormEmailServiceRepository

func NewGormEmailServiceRepository(db *gorm.DB) IEmailServiceRepository

type IEmailStatusRepository

type IEmailStatusRepository interface {
	IRepository[NotifierEmailCampaignStatus]
	FirstOrCreate(status *NotifierEmailCampaignStatus) error
}

func NewGormEmailStatusRepository

func NewGormEmailStatusRepository(db *gorm.DB) IEmailStatusRepository

type IEmailSubTagRepository

type IEmailSubTagRepository interface {
	IRepository[NotifierEmailSubTag]
}

func NewGormEmailSubTagRepository

func NewGormEmailSubTagRepository(db *gorm.DB) IEmailSubTagRepository

type IEmailSubscriberRepository

type IEmailSubscriberRepository interface {
	IRepository[NotifierEmailSubscriber]
	GetByEmail(email string) (*NotifierEmailSubscriber, error)
	AssignTagToUser(userId uint64, tagsId []uint64) error
	RemoveTagsFromUser(id uint64, entity []uint64) error
	GetSubscribersForTag(tagId uint64, data *[]NotifierEmailSubscriber)
	GetUnSubscribed(data *[]NotifierEmailSubscriber)
	GetUsersByTagId(tags []NotifierTag, data *[]NotifierEmailSubscriber)
	GetByEmailWithTags(email string) (*NotifierEmailSubscriber, error)
}

func NewGormEmailSubscriberRepository

func NewGormEmailSubscriberRepository(db *gorm.DB) IEmailSubscriberRepository

type IEmailTemplateRepository

type IEmailTemplateRepository interface {
	IRepository[NotifierEmailCampaignTemplate]
}

func NewGormEmailTemplateRepository

func NewGormEmailTemplateRepository(db *gorm.DB) IEmailTemplateRepository

type IEmailUnSubEventRepository

type IEmailUnSubEventRepository interface {
	IRepository[NotifierEmailUnsubscribeEvent]
	FirstOrCreate(status *NotifierEmailUnsubscribeEvent) error
}

func NewGormEmailUnSubEventRepository

func NewGormEmailUnSubEventRepository(db *gorm.DB) IEmailUnSubEventRepository

type IMobileSubTagRepository

type IMobileSubTagRepository interface {
	IRepository[NotifierMobileSubTag]
}

func NewGormMobileSubTagRepository

func NewGormMobileSubTagRepository(db *gorm.DB) IMobileSubTagRepository

type IMobileSubscriberRepository

type IMobileSubscriberRepository interface {
	IRepository[NotifierMobileSubscriber]
	GetByMobile(mobile string) (*NotifierMobileSubscriber, error)
	AssignTagToUser(userId uint64, tagsId []uint64) error
	RemoveTagsFromUser(id uint64, entity []uint64) error
	GetSubscribersForTag(tagId uint64, data []NotifierMobileSubscriber)
	GetUnSubscribed(data []NotifierMobileSubscriber)
}

func NewGormMobileSubscriberRepository

func NewGormMobileSubscriberRepository(db *gorm.DB) IMobileSubscriberRepository

type IMobileUnSubEventRepository

type IMobileUnSubEventRepository interface {
	IRepository[NotifierMobileUnsubscribeEvent]
}

func NewGormMobileUnSubEventRepository

func NewGormMobileUnSubEventRepository(db *gorm.DB) IMobileUnSubEventRepository

type INotificationSubTagRepository

type INotificationSubTagRepository interface {
	IRepository[NotifierNotificationSubTag]
}

func NewGormNotificationSubTagRepository

func NewGormNotificationSubTagRepository(db *gorm.DB) INotificationSubTagRepository

type INotificationSubscriberRepository

type INotificationSubscriberRepository interface {
	IRepository[NotifierNotificationSubscriber]
	GetByNotification(token string) (*NotifierNotificationSubscriber, error)
	AssignTagToUser(userId uint64, tagsId []uint64) error
	RemoveTagsFromUser(id uint64, entity []uint64) error
	GetSubscribersForTag(tagId uint64, data []NotifierNotificationSubscriber)
	GetSubscribersForTagAndDriver(tagId, driverId uint64, data []NotifierNotificationSubscriber)
}

func NewGormNotificationSubscriberRepository

func NewGormNotificationSubscriberRepository(db *gorm.DB) INotificationSubscriberRepository

type INotifierNotificationDriverRepository

type INotifierNotificationDriverRepository interface {
	IRepository[NotifierNotificationService]
}

func NewGormNotifierNotificationDriverRepository

func NewGormNotifierNotificationDriverRepository(db *gorm.DB) INotifierNotificationDriverRepository

type IRepository

type IRepository[Model interface{}] interface {
	Create(*Model) error
	Update(*Model) error
	Delete(*Model) error
	Get(id uint64) (*Model, error)
	All(data *[]Model)
}

type ITagRepository

type ITagRepository interface {
	IRepository[NotifierTag]
	GetByName(name string) (*NotifierTag, error)
}

func NewGormTagRepository

func NewGormTagRepository(db *gorm.DB) ITagRepository

type IWorker

type IWorker interface {
	Run()
}

IWorker used for cronjob structs

type Mailer

type Mailer interface {
	Send(fromName, fromMail, to, subject, message string) error
	SetConfig(config []byte)
}

type MobileWorker

type MobileWorker struct {
}

func (MobileWorker) Run

func (m MobileWorker) Run()

type NotFoundError

type NotFoundError struct {
}

func (NotFoundError) Error

func (n NotFoundError) Error() string

type NotificationWorker

type NotificationWorker struct {
}

func (NotificationWorker) Run

func (n NotificationWorker) Run()

type NotifierEmailCampaign

type NotifierEmailCampaign struct {
	EmailServiceId uint64
	ScheduledAt    *time.Time
	TemplateId     uint64
	UpdatedAt      time.Time
	CreatedAt      time.Time
	StatusId       uint64
	FromEmail      string
	FromName       string
	Subject        string
	Content        string `gorm:"type=longtext"`
	Name           string
	ID             uint64
}

func GetLatestCampaignForRun

func GetLatestCampaignForRun() (*NotifierEmailCampaign, error)

func NewNotifierEmailCampaign

func NewNotifierEmailCampaign(emailServiceId uint64, scheduledAt *time.Time, templateId uint64, statusId uint64, fromEmail string, fromName string, subject string, content string, name string) *NotifierEmailCampaign

type NotifierEmailCampaignStatus

type NotifierEmailCampaignStatus struct {
	Name string
	ID   uint64
}

func NewNotifierEmailStatus

func NewNotifierEmailStatus(name string, ID uint64) *NotifierEmailCampaignStatus

type NotifierEmailCampaignTag

type NotifierEmailCampaignTag struct {
	CampaignId uint64
	TagId      uint64
}

func NewNotifierEmailCampaignTag

func NewNotifierEmailCampaignTag(campaignId uint64, tagId uint64) *NotifierEmailCampaignTag

type NotifierEmailCampaignTemplate

type NotifierEmailCampaignTemplate struct {
	UpdatedAt time.Time
	CreatedAt time.Time
	Content   string `gorm:"type=longtext"`
	Name      string
	ID        uint64
}

func CreateEmailTemplate

func CreateEmailTemplate(name, content string) (*NotifierEmailCampaignTemplate, error)

func EmailTemplateList

func EmailTemplateList() ([]NotifierEmailCampaignTemplate, error)

func NewNotifierEmailCampaignTemplate

func NewNotifierEmailCampaignTemplate(content string, name string) *NotifierEmailCampaignTemplate

func UpdateEmailTemplate

func UpdateEmailTemplate(id uint64, name, content string) (*NotifierEmailCampaignTemplate, error)

type NotifierEmailMessage

type NotifierEmailMessage struct {
	RecipientEmail string
	EmailServiceId uint64
	SubscriberId   uint64
	SourceType     string
	Message        string
	CreatedAt      time.Time
	UpdatedAt      time.Time
	FromEmail      string
	SourceId       uint64
	FromName       string
	QueuedAt       *time.Time
	FailedAt       *time.Time
	Subject        string
	SentAt         *time.Time
	ID             uint64
}

func NewNotifierEmailMessage

func NewNotifierEmailMessage(recipientEmail string, subscriberId uint64, sourceType string, fromEmail string, sourceId uint64, fromName string, subject string, emailServiceId uint64, message string) *NotifierEmailMessage

type NotifierEmailService

type NotifierEmailService struct {
	Payload string `gorm:"type=longtext"`
	Type    string
	Name    string
	ID      uint64
}

func CreateEmailService

func CreateEmailService(name, serviceType string, payload []byte) (*NotifierEmailService, error)

func GetEmailServiceById

func GetEmailServiceById(service uint64) (*NotifierEmailService, error)

func GetEmailServices

func GetEmailServices() ([]NotifierEmailService, error)

func NewNotifierEmailService

func NewNotifierEmailService(payload string, Type string, name string) *NotifierEmailService

type NotifierEmailSubTag

type NotifierEmailSubTag struct {
	EmailSubscriberId uint64
	TagId             uint64
}

func NewNotifierEmailSubTag

func NewNotifierEmailSubTag(emailSubscriberId uint64, tagId uint64) *NotifierEmailSubTag

type NotifierEmailSubscriber

type NotifierEmailSubscriber struct {
	UnsubscribedEventId *uint64
	Tags                []NotifierTag `gorm:"many2many:notifier_email_sub_tags;ForeignKey:id;References:id;JoinForeignKey:EmailSubscriberId;joinReferences:TagId"`
	UnsubscribedAt      *time.Time
	CreatedAt           time.Time
	UpdatedAt           time.Time
	FirstName           string
	LastName            string
	Email               string
	ID                  uint64
}

func GetEmailSubscribersWithTags

func GetEmailSubscribersWithTags(tags []NotifierTag) ([]NotifierEmailSubscriber, error)

func GetTagEmailSubscribers

func GetTagEmailSubscribers(tag string) ([]NotifierEmailSubscriber, error)

func GetUnsubscribedEmails

func GetUnsubscribedEmails() ([]NotifierEmailSubscriber, error)

func NewNotifierEmailSubscriber

func NewNotifierEmailSubscriber(email, firstName, lastName string) *NotifierEmailSubscriber

func SubscribeEmail

func SubscribeEmail(email, fName, lName string, tags []string, createTag bool) (*NotifierEmailSubscriber, error)

func (*NotifierEmailSubscriber) Unsubscribable

func (email *NotifierEmailSubscriber) Unsubscribable() bool

type NotifierEmailUnsubscribeEvent

type NotifierEmailUnsubscribeEvent struct {
	ID     uint64
	Reason string
}

func EmailUnsubscribeEventsList

func EmailUnsubscribeEventsList() ([]NotifierEmailUnsubscribeEvent, error)

func NewNotifierEmailUnsubscribeEvent

func NewNotifierEmailUnsubscribeEvent(reason string, ID uint64) *NotifierEmailUnsubscribeEvent

type NotifierMobileDriver

type NotifierMobileDriver struct {
	Payload string `gorm:"type=longtext"`
	Type    string
	Name    string
	ID      uint64
}

func NewNotifierMobileDriver

func NewNotifierMobileDriver(payload string, Type string, name string) *NotifierMobileDriver

type NotifierMobileSubTag

type NotifierMobileSubTag struct {
	MobileSubscriberId uint64
	TagId              uint64
}

func NewNotifierMobileSubTag

func NewNotifierMobileSubTag(mobileSubscriberId uint64, tagId uint64) *NotifierMobileSubTag

type NotifierMobileSubscriber

type NotifierMobileSubscriber struct {
	UnsubscribedEventId *uint64
	UnsubscribedAt      *time.Time
	CountryCode         string
	CreatedAt           time.Time
	UpdatedAt           time.Time
	FirstName           string
	LastName            string
	Mobile              string
	ID                  uint64
}

func GetTagMobileSubscribers

func GetTagMobileSubscribers(tag string) ([]NotifierMobileSubscriber, error)

func GetUnsubscribedMobiles

func GetUnsubscribedMobiles() ([]NotifierMobileSubscriber, error)

func NewNotifierMobileSubscriber

func NewNotifierMobileSubscriber(countryCode, mobile, firstName, lastName string) *NotifierMobileSubscriber

func SubscribeMobile

func SubscribeMobile(countryCode, mobile, fName, lName string, tags []string, createTag bool) (*NotifierMobileSubscriber, error)

func (*NotifierMobileSubscriber) Unsubscribable

func (mobile *NotifierMobileSubscriber) Unsubscribable() bool

type NotifierMobileUnsubscribeEvent

type NotifierMobileUnsubscribeEvent struct {
	ID     uint64
	Reason string
}

func MobileUnsubscribeEventsList

func MobileUnsubscribeEventsList() ([]NotifierMobileUnsubscribeEvent, error)

func NewNotifierMobileUnsubscribeEvent

func NewNotifierMobileUnsubscribeEvent(reason string, ID uint64) *NotifierMobileUnsubscribeEvent

type NotifierNotificationService

type NotifierNotificationService struct {
	Payload string `gorm:"type=longtext"`
	Type    string
	Name    string
	ID      uint64
}

func NewNotifierNotificationService

func NewNotifierNotificationService(payload string, Type string, name string) *NotifierNotificationService

func NotificationDriversList

func NotificationDriversList() ([]NotifierNotificationService, error)

type NotifierNotificationSubTag

type NotifierNotificationSubTag struct {
	NotificationSubscriberId uint64
	TagId                    uint64
}

func NewNotifierNotificationSubTag

func NewNotifierNotificationSubTag(notificationSubscriberId uint64, tagId uint64) *NotifierNotificationSubTag

type NotifierNotificationSubscriber

type NotifierNotificationSubscriber struct {
	CreatedAt time.Time
	UpdatedAt time.Time
	FirstName string
	LastName  string
	DriverId  uint64
	Token     string
	ID        uint64
}

func AddNewToken

func AddNewToken(token, fName, lName string, driverId uint64, tags []string, createTag bool) (*NotifierNotificationSubscriber, error)

func GetTagAndDriverTokenSubscribers

func GetTagAndDriverTokenSubscribers(tag string, driverId uint64) ([]NotifierNotificationSubscriber, error)

func GetTagTokenSubscribers

func GetTagTokenSubscribers(tag string) ([]NotifierNotificationSubscriber, error)

func NewNotifierNotificationSubscriber

func NewNotifierNotificationSubscriber(token, firstName, lastName string, driverId uint64) *NotifierNotificationSubscriber

type NotifierTag

type NotifierTag struct {
	CreatedAt time.Time
	UpdatedAt time.Time
	Name      string
	ID        uint64
}

func CreateTag

func CreateTag(name string) (*NotifierTag, error)

func GetEmailCampaignTags

func GetEmailCampaignTags(cmpId uint64) []NotifierTag

func GetTagByName

func GetTagByName(name string) (*NotifierTag, error)

func NewNotifierTag

func NewNotifierTag(name string) *NotifierTag

func TagsList

func TagsList() ([]NotifierTag, error)

type Queue

type Queue struct {
	// contains filtered or unexported fields
}

func NewQueue

func NewQueue(name string) *Queue

func (*Queue) CloseWorker

func (q *Queue) CloseWorker()

func (*Queue) Send

func (q *Queue) Send(data *QueueMessage)

func (*Queue) StartListening

func (q *Queue) StartListening()

type QueueMessage

type QueueMessage struct {
	// contains filtered or unexported fields
}

func NewQueueMessage

func NewQueueMessage(handle func(data any) error, data interface{}) *QueueMessage

type SmtpConfig

type SmtpConfig struct {
	Host       string
	Port       string
	Username   string
	Password   string
	Encryption string
}

type SmtpMailer

type SmtpMailer struct {
	// contains filtered or unexported fields
}

func (*SmtpMailer) Send

func (s *SmtpMailer) Send(fromName, fromMail, to, subject, message string) error

func (*SmtpMailer) SetConfig

func (s *SmtpMailer) SetConfig(config []byte)

type WorkerConfig

type WorkerConfig struct {
	Duration time.Duration
	Worker   IWorker
	Name     string
}

type WorkersList

type WorkersList []WorkerConfig

Directories

Path Synopsis
examples

Jump to

Keyboard shortcuts

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