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 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 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.
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.
Functions ¶
func SubjectMessageReceived ¶
func SubjectMessageReceived(channel chatplatform.ID) string
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).
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 chatplatform.ID, msg chatplatform.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() chatplatform.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.