Documentation
¶
Index ¶
- Constants
- type CompletedRequest
- func (creq CompletedRequest) CheckStatus(expected int) bool
- func (creq CompletedRequest) CheckStatusOK() bool
- func (creq CompletedRequest) Close()
- func (creq CompletedRequest) JSON(decodeInto interface{}) error
- func (creq CompletedRequest) OK() bool
- func (creq CompletedRequest) Text() (string, error)
- type Event
- type EventContainer
- type EventContent
- type Invite
- type InvitedRoom
- type LeftRoom
- type MatrixBot
- func (mx *MatrixBot) DummyLogin() error
- func (mx *MatrixBot) GetRoom(roomID string) *Room
- func (mx *MatrixBot) GetURL(path string, args ...interface{}) string
- func (mx *MatrixBot) Join(roomID string) error
- func (mx *MatrixBot) Listen()
- func (mx *MatrixBot) NewJSONRequest(payload interface{}, url string, urlArgs ...interface{}) Request
- func (mx *MatrixBot) NewPlainRequest(url string, urlArgs ...interface{}) Request
- func (mx *MatrixBot) NewRequest(payload, contentType, url string, urlArgs ...interface{}) Request
- func (mx *MatrixBot) NextTransactionID() int
- func (mx *MatrixBot) PasswordLogin(user, password string) error
- func (mx *MatrixBot) SetToken(user, token string) error
- func (mx *MatrixBot) Stop()
- func (mx *MatrixBot) Sync() error
- type Member
- type Request
- type Room
- func (r *Room) Emote(message string) (SendResponse, error)
- func (r *Room) Send(message string) (SendResponse, error)
- func (r *Room) SendHTML(message string) (SendResponse, error)
- func (r *Room) Sendf(message string, args ...interface{}) (SendResponse, error)
- func (r *Room) SendfHTML(message string, args ...interface{}) (SendResponse, error)
- type SRoom
- type SendResponse
- type SyncData
- type SyncRooms
- type Timeline
- type Unsigned
Constants ¶
const ( EvtRoomAliases = "m.room.aliases" EvtRoomCanonicalAlias = "m.room.canonical_alias" EvtRoomCreate = "m.room.create" EvtRoomJoinRules = "m.room.join_rules" EvtRoomMember = "m.room.member" EvtRoomPowerLevels = "m.room.power_levels" EvtRoomRedaction = "m.room.redaction" EvtRoomHistoryVisibility = "m.room.history_visibility" EvtRoomThirdPartyInvite = "m.room.third_party_invite" EvtRoomGuestAccess = "m.room.guest_access" )
Room events
const ( EvtRoomMessage = "m.room.message" EvtRoomMessageFeedback = "m.room.message.feedback" EvtRoomName = "m.room.name" EvtRoomTopic = "m.room.topic" EvtRoomAvatar = "m.room.avatar" )
Instant messaging events
const ( MsgText = "m.text" MsgEmote = "m.emote" MsgNotice = "m.notice" MsgImage = "m.image" MsgFile = "m.file" MsgLocation = "m.location" MsgVideo = "m.video" MsgAudio = "m.audio" )
Message types
const ( LoginPassword = "m.login.password" LoginReCAPTCHA = "m.login.recaptcha" LoginOAuth2 = "m.login.oauth2" LoginEmailIdent = "m.login.email.identity" LoginToken = "m.login.token" LoginDummy = "m.login.dummy" )
Login types
const ( EvtCallInvite = "m.call.invite" EvtCallCandidates = "m.call.candidates" EvtCallAnswer = "m.call.answer" EvtCallHangup = "m.call.hangup" )
VoIP events
const ( EvtTyping = "m.typing" EvtReceipt = "m.receipt" EvtRead = "m.read" EvtPresence = "m.presence" )
Presence events
const (
EvtTag = "m.tag"
)
Room tagging
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type CompletedRequest ¶
CompletedRequest is a Matrix API request that has been called.
func (CompletedRequest) CheckStatus ¶
func (creq CompletedRequest) CheckStatus(expected int) bool
CheckStatus makes sure that the response HTTP status code is correct.
func (CompletedRequest) CheckStatusOK ¶
func (creq CompletedRequest) CheckStatusOK() bool
CheckStatusOK makes sure that the response HTTP status code is OK 200.
func (CompletedRequest) Close ¶
func (creq CompletedRequest) Close()
Close closes the response body stream.
func (CompletedRequest) JSON ¶
func (creq CompletedRequest) JSON(decodeInto interface{}) error
JSON reads the body of the response and parses it from JSON into an interface.
func (CompletedRequest) OK ¶
func (creq CompletedRequest) OK() bool
OK checks if the request completed successfully.
func (CompletedRequest) Text ¶
func (creq CompletedRequest) Text() (string, error)
Text reads the body of the response and returns it as a string.
type Event ¶
type Event struct { ID string `json:"event_id"` Type string `json:"type"` Sender string `json:"sender"` StateKey string `json:"state_key"` Content map[string]interface{} `json:"content"` OriginServerTime int64 `json:"origin_server_ts"` Age int64 `json:"age"` TransactionID string `json:"txn_id"` Unsigned Unsigned `json:"unsigned"` Room *Room `json:"-"` }
Event represents a single event
func (Event) CanMarkRead ¶
CanMarkRead checks if the event can be marked as read
type EventContainer ¶
type EventContainer struct {
Events []Event `json:"events"`
}
EventContainer contains an array of events
type EventContent ¶
EventContent contains the name and body of an event
type Invite ¶
type Invite struct { Sender string Name string ID string Members map[string]string Session *MatrixBot }
Invite wraps an invite to a room
type InvitedRoom ¶
type InvitedRoom struct {
InviteState EventContainer `json:"invite_state"`
}
InvitedRoom is a room that the user has been invited to
type LeftRoom ¶
type LeftRoom struct { // Member list and other persistent data State EventContainer `json:"state"` // Messages, state changes, etc.. Timeline EventContainer `json:"timeline"` }
LeftRoom is a room the user has left or been banned from
type MatrixBot ¶
type MatrixBot struct { NextBatch string Rooms map[string]*Room Invites map[string]*Invite Presence map[string]string AccessToken string MatrixID string HomeServer string TxnID int Timeline chan Event InviteChan chan string JoinChan chan string // contains filtered or unexported fields }
MatrixBot is a client-server Matrix session
func (*MatrixBot) DummyLogin ¶
DummyLogin tries to log in without authentication
func (*MatrixBot) NewJSONRequest ¶
func (mx *MatrixBot) NewJSONRequest(payload interface{}, url string, urlArgs ...interface{}) Request
NewJSONRequest creates a new Matrix API request and marshals the given object to JSON and uses it as the payload.
func (*MatrixBot) NewPlainRequest ¶
NewPlainRequest creates a new payloadless Matrix API request.
func (*MatrixBot) NewRequest ¶
NewRequest creates a new Matrix API request with a custom payload.
func (*MatrixBot) NextTransactionID ¶
NextTransactionID returns the next message transaction ID
func (*MatrixBot) PasswordLogin ¶
PasswordLogin tries to log in with username and password
type Request ¶
Request wraps a Matrix API request.
func (Request) GET ¶
func (req Request) GET() CompletedRequest
GET executes this request with HTTP GET.
func (Request) HTTP ¶
func (req Request) HTTP(method string) CompletedRequest
HTTP executes this request with the given HTTP method.
func (Request) POST ¶
func (req Request) POST() CompletedRequest
POST executes this request with HTTP POST.
func (Request) PUT ¶
func (req Request) PUT() CompletedRequest
PUT executes this request with HTTP PUT.
type Room ¶
type Room struct { ID string Name string Members map[string]Member Aliases []string Session *MatrixBot }
Room is a room
func (*Room) Emote ¶
func (r *Room) Emote(message string) (SendResponse, error)
Send emote message to this room
func (*Room) Send ¶
func (r *Room) Send(message string) (SendResponse, error)
Send sends a message to this room
func (*Room) SendHTML ¶
func (r *Room) SendHTML(message string) (SendResponse, error)
SendHTML sends a HTML message to this room
type SRoom ¶
type SRoom struct { // Typing notifications, presence updates, etc.. Ephemeral EventContainer `json:"ephemeral"` // Member list and other persistent data State EventContainer `json:"state"` // Messages, state changes, etc.. Timeline Timeline `json:"timeline"` // Tags and custom configs AccountData EventContainer `json:"account_data"` }
SRoom represents a single room
type SendResponse ¶
type SendResponse struct { EventID string `json:"event_id"` Error string `json:"error"` ErrorCode string `json:"errcode"` }
SendResponse wraps the response to a room send request
type SyncData ¶
type SyncData struct { NextBatch string `json:"next_batch"` Rooms SyncRooms `json:"rooms"` Presence EventContainer `json:"presence"` Initial bool `json:"-"` }
SyncData contains everything in a single synchronization
type SyncRooms ¶
type SyncRooms struct { Join map[string]SRoom `json:"join"` Invited map[string]InvitedRoom `json:"invite"` Leave map[string]LeftRoom `json:"leave"` }
SyncRooms contains all joined and invited rooms
type Timeline ¶
type Timeline struct { EventContainer Limited bool `json:"limited"` PrevBatch string `json:"prev_batch"` }
Timeline wraps things in a timeline