Documentation ¶
Index ¶
- Constants
- Variables
- func NewApi(homeserverUrl *url.URL) (*api, error)
- type Api
- type AuthType
- type BaseAuthData
- type CrossSigningKeys
- type DeviceIDList
- type DeviceKeys
- type DeviceKeysRequest
- type HTTPError
- type IdentifierType
- type KeyMap
- type LazyLoadSummary
- type OneTimeKey
- type OneTimeKeysCount
- type OneTimeKeysRequest
- type ReqAliasCreate
- type ReqBanUser
- type ReqClaimKeys
- type ReqCreateRoom
- type ReqDeleteDevice
- type ReqDeleteDevices
- type ReqDeviceInfo
- type ReqInvite3PID
- type ReqInviteUser
- type ReqKeysSignatures
- type ReqKickUser
- type ReqLogin
- type ReqMembers
- type ReqPresence
- type ReqPutPushRule
- type ReqQueryKeys
- type ReqRedact
- type ReqRegister
- type ReqSendToDevice
- type ReqTyping
- type ReqUIAuthFallback
- type ReqUIAuthLogin
- type ReqUnbanUser
- type ReqUploadKeys
- type ReqUploadSignatures
- type RespAliasCreate
- type RespAliasDelete
- type RespAliasResolve
- type RespBanUser
- type RespClaimKeys
- type RespCreateFilter
- type RespCreateRoom
- type RespDeviceInfo
- type RespDevicesInfo
- type RespError
- type RespForgetRoom
- type RespInviteUser
- type RespJoinRoom
- type RespJoinedMembers
- type RespJoinedRooms
- type RespKeyChanges
- type RespKickUser
- type RespLeaveRoom
- type RespLogin
- type RespLoginFlows
- type RespLogout
- type RespMediaUpload
- type RespMembers
- type RespMessages
- type RespQueryKeys
- type RespRegister
- type RespSendEvent
- type RespSendToDevice
- type RespSync
- type RespTurnServer
- type RespTyping
- type RespUnbanUser
- type RespUploadKeys
- type RespUploadSignatures
- type RespUserDisplayName
- type RespUserInteractive
- type RespVersions
- type RespWhoami
- type Signatures
- type SyncInvitedRoom
- type SyncJoinedRoom
- type SyncLeftRoom
- type UploadCrossSigningKeysReq
- type UserIdentifier
Constants ¶
const ( AuthTypePassword = "m.login.password" AuthTypeReCAPTCHA = "m.login.recaptcha" AuthTypeOAuth2 = "m.login.oauth2" AuthTypeSSO = "m.login.sso" AuthTypeEmail = "m.login.email.identity" AuthTypeMSISDN = "m.login.msisdn" AuthTypeToken = "m.login.token" AuthTypeDummy = "m.login.dummy" AuthTypeAppservice = "uk.half-shot.msc2778.login.application_service" )
const ( IdentifierTypeUser = "m.id.user" IdentifierTypeThirdParty = "m.id.thirdparty" IdentifierTypePhone = "m.id.phone" )
const DefaultContentType = "application/json"
Variables ¶
var ( // Forbidden access, e.g. joining a room without permission, failed login. MForbidden = RespError{ErrCode: "M_FORBIDDEN"} // The access token specified was not recognised. MUnknownToken = RespError{ErrCode: "M_UNKNOWN_TOKEN"} // No access token was specified for the request. MMissingToken = RespError{ErrCode: "M_MISSING_TOKEN"} // Request contained valid JSON, but it was malformed in some way, e.g. missing required keys, invalid values for keys. MBadJSON = RespError{ErrCode: "M_BAD_JSON"} // Request did not contain valid JSON. MNotJSON = RespError{ErrCode: "M_NOT_JSON"} // No resource was found for this request. MNotFound = RespError{ErrCode: "M_NOT_FOUND"} // Too many requests have been sent in a short period of time. Wait a while then try again. MLimitExceeded = RespError{ErrCode: "M_LIMIT_EXCEEDED"} // The user ID associated with the request has been deactivated. // Typically for endpoints that prove authentication, such as /login. MUserDeactivated = RespError{ErrCode: "M_USER_DEACTIVATED"} // Encountered when trying to register a user ID which has been taken. MUserInUse = RespError{ErrCode: "M_USER_IN_USE"} // Encountered when trying to register a user ID which is not valid. MInvalidUsername = RespError{ErrCode: "M_INVALID_USERNAME"} // Sent when the room alias given to the createRoom API is already in use. MRoomInUse = RespError{ErrCode: "M_ROOM_IN_USE"} // The state change requested cannot be performed, such as attempting to unban a user who is not banned. MBadState = RespError{ErrCode: "M_BAD_STATE"} // The request or entity was too large. MTooLarge = RespError{ErrCode: "M_TOO_LARGE"} // The resource being requested is reserved by an application service, or the application service making the request has not created the resource. MExclusive = RespError{ErrCode: "M_EXCLUSIVE"} // The client's request to create a room used a room version that the server does not support. MUnsupportedRoomVersion = RespError{ErrCode: "M_UNSUPPORTED_ROOM_VERSION"} // The client attempted to join a room that has a version the server does not support. // Inspect the room_version property of the error response for the room's version. MIncompatibleRoomVersion = RespError{ErrCode: "M_INCOMPATIBLE_ROOM_VERSION"} )
Common error codes from https://matrix.org/docs/spec/client_server/latest#api-standards
Can be used with errors.Is() to check the response code without casting the error:
err := client.Sync() if errors.Is(err, MUnknownToken) { // logout }
var (
ErrEmptyHomeserver = errors.New("empty homeserver url")
)
Functions ¶
Types ¶
type BaseAuthData ¶
type CrossSigningKeys ¶
type CrossSigningKeys struct { UserID id.UserID `json:"user_id"` Usage []id.CrossSigningUsage `json:"usage"` Keys map[id.KeyID]id.Ed25519 `json:"keys"` Signatures map[id.UserID]map[id.KeyID]string `json:"signatures,omitempty"` }
func (*CrossSigningKeys) FirstKey ¶
func (csk *CrossSigningKeys) FirstKey() id.Ed25519
type DeviceIDList ¶
type DeviceKeys ¶
type DeviceKeysRequest ¶
type DeviceKeysRequest map[id.UserID]DeviceIDList
type HTTPError ¶
type HTTPError struct { Request *fasthttp.Request Response *fasthttp.Response ResponseBody string WrappedError error RespError *RespError Message string }
HTTPError An HTTP Error response, which may wrap an underlying native Go Error.
type IdentifierType ¶
type IdentifierType string
type KeyMap ¶
type KeyMap map[id.DeviceKeyID]string
func (KeyMap) GetCurve25519 ¶
func (km KeyMap) GetCurve25519(deviceID id.DeviceID) id.Curve25519
type LazyLoadSummary ¶
type OneTimeKey ¶
type OneTimeKey struct { Key id.Curve25519 `json:"key"` IsSigned bool `json:"-"` Signatures Signatures `json:"signatures,omitempty"` Unsigned map[string]interface{} `json:"unsigned,omitempty"` }
func (*OneTimeKey) MarshalJSON ¶
func (otk *OneTimeKey) MarshalJSON() ([]byte, error)
func (*OneTimeKey) UnmarshalJSON ¶
func (otk *OneTimeKey) UnmarshalJSON(data []byte) (err error)
type OneTimeKeysCount ¶
type OneTimeKeysRequest ¶
type ReqAliasCreate ¶
type ReqBanUser ¶
type ReqBanUser struct { Reason string `json:"reason,omitempty"` UserID id.UserID `json:"user_id"` }
ReqBanUser is the JSON request for http://matrix.org/docs/spec/client_server/r0.2.0.html#post-matrix-client-r0-rooms-roomid-ban
type ReqClaimKeys ¶
type ReqClaimKeys struct { OneTimeKeys OneTimeKeysRequest `json:"one_time_keys"` Timeout int64 `json:"timeout,omitempty"` }
type ReqCreateRoom ¶
type ReqCreateRoom struct { Visibility string `json:"visibility,omitempty"` RoomAliasName string `json:"room_alias_name,omitempty"` Name string `json:"name,omitempty"` Topic string `json:"topic,omitempty"` Invite []id.UserID `json:"invite,omitempty"` Invite3PID []ReqInvite3PID `json:"invite_3pid,omitempty"` CreationContent map[string]interface{} `json:"creation_content,omitempty"` InitialState []*event.Event `json:"initial_state,omitempty"` Preset string `json:"preset,omitempty"` IsDirect bool `json:"is_direct,omitempty"` }
ReqCreateRoom is the JSON request for https://matrix.org/docs/spec/client_server/r0.2.0.html#post-matrix-client-r0-createroom
type ReqDeleteDevice ¶
type ReqDeleteDevice struct {
Auth interface{} `json:"auth,omitempty"`
}
ReqDeleteDevice is the JSON request for https://matrix.org/docs/spec/client_server/r0.6.1#delete-matrix-client-r0-devices-deviceid
type ReqDeleteDevices ¶
type ReqDeleteDevices struct { Devices []id.DeviceID `json:"devices"` Auth interface{} `json:"auth,omitempty"` }
ReqDeleteDevices is the JSON request for https://matrix.org/docs/spec/client_server/r0.6.1#post-matrix-client-r0-delete-devices
type ReqDeviceInfo ¶
type ReqDeviceInfo struct {
DisplayName string `json:"display_name,omitempty"`
}
ReqDeviceInfo is the JSON request for https://matrix.org/docs/spec/client_server/r0.6.1#put-matrix-client-r0-devices-deviceid
type ReqInvite3PID ¶
type ReqInvite3PID struct { IDServer string `json:"id_server"` Medium string `json:"medium"` Address string `json:"address"` }
ReqInvite3PID is the JSON request for https://matrix.org/docs/spec/client_server/r0.2.0.html#id57 It is also a JSON object used in https://matrix.org/docs/spec/client_server/r0.2.0.html#post-matrix-client-r0-createroom
type ReqInviteUser ¶
ReqInviteUser is the JSON request for http://matrix.org/docs/spec/client_server/r0.2.0.html#post-matrix-client-r0-rooms-roomid-invite
type ReqKeysSignatures ¶
type ReqKeysSignatures struct { UserID id.UserID `json:"user_id"` DeviceID id.DeviceID `json:"device_id,omitempty"` Algorithms []id.Algorithm `json:"algorithms,omitempty"` Usage []id.CrossSigningUsage `json:"usage,omitempty"` Keys map[id.KeyID]string `json:"keys"` Signatures Signatures `json:"signatures"` }
type ReqKickUser ¶
type ReqKickUser struct { Reason string `json:"reason,omitempty"` UserID id.UserID `json:"user_id"` }
ReqKickUser is the JSON request for http://matrix.org/docs/spec/client_server/r0.2.0.html#post-matrix-client-r0-rooms-roomid-kick
type ReqLogin ¶
type ReqLogin struct { Type AuthType `json:"type"` Identifier UserIdentifier `json:"identifier"` Password string `json:"password,omitempty"` Token string `json:"token,omitempty"` DeviceID id.DeviceID `json:"device_id,omitempty"` InitialDeviceDisplayName string `json:"initial_device_display_name,omitempty"` }
ReqLogin is the JSON request for http://matrix.org/docs/spec/client_server/r0.2.0.html#post-matrix-client-r0-login
type ReqMembers ¶
type ReqMembers struct { At string `json:"at"` Membership event.Membership `json:"membership,omitempty"` NotMembership event.Membership `json:"not_membership,omitempty"` }
type ReqPresence ¶
type ReqPutPushRule ¶
type ReqPutPushRule struct { Before string `json:"-"` After string `json:"-"` Actions []pushrules.PushActionType `json:"actions"` Conditions []pushrules.PushCondition `json:"conditions"` Pattern string `json:"pattern"` }
type ReqQueryKeys ¶
type ReqQueryKeys struct { DeviceKeys DeviceKeysRequest `json:"device_keys"` Timeout int64 `json:"timeout,omitempty"` Token string `json:"token,omitempty"` }
type ReqRedact ¶
ReqRedact is the JSON request for http://matrix.org/docs/spec/client_server/r0.2.0.html#put-matrix-client-r0-rooms-roomid-redact-eventid-txnid
type ReqRegister ¶
type ReqRegister struct { Username string `json:"username,omitempty"` BindEmail bool `json:"bind_email,omitempty"` Password string `json:"password,omitempty"` DeviceID id.DeviceID `json:"device_id,omitempty"` InitialDeviceDisplayName string `json:"initial_device_display_name"` Auth interface{} `json:"auth,omitempty"` }
ReqRegister is the JSON request for http://matrix.org/docs/spec/client_server/r0.2.0.html#post-matrix-client-r0-register
type ReqSendToDevice ¶
type ReqTyping ¶
ReqTyping is the JSON request for https://matrix.org/docs/spec/client_server/r0.2.0.html#put-matrix-client-r0-rooms-roomid-typing-userid
type ReqUIAuthFallback ¶
type ReqUIAuthLogin ¶
type ReqUIAuthLogin struct { BaseAuthData User string `json:"user"` Password string `json:"password"` }
type ReqUnbanUser ¶
ReqUnbanUser is the JSON request for http://matrix.org/docs/spec/client_server/r0.2.0.html#post-matrix-client-r0-rooms-roomid-unban
type ReqUploadKeys ¶
type ReqUploadKeys struct { DeviceKeys *DeviceKeys `json:"device_keys,omitempty"` OneTimeKeys map[id.KeyID]OneTimeKey `json:"one_time_keys"` }
type ReqUploadSignatures ¶
type ReqUploadSignatures map[id.UserID]map[string]ReqKeysSignatures
type RespAliasCreate ¶
type RespAliasCreate struct{}
type RespAliasDelete ¶
type RespAliasDelete struct{}
type RespAliasResolve ¶
type RespBanUser ¶
type RespBanUser struct{}
RespBanUser is the JSON response for http://matrix.org/docs/spec/client_server/r0.2.0.html#post-matrix-client-r0-rooms-roomid-ban
type RespClaimKeys ¶
type RespCreateFilter ¶
type RespCreateFilter struct {
FilterID string `json:"filter_id"`
}
RespCreateFilter is the JSON response for http://matrix.org/docs/spec/client_server/r0.2.0.html#post-matrix-client-r0-user-userid-filter
type RespCreateRoom ¶
RespCreateRoom is the JSON response for https://matrix.org/docs/spec/client_server/r0.6.0.html#post-matrix-client-r0-createroom
type RespDeviceInfo ¶
type RespDeviceInfo struct { DeviceID id.DeviceID `json:"device_id"` DisplayName string `json:"display_name"` LastSeenIP string `json:"last_seen_ip"` LastSeenTS int64 `json:"last_seen_ts"` }
RespDeviceInfo is the JSON response for https://matrix.org/docs/spec/client_server/r0.6.1#get-matrix-client-r0-devices-deviceid
type RespDevicesInfo ¶
type RespDevicesInfo struct {
Devices []RespDeviceInfo `json:"devices"`
}
RespDevicesInfo is the JSON response for https://matrix.org/docs/spec/client_server/r0.6.1#get-matrix-client-r0-devices
type RespError ¶
RespError is the standard JSON error response from Homeservers. It also implements the Golang "error" interface. See http://matrix.org/docs/spec/client_server/r0.6.1.html#api-standards
func (*RespError) MarshalJSON ¶
func (*RespError) UnmarshalJSON ¶
type RespForgetRoom ¶
type RespForgetRoom struct{}
RespForgetRoom is the JSON response for http://matrix.org/docs/spec/client_server/r0.2.0.html#post-matrix-client-r0-rooms-roomid-forget
type RespInviteUser ¶
type RespInviteUser struct{}
RespInviteUser is the JSON response for http://matrix.org/docs/spec/client_server/r0.2.0.html#post-matrix-client-r0-rooms-roomid-invite
type RespJoinRoom ¶
RespJoinRoom is the JSON response for http://matrix.org/docs/spec/client_server/r0.2.0.html#post-matrix-client-r0-rooms-roomid-join
type RespJoinedMembers ¶
type RespJoinedMembers struct { Joined map[id.UserID]struct { DisplayName *string `json:"display_name"` AvatarURL *string `json:"avatar_url"` } `json:"joined"` }
RespJoinedMembers is the JSON response for https://matrix.org/docs/spec/client_server/r0.4.0.html#get-matrix-client-r0-joined-rooms
type RespJoinedRooms ¶
RespJoinedRooms is the JSON response for https://matrix.org/docs/spec/client_server/r0.4.0.html#get-matrix-client-r0-joined-rooms
type RespKeyChanges ¶
type RespKickUser ¶
type RespKickUser struct{}
RespKickUser is the JSON response for http://matrix.org/docs/spec/client_server/r0.2.0.html#post-matrix-client-r0-rooms-roomid-kick
type RespLeaveRoom ¶
type RespLeaveRoom struct{}
RespLeaveRoom is the JSON response for http://matrix.org/docs/spec/client_server/r0.2.0.html#post-matrix-client-r0-rooms-roomid-leave
type RespLogin ¶
type RespLogin struct { AccessToken string `json:"access_token"` DeviceID id.DeviceID `json:"device_id"` UserID id.UserID `json:"user_id"` }
RespLogin is the JSON response for http://matrix.org/docs/spec/client_server/r0.2.0.html#post-matrix-client-r0-login
type RespLoginFlows ¶
type RespLoginFlows struct { Flows []struct { Type AuthType `json:"type"` } `json:"flows"` }
func (*RespLoginFlows) HasFlow ¶
func (rlf *RespLoginFlows) HasFlow(flowType AuthType) bool
type RespLogout ¶
type RespLogout struct{}
RespLogout is the JSON response for http://matrix.org/docs/spec/client_server/r0.2.0.html#post-matrix-client-r0-logout
type RespMediaUpload ¶
type RespMediaUpload struct {
ContentURI id.ContentURI `json:"content_uri"`
}
RespMediaUpload is the JSON response for http://matrix.org/docs/spec/client_server/r0.2.0.html#post-matrix-media-r0-upload
type RespMembers ¶
type RespMessages ¶
type RespMessages struct { Start string `json:"start"` Chunk []*event.Event `json:"chunk"` State []*event.Event `json:"state"` End string `json:"end"` }
RespMessages is the JSON response for https://matrix.org/docs/spec/client_server/r0.2.0.html#get-matrix-client-r0-rooms-roomid-messages
type RespQueryKeys ¶
type RespQueryKeys struct { Failures map[string]interface{} `json:"failures"` DeviceKeys map[id.UserID]map[id.DeviceID]DeviceKeys `json:"device_keys"` MasterKeys map[id.UserID]CrossSigningKeys `json:"master_keys"` SelfSigningKeys map[id.UserID]CrossSigningKeys `json:"self_signing_keys"` UserSigningKeys map[id.UserID]CrossSigningKeys `json:"user_signing_keys"` }
type RespRegister ¶
type RespRegister struct { AccessToken string `json:"access_token"` DeviceID id.DeviceID `json:"device_id"` HomeServer string `json:"home_server"` RefreshToken string `json:"refresh_token"` UserID id.UserID `json:"user_id"` }
RespRegister is the JSON response for http://matrix.org/docs/spec/client_server/r0.2.0.html#post-matrix-client-r0-register
type RespSendEvent ¶
RespSendEvent is the JSON response for http://matrix.org/docs/spec/client_server/r0.2.0.html#put-matrix-client-r0-rooms-roomid-send-eventtype-txnid
type RespSendToDevice ¶
type RespSendToDevice struct{}
type RespSync ¶
type RespSync struct { NextBatch string `json:"next_batch"` AccountData struct { Events []*event.Event `json:"events"` } `json:"account_data"` Presence struct { Events []*event.Event `json:"events"` } `json:"presence"` ToDevice struct { Events []*event.Event `json:"events"` } `json:"to_device"` DeviceLists struct { Changed []id.UserID `json:"changed"` Left []id.UserID `json:"left"` } `json:"device_lists"` DeviceOneTimeKeysCount OneTimeKeysCount `json:"device_one_time_keys_count"` Rooms struct { Leave map[id.RoomID]SyncLeftRoom `json:"leave"` Join map[id.RoomID]SyncJoinedRoom `json:"join"` Invite map[id.RoomID]SyncInvitedRoom `json:"invite"` } `json:"rooms"` }
RespSync is the JSON response for http://matrix.org/docs/spec/client_server/r0.6.0.html#get-matrix-client-r0-sync
type RespTurnServer ¶
type RespTyping ¶
type RespTyping struct{}
RespTyping is the JSON response for https://matrix.org/docs/spec/client_server/r0.2.0.html#put-matrix-client-r0-rooms-roomid-typing-userid
type RespUnbanUser ¶
type RespUnbanUser struct{}
RespUnbanUser is the JSON response for http://matrix.org/docs/spec/client_server/r0.2.0.html#post-matrix-client-r0-rooms-roomid-unban
type RespUploadKeys ¶
type RespUploadKeys struct {
OneTimeKeyCounts OneTimeKeysCount `json:"one_time_key_counts"`
}
type RespUploadSignatures ¶
type RespUploadSignatures struct {
Failures map[string]interface{} `json:"failures"`
}
type RespUserDisplayName ¶
type RespUserDisplayName struct {
DisplayName string `json:"displayname"`
}
RespUserDisplayName is the JSON response for https://matrix.org/docs/spec/client_server/r0.2.0.html#get-matrix-client-r0-profile-userid-displayname
type RespUserInteractive ¶
type RespUserInteractive struct { Flows []struct { Stages []AuthType `json:"stages"` } `json:"flows"` Params map[AuthType]interface{} `json:"params"` Session string `json:"session"` Completed []string `json:"completed"` ErrCode string `json:"errcode"` Error string `json:"error"` }
RespUserInteractive is the JSON response for https://matrix.org/docs/spec/client_server/r0.2.0.html#user-interactive-authentication-api
func (RespUserInteractive) HasSingleStageFlow ¶
func (r RespUserInteractive) HasSingleStageFlow(stageName AuthType) bool
HasSingleStageFlow returns true if there exists at least 1 Flow with a single stage of stageName.
type RespVersions ¶
type RespVersions struct { Versions []string `json:"versions"` UnstableFeatures map[string]bool `json:"unstable_features"` }
RespVersions is the JSON response for http://matrix.org/docs/spec/client_server/r0.6.1.html#get-matrix-client-versions
type RespWhoami ¶
type RespWhoami struct { UserID id.UserID `json:"user_id"` // N.B. This field is not in the spec yet, it's expected to land in r0.6.2 or r0.7.0 DeviceID id.DeviceID `json:"device_id"` }
RespWhoami is the JSON response for https://matrix.org/docs/spec/client_server/r0.6.1#get-matrix-client-r0-account-whoami
type SyncInvitedRoom ¶
type SyncInvitedRoom struct { Summary LazyLoadSummary `json:"summary"` State struct { Events []*event.Event `json:"events"` } `json:"invite_state"` }
type SyncJoinedRoom ¶
type SyncJoinedRoom struct { Summary LazyLoadSummary `json:"summary"` State struct { Events []*event.Event `json:"events"` } `json:"state"` Timeline struct { Events []*event.Event `json:"events"` Limited bool `json:"limited"` PrevBatch string `json:"prev_batch"` } `json:"timeline"` Ephemeral struct { Events []*event.Event `json:"events"` } `json:"ephemeral"` AccountData struct { Events []*event.Event `json:"events"` } `json:"account_data"` }
type SyncLeftRoom ¶
type UploadCrossSigningKeysReq ¶
type UploadCrossSigningKeysReq struct { Master CrossSigningKeys `json:"master_key"` SelfSigning CrossSigningKeys `json:"self_signing_key"` UserSigning CrossSigningKeys `json:"user_signing_key"` Auth interface{} `json:"auth,omitempty"` }