lib

package
v0.1.2 Latest Latest
Warning

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

Go to latest
Published: May 25, 2023 License: MIT Imports: 13 Imported by: 1

Documentation

Index

Constants

View Source
const (
	HTTPStatusOk       = 200
	HTTPStatusCreated  = 201
	HTTPStatusNoChange = 204
	HTTPRedirectOk     = 300
)
View Source
const (
	NovuURL     = "https://api.novu.co"
	NovuVersion = "v1"
)
View Source
const Version = "v1"

Variables

This section is empty.

Functions

func MustParseURL added in v0.1.2

func MustParseURL(rawURL string) *url.URL

Types

type APIClient

type APIClient struct {

	// Api Service
	SubscriberApi   *SubscriberService
	EventApi        *EventService
	TopicsApi       *TopicService
	IntegrationsApi *IntegrationService
	// contains filtered or unexported fields
}

func NewAPIClient

func NewAPIClient(apiKey string, cfg *Config) *APIClient

type BroadcastEventToAll added in v0.1.2

type BroadcastEventToAll struct {
	Name          interface{} `json:"name,omitempty"`
	Payload       interface{} `json:"payload,omitempty"`
	Overrides     interface{} `json:"overrides,omitempty"`
	TransactionId string      `json:"transactionId,omitempty"`
	Actor         interface{} `json:"actor,omitempty"`
}

type BulkTriggerEvent added in v0.1.2

type BulkTriggerEvent struct {
	Events []BulkTriggerOptions `json:"events"`
}

type BulkTriggerOptions added in v0.1.2

type BulkTriggerOptions struct {
	Name          interface{} `json:"name,omitempty"`
	To            interface{} `json:"to,omitempty"`
	Payload       interface{} `json:"payload,omitempty"`
	Overrides     interface{} `json:"overrides,omitempty"`
	TransactionId string      `json:"transactionId,omitempty"`
	Actor         interface{} `json:"actor,omitempty"`
}

type CTA added in v0.1.2

type CTA struct {
	Type   string `json:"type"`
	Action struct {
		Status  string `json:"status"`
		Buttons struct {
			Type          string `json:"type"`
			Content       string `json:"content"`
			ResultContent string `json:"resultContent"`
		} `json:"buttons"`
		Result struct {
			Payload map[string]interface{} `json:"payload"`
			Type    string                 `json:"type"`
		} `json:"result"`
	}
}

type Channel added in v0.1.2

type Channel struct {
	Email bool `json:"email"`
	Sms   bool `json:"sms"`
	Chat  bool `json:"chat"`
	InApp bool `json:"in_app"`
	Push  bool `json:"push"`
}

type ChannelType

type ChannelType string
const (
	EMAIL  ChannelType = "EMAIL"
	SMS    ChannelType = "SMS"
	DIRECT ChannelType = "DIRECT"
)

type Config

type Config struct {
	BackendURL *url.URL
	HttpClient *http.Client
}

type CreateIntegrationRequest added in v0.1.2

type CreateIntegrationRequest struct {
	ProviderID  string                 `json:"providerId"`
	Channel     ChannelType            `json:"channel"`
	Credentials IntegrationCredentials `json:"credentials,omitempty"`
	Active      bool                   `json:"active"`
	Check       bool                   `json:"check"`
}

type CreateTopicRequest added in v0.1.2

type CreateTopicRequest struct {
	Name string `json:"name"`
	Key  string `json:"key"`
}

type Data

type Data struct {
	Acknowledged bool   `json:"acknowledged"`
	Status       string `json:"status"`
}

type EventRequest

type EventRequest struct {
	Name          string      `json:"name"`
	To            interface{} `json:"to"`
	Payload       interface{} `json:"payload"`
	Overrides     interface{} `json:"overrides,omitempty"`
	TransactionId string      `json:"transactionId,omitempty"`
	Actor         interface{} `json:"actor,omitempty"`
}

type EventResponse

type EventResponse struct {
	Data interface{} `json:"data"`
}

type EventService

type EventService service

func (*EventService) BroadcastToAll added in v0.1.2

func (e *EventService) BroadcastToAll(ctx context.Context, data BroadcastEventToAll) (EventResponse, error)

func (*EventService) CancelTrigger added in v0.1.2

func (e *EventService) CancelTrigger(ctx context.Context, transactionId string) (bool, error)

func (*EventService) Trigger

func (e *EventService) Trigger(ctx context.Context, eventId string, data ITriggerPayloadOptions) (EventResponse, error)

func (*EventService) TriggerBulk added in v0.1.2

func (e *EventService) TriggerBulk(ctx context.Context, data []BulkTriggerOptions) ([]EventResponse, error)

type GeneralError

type GeneralError error

type GetIntegrationsResponse added in v0.1.2

type GetIntegrationsResponse struct {
	Data []Integration `json:"data"`
}

type GetTopicResponse added in v0.1.2

type GetTopicResponse struct {
	Id             string   `json:"_id"`
	OrganizationId string   `json:"_organizationId"`
	EnvironmentId  string   `json:"_environmentId"`
	Key            string   `json:"key"`
	Name           string   `json:"name"`
	Subscribers    []string `json:"subscribers"`
}

type IAttachmentOptions

type IAttachmentOptions struct {
	Mime     string        `json:"mime,omitempty"`
	File     io.Reader     `json:"file,omitempty"`
	Name     string        `json:"name,omitempty"`
	Channels []ChannelType `json:"channels,omitempty"`
}

type IEvent

type IEvent interface {
	Trigger(ctx context.Context, eventId string, data ITriggerPayloadOptions) (EventResponse, error)
	TriggerBulk(ctx context.Context, data []BulkTriggerOptions) ([]EventResponse, error)
	BroadcastToAll(ctx context.Context, data BroadcastEventToAll) (EventResponse, error)
	CancelTrigger(ctx context.Context, transactionId string) (bool, error)
}

type IIntegration added in v0.1.2

type IIntegration interface {
	Create(ctx context.Context, request CreateIntegrationRequest) (*IntegrationResponse, error)
	GetAll(ctx context.Context) (*GetIntegrationsResponse, error)
	GetActive(ctx context.Context) (*GetIntegrationsResponse, error)
	Update(ctx context.Context, integrationId string, request UpdateIntegrationRequest) (*IntegrationResponse, error)
	Delete(ctx context.Context, integrationId string) (*IntegrationResponse, error)
}

type ISubscribers

type ISubscribers interface {
	Identify(ctx context.Context, subscriberID string, data interface{}) (SubscriberResponse, error)
	Get(ctx context.Context, subscriberID string) (SubscriberResponse, error)
	Update(ctx context.Context, subscriberID string, data interface{}) (SubscriberResponse, error)
	Delete(ctx context.Context, subscriberID string) (SubscriberResponse, error)
	GetNotificationFeed(ctx context.Context, subscriberID string, opts *SubscriberNotificationFeedOptions) (*SubscriberNotificationFeedResponse, error)
	GetUnseenCount(ctx context.Context, subscriberID string, opts *SubscriberUnseenCountOptions) (*SubscriberUnseenCountResponse, error)
	MarkMessageSeen(ctx context.Context, subscriberID string, opts SubscriberMarkMessageSeenOptions) (*SubscriberNotificationFeedResponse, error)
	GetPreferences(ctx context.Context, subscriberID string) (*SubscriberPreferencesResponse, error)
	UpdatePreferences(ctx context.Context, subscriberID string, templateId string, opts *UpdateSubscriberPreferencesOptions) (*SubscriberPreferencesResponse, error)
}

type ITopic added in v0.1.2

type ITopic interface {
	Create(ctx context.Context, key string, name string) error
	List(ctx context.Context, options *ListTopicsOptions) (*ListTopicsResponse, error)
	AddSubscribers(ctx context.Context, key string, subscribers []string) error
	RemoveSubscribers(ctx context.Context, key string, subscribers []string) error
	Get(ctx context.Context, key string) (*GetTopicResponse, error)
	Rename(ctx context.Context, key string, name string) (*GetTopicResponse, error)
}

type ITriggerPayload

type ITriggerPayload interface {
	string | []string | bool | int64 | IAttachmentOptions | []IAttachmentOptions
}

type ITriggerPayloadOptions

type ITriggerPayloadOptions struct {
	To            interface{} `json:"to,omitempty"`
	Payload       interface{} `json:"payload,omitempty"`
	Overrides     interface{} `json:"overrides,omitempty"`
	TransactionId string      `json:"transactionId,omitempty"`
	Actor         interface{} `json:"actor,omitempty"`
}

type Integration added in v0.1.2

type Integration struct {
	Id             string                 `json:"_id"`
	EnvironmentID  string                 `json:"_environmentId"`
	OrganizationID string                 `json:"_organizationId"`
	ProviderID     string                 `json:"providerId"`
	Channel        ChannelType            `json:"channel"`
	Credentials    IntegrationCredentials `json:"credentials"`
	Active         bool                   `json:"active"`
	Deleted        bool                   `json:"deleted"`
	UpdatedAt      string                 `json:"updatedAt"`
	DeletedAt      string                 `json:"deletedAt"`
	DeletedBy      string                 `json:"deletedBy"`
}

type IntegrationCredentials added in v0.1.2

type IntegrationCredentials struct {
	ApiKey           string                 `json:"apiKey,omitempty"`
	User             string                 `json:"user,omitempty"`
	SecretKey        string                 `json:"secretKey,omitempty"`
	Domain           string                 `json:"domain,omitempty"`
	Password         string                 `json:"password,omitempty"`
	Host             string                 `json:"host,omitempty"`
	Port             string                 `json:"port,omitempty"`
	Secure           bool                   `json:"secure,omitempty"`
	Region           string                 `json:"region,omitempty"`
	AccountSID       string                 `json:"accountSid,omitempty"`
	MessageProfileID string                 `json:"messageProfileId,omitempty"`
	Token            string                 `json:"token,omitempty"`
	From             string                 `json:"from,omitempty"`
	SenderName       string                 `json:"senderName,omitempty"`
	ProjectName      string                 `json:"projectName,omitempty"`
	ApplicationID    string                 `json:"applicationId,omitempty"`
	ClientID         string                 `json:"clientId,omitempty"`
	RequireTls       bool                   `json:"requireTls,omitempty"`
	IgnoreTls        bool                   `json:"ignoreTls,omitempty"`
	TlsOptions       map[string]interface{} `json:"tlsOptions,omitempty"`
}

type IntegrationResponse added in v0.1.2

type IntegrationResponse struct {
	Data Integration `json:"data"`
}

type IntegrationService added in v0.1.2

type IntegrationService service

func (IntegrationService) Create added in v0.1.2

func (IntegrationService) Delete added in v0.1.2

func (i IntegrationService) Delete(ctx context.Context, integrationId string) (*IntegrationResponse, error)

func (IntegrationService) GetActive added in v0.1.2

func (IntegrationService) GetAll added in v0.1.2

func (IntegrationService) Update added in v0.1.2

type ListTopicsOptions added in v0.1.2

type ListTopicsOptions struct {
	Page     *int    `json:"page,omitempty"`
	PageSize *int    `json:"pageSize,omitempty"`
	Key      *string `json:"key,omitempty"`
}

type ListTopicsResponse added in v0.1.2

type ListTopicsResponse struct {
	Page       int                `json:"name"`
	PageSize   int                `json:"pageSize"`
	TotalCount int                `json:"totalCount"`
	Data       []GetTopicResponse `json:"data"`
}

type NotificationFeedData added in v0.1.2

type NotificationFeedData struct {
	CTA              CTA       `json:"cta"`
	Channel          string    `json:"channel"`
	Content          string    `json:"content"`
	CreatedAt        time.Time `json:"createdAt"`
	Deleted          bool      `json:"deleted"`
	DeviceTokens     []string  `json:"deviceTokens"`
	DirectWebhookURL string    `json:"directWebhookUrl"`
	EnvironmentID    string    `json:"_environmentId"`
	ErrorID          string    `json:"errorId"`
	ErrorText        string    `json:"errorText"`
	FeedID           string    `json:"_feedId"`
	ID               string    `json:"_id"`
	JobID            string    `json:"_jobId"`
	LastReadDate     time.Time `json:"lastReadDate"`
	LastSeenDate     time.Time `json:"lastSeenDate"`
	MessageTemplate  string    `json:"_messageTemplateId"`
	NotificationID   string    `json:"_notificationId"`
	OrganizationID   string    `json:"_organizationId"`
	Payload          struct {
		UpdateMessage string `json:"updateMessage"`
	} `json:"payload"`
	ProviderID string `json:"providerId"`
	Read       bool   `json:"read"`
	ResponseID string `json:"id"`
	Seen       bool   `json:"seen"`
	Status     string `json:"status"`
	Subscriber struct {
		ID           string `json:"_id"`
		SubscriberID string `json:"subscriberId"`
	} `json:"subscriber"`
	SubscriberID       string    `json:"_subscriberId"`
	TemplateID         string    `json:"_templateId"`
	TemplateIdentifier string    `json:"templateIdentifier"`
	TransactionID      string    `json:"transactionId"`
	UpdatedAt          time.Time `json:"updatedAt"`
}

type Preference added in v0.1.2

type Preference struct {
	Enabled  bool    `json:"enabled"`
	Channels Channel `json:"channels"`
}

type QueryParam added in v0.1.2

type QueryParam struct {
	Key   string
	Value string
}

func GenerateQueryParamsFromStruct added in v0.1.2

func GenerateQueryParamsFromStruct[T interface{}](queryParamsStruct T) ([]QueryParam, error)

type RenameTopicRequest added in v0.1.2

type RenameTopicRequest struct {
	Name string `json:"name"`
}

type Response

type Response struct {
	Data Data `json:"data"`
}

type SubscriberMarkMessageSeenOptions added in v0.1.2

type SubscriberMarkMessageSeenOptions struct {
	MessageID string `json:"messageId"`
	Seen      bool   `json:"seen"`
	Read      bool   `json:"read"`
}

type SubscriberNotificationFeedOptions added in v0.1.2

type SubscriberNotificationFeedOptions struct {
	Page           int    `queryKey:"page"`
	FeedIdentifier string `queryKey:"feedIdentifier"`
	Seen           bool   `queryKey:"seen"`
}

type SubscriberNotificationFeedResponse added in v0.1.2

type SubscriberNotificationFeedResponse struct {
	TotalCount int                    `json:"totalCount"`
	Data       []NotificationFeedData `json:"data"`
	PageSize   int                    `json:"pageSize"`
	Page       int                    `json:"page"`
}

type SubscriberPayload

type SubscriberPayload struct {
	FirstName string                 `json:"first_name,omitempty"`
	LastName  string                 `json:"last_name,omitempty"`
	Email     string                 `json:"email,omitempty"`
	Phone     string                 `json:"phone,omitempty"`
	Avatar    string                 `json:"avatar,omitempty"`
	Data      map[string]interface{} `json:"data,omitempty"`
}

type SubscriberPreferencesResponse added in v0.1.2

type SubscriberPreferencesResponse struct {
	Data []struct {
		Template   Template   `json:"template"`
		Preference Preference `json:"preference"`
	} `json:"data"`
}

type SubscriberResponse

type SubscriberResponse struct {
	Data interface{} `json:"data"`
}

type SubscriberService

type SubscriberService service

func (*SubscriberService) Delete

func (s *SubscriberService) Delete(ctx context.Context, subscriberID string) (SubscriberResponse, error)

func (*SubscriberService) Get added in v0.1.2

func (s *SubscriberService) Get(ctx context.Context, subscriberID string) (SubscriberResponse, error)

func (*SubscriberService) GetNotificationFeed added in v0.1.2

func (*SubscriberService) GetPreferences added in v0.1.2

func (s *SubscriberService) GetPreferences(ctx context.Context, subscriberID string) (*SubscriberPreferencesResponse, error)

func (*SubscriberService) GetUnseenCount added in v0.1.2

func (*SubscriberService) Identify

func (s *SubscriberService) Identify(ctx context.Context, subscriberID string, data interface{}) (SubscriberResponse, error)

func (*SubscriberService) MarkMessageSeen added in v0.1.2

func (*SubscriberService) Update

func (s *SubscriberService) Update(ctx context.Context, subscriberID string, data interface{}) (SubscriberResponse, error)

func (*SubscriberService) UpdatePreferences added in v0.1.2

func (s *SubscriberService) UpdatePreferences(ctx context.Context, subscriberID string, templateId string, opts *UpdateSubscriberPreferencesOptions) (*SubscriberPreferencesResponse, error)

type SubscriberUnseenCountOptions added in v0.1.2

type SubscriberUnseenCountOptions struct {
	Seen *bool `json:"seen"`
}

type SubscriberUnseenCountResponse added in v0.1.2

type SubscriberUnseenCountResponse struct {
	Data struct {
		Count int `json:"count"`
	} `json:"data"`
}

type SubscribersTopicRequest added in v0.1.2

type SubscribersTopicRequest struct {
	Subscribers []string `json:"subscribers"`
}

type Template added in v0.1.2

type Template struct {
	ID       string `json:"_id"`
	Name     string `json:"name"`
	Critical bool   `json:"critical"`
}

type TopicService added in v0.1.2

type TopicService service

func (*TopicService) AddSubscribers added in v0.1.2

func (t *TopicService) AddSubscribers(ctx context.Context, key string, subscribers []string) error

func (*TopicService) Create added in v0.1.2

func (t *TopicService) Create(ctx context.Context, key string, name string) error

func (*TopicService) Get added in v0.1.2

func (*TopicService) List added in v0.1.2

func (*TopicService) RemoveSubscribers added in v0.1.2

func (t *TopicService) RemoveSubscribers(ctx context.Context, key string, subscribers []string) error

func (*TopicService) Rename added in v0.1.2

func (t *TopicService) Rename(ctx context.Context, key string, name string) (*GetTopicResponse, error)

type TriggerRecipientsTypeArray

type TriggerRecipientsTypeArray interface {
	[]string | []SubscriberPayload
}

type TriggerRecipientsTypeSingle

type TriggerRecipientsTypeSingle interface {
	string | SubscriberPayload
}

type TriggerTopicRecipientsTypeSingle added in v0.1.2

type TriggerTopicRecipientsTypeSingle struct {
	TopicKey string `json:"topicKey,omitempty"`
	Type     string `json:"type,omitempty"`
}

type UpdateIntegrationRequest added in v0.1.2

type UpdateIntegrationRequest struct {
	Credentials IntegrationCredentials `json:"credentials"`
	Active      bool                   `json:"active"`
	Check       bool                   `json:"check"`
}

type UpdateSubscriberPreferencesChannel added in v0.1.2

type UpdateSubscriberPreferencesChannel struct {
	Type    ChannelType `json:"type"`
	Enabled bool        `json:"enabled"`
}

type UpdateSubscriberPreferencesOptions added in v0.1.2

type UpdateSubscriberPreferencesOptions struct {
	Channel []UpdateSubscriberPreferencesChannel `json:"channel,omitempty"`
	Enabled bool                                 `json:"enabled,omitempty"`
}

Jump to

Keyboard shortcuts

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