Documentation
¶
Overview ¶
Package events owns what an event is: the subject names, the CloudEvent types, the schema URNs, and the Go types the bus encodes and decodes.
It is a contract, not a mechanism. The mechanism is gitlab.com/phpboyscout/go/messaging, and requests to make this package own delivery, retries or storage have to explain why they belong somewhere that names none of those (0019 D12).
Index ¶
Constants ¶
const ( FeedbackHelpful = "👍" FeedbackNotHelpful = "👎" )
The feedback emoji (spec 0010 D9). respond offers them and the gateway publishes only them.
const PatternMessageReceived = subjectRoot + ".*"
PatternMessageReceived subscribes to every channel's messages.
A single-token wildcard rather than ">": the subject has exactly one token after the root, so "*" says that and ">" would also admit a deeper subject this contract does not define.
const PatternReactionChanged = reactionSubjectRoot + ".*"
PatternReactionChanged subscribes to every channel's feedback reactions.
const Source = "urn:phpbotscout:gateway"
Source identifies the context these events happened in. Required by Bus.PublishValue, which builds the whole event and so must be told.
const TypeMessageReceived = "uk.phpboyscout.phpbotscout.message.received.v1"
TypeMessageReceived is the CloudEvent type consumers filter on.
const TypeReactionChanged = "uk.phpboyscout.phpbotscout.reaction.changed.v1"
TypeReactionChanged is the CloudEvent type of a feedback reaction.
Variables ¶
var SchemaMessageReceived = urn.Schema{Name: subjectRoot, Version: 1}.String()
SchemaMessageReceived names the shape of a MessageReceived payload (0019 D18).
Emitted on every event and resolved by nothing. It costs one publish option, and it is what lets an event that escapes this process say what it is.
var SchemaReactionChanged = urn.Schema{Name: reactionSubjectRoot, Version: 1}.String()
SchemaReactionChanged names the shape of a ReactionChanged payload.
Functions ¶
func SubjectMessageReceived ¶
SubjectMessageReceived is the subject one channel's messages travel on.
The channel is in the subject so a subscriber can take a slice without receiving what it did not ask for: answering wants the project forums, moderation wants everything a person can read (0019 OQ6).
func SubjectReactionChanged ¶ added in v0.9.0
SubjectReactionChanged is the subject one channel's feedback reactions travel on.
Types ¶
type MessageReceived ¶
type MessageReceived struct {
SpaceID string `json:"space_id"`
ChannelID string `json:"channel_id"`
ThreadID string `json:"thread_id,omitempty"`
ParentID string `json:"parent_id,omitempty"`
MessageID string `json:"message_id"`
AuthorID string `json:"author_id"`
// AuthorIsBot and Addressed are the whole of what a consumer needs to run
// its trigger. Without them the answering path would have to reach back to
// the platform for facts the gateway already had (R-ANS-3, 0010 D2).
AuthorIsBot bool `json:"author_is_bot"`
Addressed bool `json:"addressed"`
Content string `json:"content"`
}
MessageReceived is a Discord message on its way to a consumer.
Identifiers and the message text, and nothing a person chose. A display name is user-controlled and would reach a log line through an attribute that has neither a schema nor a review (0019 D13).
func NewMessageReceived ¶
func NewMessageReceived(space comms.ID, msg comms.Message) MessageReceived
NewMessageReceived builds the payload from a platform message.
The one place the conversion happens, so the rule that no display name crosses it has a single site to hold rather than a convention to remember.
func (MessageReceived) Message ¶
func (m MessageReceived) Message() comms.Message
Message is the platform message a consumer works with, rebuilt from the event. The inverse of NewMessageReceived for everything the event carries: the Author has an id and bot-ness and no name, because the event never had one (0019 D13), and Ref resolves to the same place a reply would have gone.
type ReactionChanged ¶ added in v0.9.0
type ReactionChanged struct {
SpaceID string `json:"space_id"`
ChannelID string `json:"channel_id"`
ThreadID string `json:"thread_id,omitempty"`
MessageID string `json:"message_id"`
UserID string `json:"user_id"`
// Emoji is FeedbackHelpful or FeedbackNotHelpful, normalised.
Emoji string `json:"emoji"`
Removed bool `json:"removed,omitempty"`
}
ReactionChanged is a person adding or removing a feedback emoji (spec 0027). It carries identifiers only: no member, so no display name (0019 D13).
func NewReactionChanged ¶ added in v0.9.0
NewReactionChanged builds the event for a reaction, and reports false for anything that is not a vote: another emoji, or a moderator clearing reactions, which changes no verdict (0027 D6).
func (ReactionChanged) Added ¶ added in v0.9.0
func (r ReactionChanged) Added() bool
Added reports whether the reaction was put on rather than taken off.
func (ReactionChanged) Helpful ¶ added in v0.9.0
func (r ReactionChanged) Helpful() bool
Helpful reports whether the reaction is the helpful one.