type Client struct { HomeserverURL *url.URL Prefix string UserID string AccessToken string Rooms map[string]*Room Worker *Worker NextBatchStorer NextBatchStorer ClientConfig api.ClientConfig // contains filtered or unexported fields }
Client represents a Matrix client.
func NewClient(httpClient *http.Client, homeserverURL *url.URL, accessToken, userID string) *Client
NewClient creates a new Matrix Client ready for syncing
func (cli *Client) JoinRoom(roomIDorAlias, serverName, invitingUserID string) (string, error)
JoinRoom joins the client to a room ID or alias. If serverName is specified, this will be added as a query param to instruct the homeserver to join via that server. If invitingUserID is specified, the inviting user ID will be inserted into the content of the join request. Returns a room ID.
func (cli *Client) SendMessageEvent(roomID string, eventType string, contentJSON interface{}) (string, error)
SendMessageEvent sends a message event into a room, returning the event_id on success. contentJSON should be a pointer to something that can be encoded as JSON using json.Marshal.
func (cli *Client) SendText(roomID, text string) (string, error)
SendText sends an m.room.message event into the given room with a msgtype of m.text
func (cli *Client) SetDisplayName(displayName string) error
SetDisplayName sets the user's profile display name
func (cli *Client) StopSync()
StopSync stops the ongoing sync started by Sync.
func (cli *Client) Sync()
Sync starts syncing with the provided Homeserver. This function will be invoked continually. If Sync is called twice then the first sync will be stopped.
func (cli *Client) UploadLink(link string) (string, error)
UploadLink uploads an HTTP URL and then returns an MXC URI.
func (cli *Client) UploadToContentRepo(content io.Reader, contentType string, contentLength int64) (string, error)
UploadToContentRepo uploads the given bytes to the content repository and returns an MXC URI.
type Event struct { StateKey string `json:"state_key"` // The state key for the event. Only present on State Events. Sender string `json:"sender"` // The user ID of the sender of the event Type string `json:"type"` // The event type Timestamp int `json:"origin_server_ts"` // The unix timestamp when this message was sent by the origin server ID string `json:"event_id"` // The unique ID of this event RoomID string `json:"room_id"` // The room the event was sent to. May be nil (e.g. for presence) Content map[string]interface{} `json:"content"` // The JSON content of the event. }
Event represents a single Matrix event.
func (event *Event) Body() (body string, ok bool)
Body returns the value of the "body" key in the event content if it is present and is a string.
func (event *Event) MessageType() (msgtype string, ok bool)
MessageType returns the value of the "msgtype" key in the event content if it is present and is a string.
type HTMLMessage struct { Body string `json:"body"` MsgType string `json:"msgtype"` Format string `json:"format"` FormattedBody string `json:"formatted_body"` }
An HTMLMessage is the contents of a Matrix HTML formated message event.
func GetHTMLMessage(msgtype, htmlText string) HTMLMessage
GetHTMLMessage returns an HTMLMessage with the body set to a stripped version of the provided HTML, in addition to the provided HTML.
type ImageInfo struct { Height uint `json:"h"` Width uint `json:"w"` Mimetype string `json:"mimetype"` Size uint `json:"size"` }
ImageInfo contains info about an image
type ImageMessage struct { MsgType string `json:"msgtype"` Body string `json:"body"` URL string `json:"url"` Info ImageInfo `json:"info"` }
ImageMessage is an m.image event
type NextBatchStorer interface { // Save a next_batch token for a given user. Best effort. Save(userID, nextBatch string) // Load a next_batch token for a given user. Return an empty string if no token exists. Load(userID string) string }
NextBatchStorer controls loading/saving of next_batch tokens for users
type OnEventListener func(*Event)
OnEventListener can be used with Worker.OnEventType to be informed of incoming events.
type Room struct { ID string State map[string]map[string]*Event Timeline []Event }
Room represents a single Matrix room.
func NewRoom(roomID string) *Room
NewRoom creates a new Room with the given ID
func (room Room) GetMembershipState(userID string) string
GetMembershipState returns the membership state of the given user ID in this room. If there is no entry for this member, 'leave' is returned for consistency with left users.
func (room Room) GetStateEvent(eventType string, stateKey string) *Event
GetStateEvent returns the state event for the given type/state_key combo, or nil.
func (room Room) UpdateState(event *Event)
UpdateState updates the room's current state with the given Event. This will clobber events based on the type/state_key combination.
type StarterLinkMessage struct { Body string Link string }
StarterLinkMessage represents a message with a starter_link custom data.
func (m StarterLinkMessage) MarshalJSON() ([]byte, error)
MarshalJSON converts this message into actual event content JSON.
type TextMessage struct { MsgType string `json:"msgtype"` Body string `json:"body"` }
TextMessage is the contents of a Matrix formated message event.
type Worker struct {
// contains filtered or unexported fields
}
Worker processes incoming events and updates the Matrix client's data structures. It also informs any attached listeners of the new events.
func (worker *Worker) OnEventType(eventType string, callback OnEventListener)
OnEventType allows callers to be notified when there are new events for the given event type. There are no duplicate checks.