room

package
v0.0.2 Latest Latest
Warning

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

Go to latest
Published: Apr 24, 2022 License: AGPL-3.0 Imports: 9 Imported by: 0

Documentation

Overview

Package room interfaces with matrix rooms.

Index

Constants

View Source
const MessageEventType = "m.room.message"

MessageEventType indicates a room event is a message.

Variables

This section is empty.

Functions

This section is empty.

Types

type EventWithoutContent

type EventWithoutContent struct {
	EventID               string `json:"event_id"`
	OriginSenderTimestamp int    `json:"origin_server_ts"`
	Sender                string `json:"sender"`
	StateKey              string `json:"state_key"`
	EventType             string `json:"type"`
}

EventWithoutContent represents a room event without the content field. This struct should be extended by more concrete types.

func (EventWithoutContent) IsRoomMessageEvent

func (e EventWithoutContent) IsRoomMessageEvent() bool

IsRoomMessageEvent returns true if the event represents a message sent to a matrix room.

type MessageContent

type MessageContent struct {
	MessageType   string          `json:"msgtype"`
	Body          string          `json:"body"`
	Format        string          `json:"format,omitempty"`
	FormattedBody string          `json:"formatted_body,omitempty"`
	Relates       *MessageRelates `json:"m.relates_to,omitempty"`
}

MessageContent represents the content of room message.

type MessageEvent

type MessageEvent struct {
	EventWithoutContent
	Content MessageContent `struct:"content"`
}

MessageEvent is a message sent to a room.

type MessageReference added in v0.0.2

type MessageReference struct {
	ID   string `json:"event_id"`
	Key  string `json:"key,omitempty"`
	Type string `json:"rel_type,omitempty"`
}

MessageReference references another message.

type MessageRelates added in v0.0.2

type MessageRelates struct {
	RepliesTo MessageReference `json:"m.in_reply_to"`
}

MessageRelates indicates that a message relates so another one.

type OpaqueContent

type OpaqueContent []byte

OpaqueContent is the marshalled form of a room event content.

func (*OpaqueContent) UnmarshalJSON

func (o *OpaqueContent) UnmarshalJSON(b []byte) error

UnmarshalJSON tells the json unmarshaller to leave the content field as is.

type OpaqueEvent

type OpaqueEvent struct {
	EventWithoutContent
	Content OpaqueContent `json:"content,string"`
}

OpaqueEvent is a room event with opaque content.

func (OpaqueEvent) AsRoomMessageEvent

func (r OpaqueEvent) AsRoomMessageEvent() (MessageEvent, error)

AsRoomMessageEvent converts this event to a MessageEvent. Panics if wrong type.

type ReactionContent added in v0.0.2

type ReactionContent struct {
	RelatesTo MessageReference `json:"m.relates_to"`
}

ReactionContent is the payload of a reaction.

type Room

type Room struct {
	// contains filtered or unexported fields
}

Room represents a matrix room.

func New

func New(server *matrix.Matrix, id string) *Room

New creates a new matrix room handle on the given server for the given room ID.

func (*Room) Join

func (r *Room) Join(ctx context.Context) error

Join the room.

func (*Room) SendMessage

func (r *Room) SendMessage(ctx context.Context, text string) error

SendMessage with the given text content to the room.

func (*Room) SendReaction added in v0.0.2

func (r *Room) SendReaction(ctx context.Context, source, key string) error

SendReaction sends a reaction (emoticon) to a given source event id.

func (*Room) SendReply added in v0.0.2

func (r *Room) SendReply(ctx context.Context, source, text string) error

SendReply sends a text reply to the given source event ID.

func (*Room) SyncEvents

func (r *Room) SyncEvents(ctx context.Context, log logr.Logger, handler func(MessageEvent))

SyncEvents of this room and let all messages be handled by handler.

Jump to

Keyboard shortcuts

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