11package applicationcommand
22
33import (
4- "time"
5-
64 appcmd "github.com/FlameInTheDark/gochat/internal/applicationcommands"
75 "github.com/FlameInTheDark/gochat/internal/botauth"
6+ "github.com/FlameInTheDark/gochat/internal/dto"
87 "github.com/FlameInTheDark/gochat/internal/idgen"
98 "github.com/gofiber/fiber/v2"
109)
@@ -190,9 +189,6 @@ func (e *Entity) RespondInteraction(c *fiber.Ctx) error {
190189 if err := requireInteractionID (c , record ); err != nil {
191190 return err
192191 }
193- if time .Now ().After (record .CreatedAt .Add (appcmd .InteractionDeadline )) {
194- return fiber .NewError (fiber .StatusNotFound , "unknown interaction" )
195- }
196192 var response appcmd.InteractionResponse
197193 if err := c .BodyParser (& response ); err != nil {
198194 return fiber .NewError (fiber .StatusBadRequest , "invalid interaction response" )
@@ -202,32 +198,43 @@ func (e *Entity) RespondInteraction(c *fiber.Ctx) error {
202198 if err := e .appcmd .AckInteraction (c .UserContext (), record .ID , appcmd .AckStateResponded , nil ); err != nil {
203199 return duplicateAckError ()
204200 }
201+ e .notifyInteractionStatus (c .UserContext (), record , "responded" , response .Data , nil )
205202 return c .SendStatus (fiber .StatusNoContent )
206203 case appcmd .ResponseTypeDeferredChannelMessageSource :
204+ var deferredData * appcmd.InteractionResponseData
207205 if response .Data != nil && appcmd .HasResponseFlag (response .Data , appcmd .MessageFlagEphemeral ) {
208- _ = e .setEphemeralResponse (c .UserContext (), record .ID , & appcmd.InteractionResponseData {Flags : response .Data .Flags | appcmd .MessageFlagLoading })
206+ deferredData = & appcmd.InteractionResponseData {Flags : response .Data .Flags | appcmd .MessageFlagLoading }
207+ _ = e .setEphemeralResponse (c .UserContext (), record .ID , deferredData )
208+ } else {
209+ deferredData = response .Data
209210 }
210211 if err := e .appcmd .AckInteraction (c .UserContext (), record .ID , appcmd .AckStateDeferred , nil ); err != nil {
211212 return duplicateAckError ()
212213 }
214+ e .notifyInteractionStatus (c .UserContext (), record , "deferred" , deferredData , nil )
213215 return c .SendStatus (fiber .StatusNoContent )
214216 case appcmd .ResponseTypeChannelMessageWithSource :
215217 var messageID * int64
218+ var message * dto.Message
219+ state := "responded"
216220 if appcmd .HasResponseFlag (response .Data , appcmd .MessageFlagEphemeral ) {
217221 if err := e .setEphemeralResponse (c .UserContext (), record .ID , response .Data ); err != nil {
218222 return fiber .NewError (fiber .StatusInternalServerError , "unable to store ephemeral response" )
219223 }
224+ state = "ephemeral"
220225 } else {
221226 msg , err := e .createPublicInteractionMessage (c , record , response .Data )
222227 if err != nil {
223228 return err
224229 }
225230 id := msg .Id
226231 messageID = & id
232+ message = & msg
227233 }
228234 if err := e .appcmd .AckInteraction (c .UserContext (), record .ID , appcmd .AckStateResponded , messageID ); err != nil {
229235 return duplicateAckError ()
230236 }
237+ e .notifyInteractionStatus (c .UserContext (), record , state , response .Data , message )
231238 return c .SendStatus (fiber .StatusNoContent )
232239 case appcmd .ResponseTypeAutocompleteResult :
233240 if response .Data == nil {
@@ -247,6 +254,7 @@ func (e *Entity) RespondInteraction(c *fiber.Ctx) error {
247254 if err := e .appcmd .AckInteraction (c .UserContext (), record .ID , appcmd .AckStateResponded , nil ); err != nil {
248255 return duplicateAckError ()
249256 }
257+ e .notifyInteractionStatus (c .UserContext (), record , "modal" , response .Data , nil )
250258 return c .JSON (response )
251259 default :
252260 return fiber .NewError (fiber .StatusBadRequest , "unsupported interaction response type" )
@@ -294,6 +302,7 @@ func (e *Entity) EditOriginalInteractionResponse(c *fiber.Ctx) error {
294302 if err := e .setEphemeralResponse (c .UserContext (), record .ID , & data ); err != nil {
295303 return fiber .NewError (fiber .StatusInternalServerError , "unable to store ephemeral response" )
296304 }
305+ e .notifyInteractionStatus (c .UserContext (), record , "ephemeral" , & data , nil )
297306 return c .JSON (data )
298307 }
299308 if record .InitialResponseID == nil {
@@ -303,6 +312,7 @@ func (e *Entity) EditOriginalInteractionResponse(c *fiber.Ctx) error {
303312 if err := e .setEphemeralResponse (c .UserContext (), record .ID , & data ); err != nil {
304313 return fiber .NewError (fiber .StatusInternalServerError , "unable to store ephemeral response" )
305314 }
315+ e .notifyInteractionStatus (c .UserContext (), record , "ephemeral" , & data , nil )
306316 return c .JSON (data )
307317 }
308318 out , err := e .createPublicInteractionMessage (c , record , & data )
@@ -313,12 +323,14 @@ func (e *Entity) EditOriginalInteractionResponse(c *fiber.Ctx) error {
313323 _ = e .deleteMessageResponse (c , record , out .Id )
314324 return duplicateAckError ()
315325 }
326+ e .notifyInteractionStatus (c .UserContext (), record , "responded" , & data , & out )
316327 return c .JSON (out )
317328 }
318329 out , err := e .editMessageResponse (c , record , * record .InitialResponseID , & data )
319330 if err != nil {
320331 return err
321332 }
333+ e .notifyInteractionStatus (c .UserContext (), record , "responded" , & data , & out )
322334 return c .JSON (out )
323335}
324336
@@ -357,12 +369,14 @@ func (e *Entity) CreateFollowupMessage(c *fiber.Ctx) error {
357369 if err := e .setEphemeralResponse (c .UserContext (), idgen .Next (), & data ); err != nil {
358370 return fiber .NewError (fiber .StatusInternalServerError , "unable to store ephemeral followup" )
359371 }
372+ e .notifyInteractionStatus (c .UserContext (), record , "ephemeral_followup" , & data , nil )
360373 return c .Status (fiber .StatusCreated ).JSON (data )
361374 }
362375 out , err := e .createPublicInteractionMessage (c , record , & data )
363376 if err != nil {
364377 return err
365378 }
379+ e .notifyInteractionStatus (c .UserContext (), record , "responded" , & data , & out )
366380 return c .Status (fiber .StatusCreated ).JSON (out )
367381}
368382
0 commit comments