Documentation
¶
Index ¶
- Constants
- Variables
- func ValidateAndMarshal(sch string, el Element) ([]byte, error)
- func ValidateAndUnmarshal(sch string, b []byte, el Element) error
- type Action
- type ActionType
- type BooleanFilter
- type Channel
- type Context
- type Element
- type Event
- type Flavour
- type Handling
- type Item
- type Keys
- type Link
- func GetMP4Link(url string, title string, description string, thumbnailURL string) Link
- func GetPDFDocumentLink(url string, title string, description string, thumbnailURL string) Link
- func GetPNGImageLink(url string, title string, description string, thumbnailURL string) Link
- func GetSVGImageLink(url string, title string, description string, thumbnailURL string) Link
- func GetYoutubeVideoLink(url string, title string, description string, thumbnailURL string) Link
- type LinkType
- type Message
- type NotificationBody
- type Nudge
- type Payload
- type Status
- type TextType
- type Visibility
Constants ¶
const ( LogoURL = "https://assets.healthcloud.co.ke/bewell_logo.png" BlankImageURL = "https://assets.healthcloud.co.ke/1px.png" SampleVideoURL = "https://www.youtube.com/watch?v=bPiofmZGb8o" FallbackSchemaHost = "https://schema.healthcloud.co.ke" SchemaHostEnvVarName = "SCHEMA_HOST" LinkSchemaFile = "link.schema.json" MessageSchemaFile = "message.schema.json" ActionSchemaFile = "action.schema.json" NudgeSchemaFile = "nudge.schema.json" ItemSchemaFile = "item.schema.json" FeedSchemaFile = "feed.schema.json" ContextSchemaFile = "context.schema.json" PayloadSchemaFile = "payload.schema.json" EventSchemaFile = "event.schema.json" StatusSchemaFile = "status.schema.json" VisibilitySchemaFile = "visibility.schema.json" NotificationBodySchemaFile = "notificationbody.schema.json" )
defaults
Variables ¶
var AllActionType = []ActionType{ ActionTypePrimary, ActionTypeSecondary, ActionTypeOverflow, ActionTypeFloating, }
AllActionType has the known set of action types
var AllChannel = []Channel{ ChannelFcm, ChannelEmail, ChannelSms, ChannelWhatsapp, }
AllChannel is the set of all supported notification channels
var AllFlavour = []Flavour{ FlavourPro, FlavourConsumer, }
AllFlavour is a set of all valid flavours
var AllHandling = []Handling{ HandlingInline, HandlingFullPage, }
AllHandling is the set of all valid handling strategies
var AllKeys = []Keys{ KeysActions, KeysNudges, KeysItems, }
AllKeys is the set of all valid feed keys
var AllLinkType = []LinkType{ LinkTypeYoutubeVideo, LinkTypePngImage, LinkTypePdfDocument, LinkTypeSvgImage, LinkTypeMp4, LinkTypeDefault, }
AllLinkType is the set of all known link types
var AllStatus = []Status{ StatusPending, StatusInProgress, StatusDone, }
AllStatus is the set of known statuses
var AllTextType = []TextType{ TextTypeHTML, TextTypeMarkdown, TextTypePlain, }
AllTextType is the set of all known text types
var AllVisibility = []Visibility{ VisibilityShow, VisibilityHide, }
AllVisibility is the set of all known visibility values
var IsValid = []BooleanFilter{ BooleanFilterTrue, BooleanFilterFalse, BooleanFilterBoth, }
IsValid is a set of known boolean filters
Functions ¶
func ValidateAndMarshal ¶
ValidateAndMarshal marshals a feed element to JSON, checks it against the indicated schema file and returns it if it is valid.
Types ¶
type Action ¶
type Action struct {
// A unique identifier for each action
ID string `json:"id" firestore:"id"`
// A higher sequence number means that it came later
SequenceNumber int `json:"sequenceNumber" firestore:"sequenceNumber"`
// A friendly name for the action; rich text with Unicode, can have emoji
Name string `json:"name" firestore:"name"`
// A link to a PNG image that would serve as an avatar
Icon Link `json:"icon" firestore:"icon"`
// Action types are: primary, secondary, overflow and floating
// Primary actions get dominant visual treatment;
// secondary actions less so;
// overflow actions are hidden;
// floating actions are material FABs
ActionType ActionType `json:"actionType" firestore:"actionType"`
// How the action should be handled e.g inline or full page.
// This is a hint for frontend logic.
Handling Handling `json:"handling" firestore:"handling"`
// indicated whether this action should or can be triggered by na anoymous user
AllowAnonymous bool `json:"allowAnonymous" firestore:"allowAnonymous"`
}
Action represents the global and non-global actions that a user can see/do
func (Action) IsEntity ¶
func (ac Action) IsEntity()
IsEntity marks this as an Apollo federation GraphQL entity
func (*Action) ValidateAndMarshal ¶
ValidateAndMarshal validates against JSON schema then marshals to JSON
func (*Action) ValidateAndUnmarshal ¶
ValidateAndUnmarshal checks that the input data is valid as per the relevant JSON schema and unmarshals it if it is
type ActionType ¶
type ActionType string
ActionType defines the types for global actions
const ( ActionTypePrimary ActionType = "PRIMARY" ActionTypeSecondary ActionType = "SECONDARY" ActionTypeOverflow ActionType = "OVERFLOW" ActionTypeFloating ActionType = "FLOATING" )
the known action types are constants
func (ActionType) IsValid ¶
func (e ActionType) IsValid() bool
IsValid returns true only for valid action types
func (ActionType) MarshalGQL ¶
func (e ActionType) MarshalGQL(w io.Writer)
MarshalGQL writes an action type to the supplied writer
func (ActionType) String ¶
func (e ActionType) String() string
func (*ActionType) UnmarshalGQL ¶
func (e *ActionType) UnmarshalGQL(v interface{}) error
UnmarshalGQL reads an action type from GQL
type BooleanFilter ¶
type BooleanFilter string
BooleanFilter defines true/false/both for filtering against bools
const ( BooleanFilterTrue BooleanFilter = "TRUE" BooleanFilterFalse BooleanFilter = "FALSE" BooleanFilterBoth BooleanFilter = "BOTH" )
known boolean filter value
func (BooleanFilter) IsValid ¶
func (e BooleanFilter) IsValid() bool
IsValid returns True if the boolean filter value is valid
func (BooleanFilter) MarshalGQL ¶
func (e BooleanFilter) MarshalGQL(w io.Writer)
MarshalGQL writes the bool value to the supplied writer
func (BooleanFilter) String ¶
func (e BooleanFilter) String() string
func (*BooleanFilter) UnmarshalGQL ¶
func (e *BooleanFilter) UnmarshalGQL(v interface{}) error
UnmarshalGQL reads the bool value in from input
type Channel ¶
type Channel string
Channel represents a notification challen
const ( ChannelFcm Channel = "FCM" ChannelEmail Channel = "EMAIL" ChannelSms Channel = "SMS" ChannelWhatsapp Channel = "WHATSAPP" )
known notification channels
func (Channel) MarshalGQL ¶
MarshalGQL writes the channel to the supplied writer
func (*Channel) UnmarshalGQL ¶
UnmarshalGQL converts the supplied input into a channel value
type Context ¶
type Context struct {
// the system or human user that created this event
UserID string `json:"userID" firestore:"userID"`
// the flavour of the feed/app that originated this event
Flavour Flavour `json:"flavour" firestore:"flavour"`
// the client (organization) that this user belongs to
OrganizationID string `json:"organizationID" firestore:"organizationID"`
// the location (e.g branch) from which the event was sent
LocationID string `json:"locationID" firestore:"locationID"`
// when this event was sent
Timestamp time.Time `json:"timestamp" firestore:"timestamp"`
}
Context identifies when/where/why/who/what/how an event occurred.
func (*Context) ValidateAndMarshal ¶
ValidateAndMarshal validates against JSON schema then marshals to JSON
func (*Context) ValidateAndUnmarshal ¶
ValidateAndUnmarshal checks that the input data is valid as per the relevant JSON schema and unmarshals it if it is
type Element ¶
type Element interface {
ValidateAndUnmarshal(b []byte) error
ValidateAndMarshal() ([]byte, error)
}
Element is a building block of a feed e.g a nudge, action, feed item etc An element should know how to validate itself against it's JSON schema
type Event ¶
type Event struct {
// A unique identifier for each action
ID string `json:"id" firestore:"id"`
// An event name - two upper case words separated by an underscore
Name string `json:"name" firestore:"name"`
// Technical metadata - when/where/why/who/what/how etc
Context Context `json:"context,omitempty" firestore:"context,omitempty"`
// The actual 'business data' carried by the event
Payload Payload `json:"payload,omitempty" firestore:"payload,omitempty"`
}
Event An event indicating that this action was triggered
func (Event) IsEntity ¶
func (ev Event) IsEntity()
IsEntity marks this as an Apollo federation GraphQL entity
func (*Event) ValidateAndMarshal ¶
ValidateAndMarshal validates against JSON schema then marshals to JSON
func (*Event) ValidateAndUnmarshal ¶
ValidateAndUnmarshal checks that the input data is valid as per the relevant JSON schema and unmarshals it if it is
type Flavour ¶
type Flavour string
Flavour is the flavour of a feed i.e consumer or pro
func (Flavour) MarshalGQL ¶
MarshalGQL writes the flavour to the supplied writer
func (*Flavour) UnmarshalGQL ¶
UnmarshalGQL translates and validates the input flavour
type Handling ¶
type Handling string
Handling determines whether an action is handled INLINE or
known action handling strategies
func (Handling) MarshalGQL ¶
MarshalGQL writes the Handling value to the supplied writer
func (*Handling) UnmarshalGQL ¶
UnmarshalGQL reads and validates a handling value from the supplied input
type Item ¶
type Item struct {
// A unique identifier for each feed item
ID string `json:"id" firestore:"id"`
// A higher sequence number means that it came later
SequenceNumber int `json:"sequenceNumber" firestore:"sequenceNumber"`
// When this feed item should be expired/removed, automatically. RFC3339.
Expiry time.Time `json:"expiry" firestore:"expiry"`
// If a feed item is persistent, it also goes to the inbox
// AND triggers a push notification.
// Pinning a feed item makes it persistent.
Persistent bool `json:"persistent" firestore:"persistent"`
// Whether the task under a feed item is completed, pending etc
Status Status `json:"status" firestore:"status"`
// Whether the feed item is to be shown or hidden
Visibility Visibility `json:"visibility" firestore:"visibility"`
// A link to a PNG image that would serve as an avatar
Icon Link `json:"icon" firestore:"icon"`
// The person - real or robot - that generated this feed item. Rich text.
Author string `json:"author" firestore:"author"`
// An OPTIONAL second title line. Rich text.
Tagline string `json:"tagline" firestore:"tagline"`
// A label e.g for the queue that this item belongs to
Label string `json:"label" firestore:"label"`
// When this feed item was created. RFC3339.
// This is used to calculate the feed item's age for display.
Timestamp time.Time `json:"timestamp" firestore:"timestamp"`
// An OPTIONAL summary line. Rich text.
Summary string `json:"summary" firestore:"summary"`
// Rich text that can include any unicode e.g emoji
Text string `json:"text" firestore:"text"`
// TextType determines how the frontend will render the text
TextType TextType `json:"textType" firestore:"textType"`
// an illustrative image for the item
Links []Link `json:"links" firestore:"links"`
// Actions are the primary, secondary and overflow actions associated
// with a feed item
Actions []Action `json:"actions,omitempty" firestore:"actions,omitempty"`
// Conversations are messages and replies around a feed item
Conversations []Message `json:"conversations,omitempty" firestore:"conversations,omitempty"`
// Identifiers of all the users that got this message
Users []string `json:"users,omitempty" firestore:"users,omitempty"`
// Identifiers of all the groups that got this message
Groups []string `json:"groups,omitempty" firestore:"groups,omitempty"`
// How the user should be notified of this new item, if at all
NotificationChannels []Channel `json:"notificationChannels,omitempty" firestore:"notificationChannels,omitempty"`
// FeatureImage represents the image associated to a post
FeatureImage string `json:"feature_image"`
}
Item is a single item in a feed or in an inbox
func (Item) IsEntity ¶
func (it Item) IsEntity()
IsEntity marks this as an Apollo federation GraphQL entity
func (*Item) ValidateAndMarshal ¶
ValidateAndMarshal validates against JSON schema then marshals to JSON
func (*Item) ValidateAndUnmarshal ¶
ValidateAndUnmarshal checks that the input data is valid as per the relevant JSON schema and unmarshals it if it is
type Keys ¶
type Keys string
Keys are the top level keys in a feed
known feed keys
func (Keys) MarshalGQL ¶
MarshalGQL writes the feed key to the supplied writer
func (*Keys) UnmarshalGQL ¶
UnmarshalGQL translates a feed key from a string
type Link ¶
type Link struct {
// A unique identifier for each feed item
ID string `json:"id" firestore:"id"`
// A URL at which the video can be accessed.
// For a private video, the URL should include authentication information.
URL string `json:"url" firestore:"url"`
// LinkType of link
LinkType LinkType `json:"linkType" firestore:"linkType"`
// name or title of the linked item
Title string `json:"title" firestore:"title"`
// details about the linked item
Description string `json:"description" firestore:"description"`
// A URL to a PNG image that represents a thumbnail for the item
Thumbnail string `json:"thumbnail" firestore:"thumbnail"`
}
Link holds references to media that is part of the feed. The URL should embed authentication details. The treatment will depend on the specified asset type.
func GetMP4Link ¶ added in v0.0.5
GetMP4Link returns an initialized MP4 link.
It is used in testing and default data generation.
func GetPDFDocumentLink ¶
GetPDFDocumentLink returns an initialized PDF document link.
It is used in testing and default data generation.
func GetPNGImageLink ¶
GetPNGImageLink returns an initialized PNG image link.
It is used in testing and default data generation.
func GetSVGImageLink ¶
GetSVGImageLink returns an initialized PNG image link.
It is used in testing and default data generation.
func GetYoutubeVideoLink ¶
GetYoutubeVideoLink returns an initialized YouTube video link.
It is used in testing and default data generation.
func (*Link) ValidateAndMarshal ¶
ValidateAndMarshal validates against JSON schema then marshals to JSON
func (*Link) ValidateAndUnmarshal ¶
ValidateAndUnmarshal checks that the input data is valid as per the relevant JSON schema and unmarshals it if it is
type LinkType ¶
type LinkType string
LinkType determines how a linked asset is handled on the feed
const ( LinkTypeYoutubeVideo LinkType = "YOUTUBE_VIDEO" LinkTypePngImage LinkType = "PNG_IMAGE" LinkTypePdfDocument LinkType = "PDF_DOCUMENT" LinkTypeSvgImage LinkType = "SVG_IMAGE" LinkTypeMp4 LinkType = "MP4" LinkTypeDefault LinkType = "DEFAULT" )
known link types
func (LinkType) MarshalGQL ¶
MarshalGQL writes a link type to the supplied writer
func (*LinkType) UnmarshalGQL ¶
UnmarshalGQL reads a link type from the supplied input
type Message ¶
type Message struct {
// A unique identifier for each message on the thread
ID string `json:"id" firestore:"id"`
// A higher sequence number means that it came later
SequenceNumber int `json:"sequenceNumber" firestore:"sequenceNumber"`
// Rich text that can include any unicode e.g emoji
Text string `json:"text" firestore:"text"`
// The unique ID of any message that this one is replying to - a thread
ReplyTo string `json:"replyTo" firestore:"replyTo"`
// The UID of the user that posted the message
PostedByUID string `json:"postedByUID" firestore:"postedByUID"`
// The UID of the user that posted the message
PostedByName string `json:"postedByName" firestore:"postedByName"`
// when this message was sent
Timestamp time.Time `json:"timestamp" firestore:"timestamp"`
}
Message is a message in a thread of conversations attached to a feed item
func (*Message) ValidateAndMarshal ¶
ValidateAndMarshal validates against JSON schema then marshals to JSON
func (*Message) ValidateAndUnmarshal ¶
ValidateAndUnmarshal checks that the input data is valid as per the relevant JSON schema and unmarshals it if it is
type NotificationBody ¶
type NotificationBody struct {
// Human readable rich text sent when an item/nudge is published to a user's Feed
PublishMessage string `json:"publishMessage" firestore:"publishMessage"`
// Human readable rich text sent when item/nudge is deleted to a user's Feed
DeleteMessage string `json:"deleteMessage" firestore:"deleteMessage"`
// Human readable rich text sent when a user does a RESOLVE action
ResolveMessage string `json:"resolveMessage" firestore:"resolveMessage"`
// Human readable rich text sent when a user does an UNRESOLVE action
UnresolveMessage string `json:"unresolveMessage" firestore:"unresolveMessage"`
// Human readable rich text sent when a user does a SHOW action
ShowMessage string `json:"showMessage" firestore:"showMessage"`
// Human readable rich text sent when a user does a HIDE action
HideMessage string `json:"hideMessage" firestore:"hideMessage"`
}
NotificationBody represents human readable messages sent in notifications
func (*NotificationBody) IsEntity ¶
func (nb *NotificationBody) IsEntity()
IsEntity marks this as an Apollo federation GraphQL entity
func (*NotificationBody) ValidateAndMarshal ¶
func (nb *NotificationBody) ValidateAndMarshal() ([]byte, error)
ValidateAndMarshal validates against JSON schema then marshals to JSON
func (*NotificationBody) ValidateAndUnmarshal ¶
func (nb *NotificationBody) ValidateAndUnmarshal(b []byte) error
ValidateAndUnmarshal checks that the input data is valid as per the relevant JSON schema and unmarshals it if it is
type Nudge ¶
type Nudge struct {
// A unique identifier for each nudge
ID string `json:"id" firestore:"id"`
// A higher sequence number means that it came later
SequenceNumber int `json:"sequenceNumber" firestore:"sequenceNumber"`
// Visibility determines if a nudge should be visible or not
Visibility Visibility `json:"visibility" firestore:"visibility"`
// whether the nudge is done (acted on) or pending
Status Status `json:"status" firestore:"status"`
// When this nudge should be expired/removed, automatically. RFC3339.
Expiry time.Time `json:"expiry" firestore:"expiry"`
// the title (lead line) of the nudge
Title string `json:"title" firestore:"title"`
// the text/copy of the nudge
Text string `json:"text" firestore:"text"`
// an illustrative image for the nudge
Links []Link `json:"links" firestore:"links"`
// actions to include on the nudge
Actions []Action `json:"actions" firestore:"actions"`
// Identifiers of all the users that got this message
Users []string `json:"users,omitempty" firestore:"users,omitempty"`
// Identifiers of all the groups that got this message
Groups []string `json:"groups,omitempty" firestore:"groups,omitempty"`
// How the user should be notified of this new item, if at all
NotificationChannels []Channel `json:"notificationChannels,omitempty" firestore:"notificationChannels,omitempty"`
// Text/Message the user will see in their notifications body when an action is performed on a nudge
NotificationBody NotificationBody `json:"notificationBody,omitempty" firestore:"notificationBody,omitempty"`
}
Nudge represents a "prompt" for a user e.g to set a PIN
func (Nudge) IsEntity ¶
func (nu Nudge) IsEntity()
IsEntity marks this as an Apollo federation GraphQL entity
func (*Nudge) ValidateAndMarshal ¶
ValidateAndMarshal verifies against JSON schema then marshals to JSON
func (*Nudge) ValidateAndUnmarshal ¶
ValidateAndUnmarshal checks that the input data is valid as per the relevant JSON schema and unmarshals it if it is
type Payload ¶
type Payload struct {
Data map[string]interface{} `json:"data" firestore:"data"`
}
Payload carries the actual 'business data' carried by the event. It varies from event to event.
func (*Payload) ValidateAndMarshal ¶
ValidateAndMarshal validates against JSON schema then marshals to JSON
func (*Payload) ValidateAndUnmarshal ¶
ValidateAndUnmarshal checks that the input data is valid as per the relevant JSON schema and unmarshals it if it is
type Status ¶
type Status string
Status is the set of known statuses for feed items and nudges
const ( StatusPending Status = "PENDING" StatusInProgress Status = "IN_PROGRESS" StatusDone Status = "DONE" )
known item and nudge statuses
func (Status) MarshalGQL ¶
MarshalGQL writes the status to the supplied writer
func (*Status) UnmarshalGQL ¶
UnmarshalGQL translates the input value given into a status
type TextType ¶
type TextType string
TextType determines how clients render the text
const ( TextTypeHTML TextType = "HTML" TextTypeMarkdown TextType = "MARKDOWN" TextTypePlain TextType = "PLAIN" )
known text types
func (TextType) MarshalGQL ¶
MarshalGQL writes the text type to the supplied writer
func (*TextType) UnmarshalGQL ¶
UnmarshalGQL translates the supplied interface into a text type
type Visibility ¶
type Visibility string
Visibility defines the visibility statuses of feed items
const ( VisibilityShow Visibility = "SHOW" VisibilityHide Visibility = "HIDE" )
known visibility values
func (Visibility) IsValid ¶
func (e Visibility) IsValid() bool
IsValid returns true if a visibility value is valid
func (Visibility) MarshalGQL ¶
func (e Visibility) MarshalGQL(w io.Writer)
MarshalGQL writes a visibility value into the supplied writer
func (Visibility) String ¶
func (e Visibility) String() string
func (*Visibility) UnmarshalGQL ¶
func (e *Visibility) UnmarshalGQL(v interface{}) error
UnmarshalGQL reads and validates a visibility value