types

package module
v1.5.0 Latest Latest
Warning

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

Go to latest
Published: Oct 3, 2022 License: MIT Imports: 4 Imported by: 2

README

Security Rating Maintainability Rating Reliability Rating Code Smells Technical Debt Vulnerabilities Bugs FOSSA Status GoDoc Go Report Card

types

types holds common data structures used across GEC components.

Types

type Message

type Message struct { ... }

Message is, simply, the message to be passed between recipients

func (Message) GetTimestamp

func (m Message) GetTimestamp() time.Time

func (Message) Map

func (m Message) Map() (o map[string]any)

Map returns a map from the message to be placed on a redis XSTREAM (etc.)

type Source

type Source uint8

Source signifies the source of a message; whether it's come in from whatsapp, slack, some kind of auto-responder, or just completely unknown

Constants
const (
    // SourceUnknown is where we simply ust don't know where a message comes from,
    // and is largely only used for zero'd messages, or when errors stop the
    // processing of messages.
    SourceUnknown Source = iota

    // SourceWhatsapp means a message has come from WhatsApp and usually signifies
    // a message from someone seeking advice
    SourceWhatsapp

    // SourceAutoresponse means a message was generated from an application in the
    // processing pipeline somewhere, like the various autoresponses the gec-bot
    // provides
    SourceAutoresponse

    // SourceSlack usually means a message from the GEC _back_ to recipients; though
    // in the future perhaps we'd want to allow slack users to message too...
    // dunno
    SourceSlack
)

Readme created from Go doc with goreadme

Documentation

Overview

types holds common data structures used across GEC components.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Message

type Message struct {
	Source    Source `mapstructure:"source"`
	ID        string `mapstructure:"id"`
	Timestamp int64  `mapstructure:"ts"`
	Message   string `mapstructure:"msg"`
	Sentiment int    `mapstructure:"sentiment"`
}

Message is, simply, the message to be passed between recipients

func NewMessage

func NewMessage(source Source, id, msg string) Message

NewMessage accepts a source, id and string, and returns a new Message

func ParseMessage

func ParseMessage(i map[string]any) (m Message, err error)

ParseMessage accepts a map, probably from redis, and turns it into a valid Message for processing

func (Message) GetTimestamp added in v1.1.0

func (m Message) GetTimestamp() time.Time

GetTimestamp takes the unixtimestamp stored within a Message and returns a localised time.Time based on this.

Note: to get the time in UTC you'll need to do

m.GetTimestamp().UTC()

func (Message) Map

func (m Message) Map() (o map[string]any)

Map returns a map from the message to be placed on a redis XSTREAM (etc.)

type Source

type Source uint8

Source signifies the source of a message; whether it's come in from whatsapp, slack, some kind of auto-responder, or just completely unknown

const (
	// SourceUnknown is where we simply ust don't know where a message comes from,
	// and is largely only used for zero'd messages, or when errors stop the
	// processing of messages.
	SourceUnknown Source = iota

	// SourceWhatsapp means a message has come from WhatsApp and usually signifies
	// a message from someone seeking advice
	SourceWhatsapp

	// SourceAutoresponse means a message was generated from an application in the
	// processing pipeline somewhere, like the various autoresponses the gec-bot
	// provides
	SourceAutoresponse

	// SourceSlack usually means a message from the GEC _back_ to recipients; though
	// in the future perhaps we'd want to allow slack users to message too...
	// dunno
	SourceSlack
)

func (Source) MarshalBinary added in v1.2.0

func (s Source) MarshalBinary() ([]byte, error)

MarshalBinary implements the encoding.BinaryMarshaler interface in order to serialise data to redis correctly

func (*Source) UnmarshalBinary added in v1.2.0

func (s *Source) UnmarshalBinary(data []byte) error

UnmarshalBinary implements the encoding.BinaryUnmarshaler interface in order to serialise data _from_ redis correctly

Jump to

Keyboard shortcuts

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