Debian Codegraph @

pkg/services/chat/matrix/matrix_api.go

raw symbols SCIP
1 package matrixscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/services/chat/matrix`/
2
3 // Type definitions for Matrix API message types.
4 type (
5 // messageType represents the type of a Matrix message.
6 messageTypescip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/services/chat/matrix`/messageType# string
7 // flowType represents the type of a Matrix login flow.
8 flowTypescip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/services/chat/matrix`/flowType# string
9 // identifierType represents the type of Matrix user identifier.
10 identifierTypescip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/services/chat/matrix`/identifierType# string
11 )
12
13 // apiResLoginFlows represents the response from the Matrix login flows endpoint.
14 type apiResLoginFlowsscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/services/chat/matrix`/apiResLoginFlows# struct {
15 Flowsscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/services/chat/matrix`/apiResLoginFlows#Flows. []flowscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/services/chat/matrix`/flow# `json:"flows"`
16 }
17
18 // apiReqLogin represents a login request to the Matrix API.
19 type apiReqLoginscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/services/chat/matrix`/apiReqLogin# struct {
20 Typescip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/services/chat/matrix`/apiReqLogin#Type. flowTypescip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/services/chat/matrix`/flowType# `json:"type"`
21 Identifierscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/services/chat/matrix`/apiReqLogin#Identifier. *identifierscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/services/chat/matrix`/identifier# `json:"identifier"`
22
23 Passwordscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/services/chat/matrix`/apiReqLogin#Password. string `json:"password,omitempty"`
24 Tokenscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/services/chat/matrix`/apiReqLogin#Token. string `json:"token,omitempty"`
25 DeviceIDscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/services/chat/matrix`/apiReqLogin#DeviceID. string `json:"device_id,omitempty"`
26 }
27
28 // apiResLogin represents the response from a successful Matrix login request.
29 type apiResLoginscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/services/chat/matrix`/apiResLogin# struct {
30 AccessTokenscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/services/chat/matrix`/apiResLogin#AccessToken. string `json:"access_token"`
31 HomeServerscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/services/chat/matrix`/apiResLogin#HomeServer. string `json:"home_server"`
32 UserIDscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/services/chat/matrix`/apiResLogin#UserID. string `json:"user_id"`
33 DeviceIDscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/services/chat/matrix`/apiResLogin#DeviceID. string `json:"device_id"`
34 }
35
36 // apiReqSend represents a request to send a message to a Matrix room.
37 type apiReqSendscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/services/chat/matrix`/apiReqSend# struct {
38 MsgTypescip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/services/chat/matrix`/apiReqSend#MsgType. messageTypescip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/services/chat/matrix`/messageType# `json:"msgtype"`
39 Bodyscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/services/chat/matrix`/apiReqSend#Body. string `json:"body"`
40 }
41
42 // apiResRoom represents the response from joining a Matrix room.
43 type apiResRoomscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/services/chat/matrix`/apiResRoom# struct {
44 RoomIDscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/services/chat/matrix`/apiResRoom#RoomID. string `json:"room_id"`
45 }
46
47 // apiResJoinedRooms represents the response containing the list of joined rooms.
48 type apiResJoinedRoomsscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/services/chat/matrix`/apiResJoinedRooms# struct {
49 Roomsscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/services/chat/matrix`/apiResJoinedRooms#Rooms. []string `json:"joined_rooms"`
50 }
51
52 // apiResEvent represents the response from sending a message event.
53 type apiResEventscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/services/chat/matrix`/apiResEvent# struct {
54 EventIDscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/services/chat/matrix`/apiResEvent#EventID. string `json:"event_id"`
55 }
56
57 // apiResError represents an error response from the Matrix API.
58 type apiResErrorscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/services/chat/matrix`/apiResError# struct {
59 Messagescip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/services/chat/matrix`/apiResError#Message. string `json:"error"`
60 Codescip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/services/chat/matrix`/apiResError#Code. string `json:"errcode"`
61 }
62
63 // flow represents a Matrix login flow type.
64 type flowscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/services/chat/matrix`/flow# struct {
65 Typescip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/services/chat/matrix`/flow#Type. flowTypescip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/services/chat/matrix`/flowType# `json:"type"`
66 }
67
68 // identifier represents a Matrix user identifier for authentication.
69 type identifierscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/services/chat/matrix`/identifier# struct {
70 Typescip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/services/chat/matrix`/identifier#Type. identifierTypescip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/services/chat/matrix`/identifierType# `json:"type"`
71 Userscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/services/chat/matrix`/identifier#User. string `json:"user,omitempty"`
72 }
73
74 const (
75 // Matrix API endpoint paths.
76 apiLoginscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/services/chat/matrix`/apiLogin. = "/_matrix/client/v3/login"
77 apiRoomJoinscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/services/chat/matrix`/apiRoomJoin. = "/_matrix/client/v3/join/%s"
78 apiSendMessagescip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/services/chat/matrix`/apiSendMessage. = "/_matrix/client/v3/rooms/%s/send/m.room.message/%s"
79 apiJoinedRoomsscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/services/chat/matrix`/apiJoinedRooms. = "/_matrix/client/v3/joined_rooms"
80
81 contentTypescip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/services/chat/matrix`/contentType. = "application/json"
82
83 // msgTypeText is the Matrix message type for plain text messages.
84 msgTypeTextscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/services/chat/matrix`/msgTypeText. messageTypescip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/services/chat/matrix`/messageType# = "m.text"
85 // flowLoginPassword is the Matrix login flow type for password authentication.
86 flowLoginPasswordscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/services/chat/matrix`/flowLoginPassword. flowTypescip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/services/chat/matrix`/flowType# = "m.login.password"
87 //nolint:gosec // This is a Matrix API constant, not a hardcoded credential
88 flowLoginTokenscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/services/chat/matrix`/flowLoginToken. flowTypescip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/services/chat/matrix`/flowType# = "m.login.token"
89 // idTypeUser is the Matrix identifier type for username-based authentication.
90 idTypeUserscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/services/chat/matrix`/idTypeUser. identifierTypescip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/services/chat/matrix`/identifierType# = "m.id.user"
91
92 // Matrix error code for rate limiting.
93 errCodeLimitExceededscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/services/chat/matrix`/errCodeLimitExceeded. = "M_LIMIT_EXCEEDED"
94 )
95
96 // Error returns the error message from the Matrix API error response.
97 func (e *apiResErrorscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/services/chat/matrix`/apiResError#) Errorscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/services/chat/matrix`/apiResError#Error().() string {
98 return e.Messagescip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/services/chat/matrix`/apiResError#Message.
99 }
100
101 // IsRateLimited checks if the error is a rate limiting error (M_LIMIT_EXCEEDED).
102 func (e *apiResErrorscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/services/chat/matrix`/apiResError#) IsRateLimitedscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/services/chat/matrix`/apiResError#IsRateLimited().() bool {
103 return e.Codescip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/services/chat/matrix`/apiResError#Code. == errCodeLimitExceededscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/services/chat/matrix`/errCodeLimitExceeded.
104 }
105
106 // newUserIdentifier creates a new Matrix user identifier for authentication.
107 func newUserIdentifierscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/services/chat/matrix`/newUserIdentifier().(user string) *identifierscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/services/chat/matrix`/identifier# {
108 return &identifierscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/services/chat/matrix`/identifier#{
109 Typescip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/services/chat/matrix`/identifier#Type.: idTypeUserscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/services/chat/matrix`/idTypeUser.,
110 Userscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/services/chat/matrix`/identifier#User.: user,
111 }
112 }