@@ -2194,6 +2194,93 @@ func (s *Session) WebhookExecute(webhookID int64, token string, wait bool, data
2194
2194
return
2195
2195
}
2196
2196
2197
+ // WebhookExecuteComplex executes a webhook.
2198
+ // webhookID: The ID of a webhook.
2199
+ // token : The auth token for the webhook
2200
+ func (s * Session ) WebhookExecuteComplex (webhookID int64 , token string , wait bool , data * WebhookParams ) (m * Message , err error ) {
2201
+ uri := EndpointWebhookToken (webhookID , token )
2202
+
2203
+ if wait {
2204
+ uri += "?wait=true"
2205
+ }
2206
+
2207
+ endpoint := uri
2208
+
2209
+ // TODO: Remove this when compatibility is not required.
2210
+ var files []* File
2211
+ if data .File != nil {
2212
+ files = []* File {data .File }
2213
+ }
2214
+
2215
+ var response []byte
2216
+ if len (files ) > 0 {
2217
+ body := & bytes.Buffer {}
2218
+ bodywriter := multipart .NewWriter (body )
2219
+
2220
+ var payload []byte
2221
+ payload , err = json .Marshal (data )
2222
+ if err != nil {
2223
+ return
2224
+ }
2225
+
2226
+ var p io.Writer
2227
+
2228
+ h := make (textproto.MIMEHeader )
2229
+ h .Set ("Content-Disposition" , `form-data; name="payload_json"` )
2230
+ h .Set ("Content-Type" , "application/json" )
2231
+
2232
+ p , err = bodywriter .CreatePart (h )
2233
+ if err != nil {
2234
+ return
2235
+ }
2236
+
2237
+ if _ , err = p .Write (payload ); err != nil {
2238
+ return
2239
+ }
2240
+
2241
+ for i , file := range files {
2242
+ h := make (textproto.MIMEHeader )
2243
+ h .Set ("Content-Disposition" , fmt .Sprintf (`form-data; name="file%d"; filename="%s"` , i , quoteEscaper .Replace (file .Name )))
2244
+ contentType := file .ContentType
2245
+ if contentType == "" {
2246
+ contentType = "application/octet-stream"
2247
+ }
2248
+ h .Set ("Content-Type" , contentType )
2249
+
2250
+ p , err = bodywriter .CreatePart (h )
2251
+ if err != nil {
2252
+ return
2253
+ }
2254
+
2255
+ if _ , err = io .Copy (p , file .Reader ); err != nil {
2256
+ return
2257
+ }
2258
+ }
2259
+
2260
+ err = bodywriter .Close ()
2261
+ if err != nil {
2262
+ return
2263
+ }
2264
+
2265
+ response , err = s .request ("POST" , endpoint , bodywriter .FormDataContentType (), body .Bytes (), EndpointWebhookToken (0 , "" ))
2266
+ } else {
2267
+ response , err = s .RequestWithBucketID ("POST" , endpoint , data , EndpointWebhookToken (0 , "" ))
2268
+ }
2269
+
2270
+ if err != nil {
2271
+ return
2272
+ }
2273
+
2274
+ if wait {
2275
+ err = unmarshal (response , & m )
2276
+ }
2277
+
2278
+ return
2279
+
2280
+ // _, err = s.RequestWithBucketID("POST", uri, data, EndpointWebhookToken(0, ""))
2281
+ // return
2282
+ }
2283
+
2197
2284
// MessageReactionAdd creates an emoji reaction to a message.
2198
2285
// channelID : The channel ID.
2199
2286
// messageID : The message ID.
@@ -2612,13 +2699,16 @@ func (s *Session) DeleteInteractionResponse(applicationID int64, token string) (
2612
2699
// CreateFollowupMessage Creates a followup message for an Interaction. Functions the same as Execute Webhook, but wait is always true, and flags can be set to 64 in the body to send an ephemeral message.
2613
2700
// POST /webhooks/{application.id}/{interaction.token}
2614
2701
func (s * Session ) CreateFollowupMessage (applicationID int64 , token string , data * WebhookParams ) (st * Message , err error ) {
2615
- body , err := s .RequestWithBucketID ("POST" , EndpointWebhookToken (applicationID , token ), data , EndpointWebhookToken (0 , "" ))
2616
- if err != nil {
2617
- return
2618
- }
2702
+ body , err := s .WebhookExecuteComplex (applicationID , token , true , data )
2703
+ return body , err
2619
2704
2620
- err = unmarshal (body , & st )
2621
- return
2705
+ // body, err := s.RequestWithBucketID("POST", EndpointWebhookToken(applicationID, token), data, EndpointWebhookToken(0, ""))
2706
+ // if err != nil {
2707
+ // return
2708
+ // }
2709
+
2710
+ // err = unmarshal(body, &st)
2711
+ // return
2622
2712
}
2623
2713
2624
2714
// EditFollowupMessage Edits a followup message for an Interaction. Functions the same as Edit Webhook Message.
0 commit comments