asyncmessenger

package
v1.9.3 Latest Latest
Warning

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

Go to latest
Published: Apr 23, 2024 License: GPL-3.0 Imports: 14 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrRetriesExceeded = errors.New("amount of retries exceeded")
)

Errors returned by the messenger

Functions

This section is empty.

Types

type ChannelResponse

type ChannelResponse struct {
	ChannelExternalIdentifier string
	UserIdentifier            string
}

ChannelResponse holds information about a channel

type Delete

type Delete struct {
	ExternalIdentifier        string
	ChannelExternalIdentifier string
}

Delete holds information about a delete request

type MatrixClient

type MatrixClient interface {
	SendMessageEvent(roomID id.RoomID, eventType event.Type, contentJSON interface{}, extra ...mautrix.ReqSendEvent) (resp *mautrix.RespSendEvent, err error)
	RedactEvent(roomID id.RoomID, eventID id.EventID, extra ...mautrix.ReqRedact) (resp *mautrix.RespSendEvent, err error)
	JoinedMembers(roomID id.RoomID) (resp *mautrix.RespJoinedMembers, err error)
	CreateRoom(req *mautrix.ReqCreateRoom) (resp *mautrix.RespCreateRoom, err error)
}

MatrixClient defines an interface to wrap the matrix API

type Message

type Message struct {
	Body                      string // Plain text message use \n for newlines
	BodyHTML                  string // HTML formatted message - optional
	ResponseToMessage         string // ID of a message to respond to - optional
	ChannelExternalIdentifier string // Channel ID to send the message to
}

Message holds information about a message

func HTMLMessage

func HTMLMessage(plaintextMessage, htmlMessage, channelIdentifier string) *Message

HTMLMessage constructs a simple HTML message with a plaintext fallback

func PlainTextMessage

func PlainTextMessage(message string, channelIdentifier string) *Message

PlainTextMessage constructs a simple plain text message

type MessageResponse

type MessageResponse struct {
	ExternalIdentifier string
	Timestamp          int64
}

type Messenger

type Messenger interface {
	SendMessageAsync(message *Message) error
	SendMessage(message *Message) (*MessageResponse, error)
	SendReactionAsync(reaction *Reaction) error
	SendResponseAsync(response *Response) error
	SendResponse(response *Response) (*MessageResponse, error)
	SendRedactAsync(redact *Redact) error
	CreateChannel(userID string) (*ChannelResponse, error)
	DeleteMessageAsync(deleteAction *Delete) error
}

Messenger provides an interface for sending and handling matrix events The Queue... methods work asynchronous but do not provide any information about the sent message The Send... methods work snchronous and provide more detailed feedback, they can be used asynchronous

func NewMessenger

func NewMessenger(debug bool, config *configuration.Config, db types.Database, cryptoStore crypto.Store, stateStore *encryption.StateStore, matrixClient *mautrix.Client) (Messenger, error)

type Reaction

type Reaction struct {
	Reaction                  string
	MessageExternalIdentifier string
	ChannelExternalIdentifier string
}

type Redact

type Redact struct {
	RoomID    string
	MessageID string
}

type Response

type Response struct {
	Message                   string
	MessageFormatted          string
	RespondToMessage          string
	RespondToMessageFormatted string
	RespondToUserID           string
	RespondToEventID          string
	ChannelExternalIdentifier string
}

func PlainTextResponse

func PlainTextResponse(msg, replyToEventID, replyToMessage, replyToUser, channelIdentifier string) *Response

func (*Response) GetResponseMessage

func (response *Response) GetResponseMessage() (message, messageFormatted string)

Jump to

Keyboard shortcuts

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