-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathchatmessagereaction.go
More file actions
162 lines (147 loc) · 5.83 KB
/
chatmessagereaction.go
File metadata and controls
162 lines (147 loc) · 5.83 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
// File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.
package beeperdesktopapi
import (
"context"
"errors"
"fmt"
"net/http"
"net/url"
"slices"
"github.com/beeper/desktop-api-go/internal/apijson"
"github.com/beeper/desktop-api-go/internal/apiquery"
"github.com/beeper/desktop-api-go/internal/requestconfig"
"github.com/beeper/desktop-api-go/option"
"github.com/beeper/desktop-api-go/packages/param"
"github.com/beeper/desktop-api-go/packages/respjson"
)
// Manage message reactions
//
// ChatMessageReactionService contains methods and other services that help with
// interacting with the beeperdesktop API.
//
// Note, unlike clients, this service does not read variables from the environment
// automatically. You should not instantiate this service directly, and instead use
// the [NewChatMessageReactionService] method instead.
type ChatMessageReactionService struct {
Options []option.RequestOption
}
// NewChatMessageReactionService generates a new service that applies the given
// options to each request. These options are applied after the parent client's
// options (if there is one), and before any request-specific options.
func NewChatMessageReactionService(opts ...option.RequestOption) (r ChatMessageReactionService) {
r = ChatMessageReactionService{}
r.Options = opts
return
}
// Remove the authenticated user's reaction from an existing message.
func (r *ChatMessageReactionService) Delete(ctx context.Context, messageID string, params ChatMessageReactionDeleteParams, opts ...option.RequestOption) (res *ChatMessageReactionDeleteResponse, err error) {
opts = slices.Concat(r.Options, opts)
if params.ChatID == "" {
err = errors.New("missing required chatID parameter")
return
}
if messageID == "" {
err = errors.New("missing required messageID parameter")
return
}
path := fmt.Sprintf("v1/chats/%s/messages/%s/reactions", params.ChatID, messageID)
err = requestconfig.ExecuteNewRequest(ctx, http.MethodDelete, path, params, &res, opts...)
return
}
// Add a reaction to an existing message.
func (r *ChatMessageReactionService) Add(ctx context.Context, messageID string, params ChatMessageReactionAddParams, opts ...option.RequestOption) (res *ChatMessageReactionAddResponse, err error) {
opts = slices.Concat(r.Options, opts)
if params.ChatID == "" {
err = errors.New("missing required chatID parameter")
return
}
if messageID == "" {
err = errors.New("missing required messageID parameter")
return
}
path := fmt.Sprintf("v1/chats/%s/messages/%s/reactions", params.ChatID, messageID)
err = requestconfig.ExecuteNewRequest(ctx, http.MethodPost, path, params, &res, opts...)
return
}
type ChatMessageReactionDeleteResponse struct {
// Unique identifier of the chat.
ChatID string `json:"chatID" api:"required"`
// Message ID.
MessageID string `json:"messageID" api:"required"`
// Reaction key that was removed
ReactionKey string `json:"reactionKey" api:"required"`
// Whether the reaction was successfully removed
Success bool `json:"success" api:"required"`
// JSON contains metadata for fields, check presence with [respjson.Field.Valid].
JSON struct {
ChatID respjson.Field
MessageID respjson.Field
ReactionKey respjson.Field
Success respjson.Field
ExtraFields map[string]respjson.Field
raw string
} `json:"-"`
}
// Returns the unmodified JSON received from the API
func (r ChatMessageReactionDeleteResponse) RawJSON() string { return r.JSON.raw }
func (r *ChatMessageReactionDeleteResponse) UnmarshalJSON(data []byte) error {
return apijson.UnmarshalRoot(data, r)
}
type ChatMessageReactionAddResponse struct {
// Unique identifier of the chat.
ChatID string `json:"chatID" api:"required"`
// Message ID.
MessageID string `json:"messageID" api:"required"`
// Reaction key that was added
ReactionKey string `json:"reactionKey" api:"required"`
// Whether the reaction was successfully added
Success bool `json:"success" api:"required"`
// Transaction ID used for the reaction event
TransactionID string `json:"transactionID" api:"required"`
// JSON contains metadata for fields, check presence with [respjson.Field.Valid].
JSON struct {
ChatID respjson.Field
MessageID respjson.Field
ReactionKey respjson.Field
Success respjson.Field
TransactionID respjson.Field
ExtraFields map[string]respjson.Field
raw string
} `json:"-"`
}
// Returns the unmodified JSON received from the API
func (r ChatMessageReactionAddResponse) RawJSON() string { return r.JSON.raw }
func (r *ChatMessageReactionAddResponse) UnmarshalJSON(data []byte) error {
return apijson.UnmarshalRoot(data, r)
}
type ChatMessageReactionDeleteParams struct {
// Unique identifier of the chat.
ChatID string `path:"chatID" api:"required" json:"-"`
// Reaction key to remove
ReactionKey string `query:"reactionKey" api:"required" json:"-"`
paramObj
}
// URLQuery serializes [ChatMessageReactionDeleteParams]'s query parameters as
// `url.Values`.
func (r ChatMessageReactionDeleteParams) URLQuery() (v url.Values, err error) {
return apiquery.MarshalWithSettings(r, apiquery.QuerySettings{
ArrayFormat: apiquery.ArrayQueryFormatRepeat,
NestedFormat: apiquery.NestedQueryFormatBrackets,
})
}
type ChatMessageReactionAddParams struct {
// Unique identifier of the chat.
ChatID string `path:"chatID" api:"required" json:"-"`
// Reaction key to add (emoji, shortcode, or custom emoji key)
ReactionKey string `json:"reactionKey" api:"required"`
// Optional transaction ID for deduplication and local echo tracking
TransactionID param.Opt[string] `json:"transactionID,omitzero"`
paramObj
}
func (r ChatMessageReactionAddParams) MarshalJSON() (data []byte, err error) {
type shadow ChatMessageReactionAddParams
return param.MarshalObject(r, (*shadow)(&r))
}
func (r *ChatMessageReactionAddParams) UnmarshalJSON(data []byte) error {
return apijson.UnmarshalRoot(data, r)
}