MCPcopy Index your code
hub / github.com/NdoleStudio/httpsms / Event

Method Event

api/pkg/handlers/discord_handler.go:256–282  ·  view source on GitHub ↗

Event consumes a discord event @Summary Consume a discord event @Description Publish a discord event to the registered listeners @Tags Discord @Accept json @Produce json @Success 204 {object} responses.NoContent @Failure 400 {object} responses.BadRequest @Failur

(c fiber.Ctx)

Source from the content-addressed store, hash-verified

254// @Failure 500 {object} responses.InternalServerError
255// @Router /discord/event [post]
256func (h *DiscordHandler) Event(c fiber.Ctx) error {
257 ctx, span, ctxLogger := h.tracer.StartFromFiberCtxWithLogger(c, h.logger)
258 defer span.End()
259
260 if verified := h.verifyInteraction(ctxLogger, c); !verified {
261 return h.responseUnauthorized(c)
262 }
263
264 var payload map[string]any
265 if err := json.Unmarshal(c.Body(), &payload); err != nil {
266 msg := fmt.Sprintf("cannot unmarshall [%s] to [%T]", string(c.Body()), payload)
267 ctxLogger.Error(h.tracer.WrapErrorSpan(span, stacktrace.Propagate(err, msg)))
268 return h.responseBadRequest(c, err)
269 }
270
271 ctxLogger.Info(string(c.Body()))
272
273 if payload["type"].(float64) == 1 {
274 return c.JSON(fiber.Map{"type": 1})
275 }
276
277 if payload["type"].(float64) == 2 {
278 return h.sendSMS(ctx, c, payload)
279 }
280
281 return h.responseBadRequest(c, stacktrace.NewError(fmt.Sprintf("unknown type [%d]", payload["type"])))
282}
283
284func (h *DiscordHandler) createRequest(payload map[string]any) requests.MessageSend {
285 getOption := func(name string) string {

Callers

nothing calls this directly

Calls 8

verifyInteractionMethod · 0.95
sendSMSMethod · 0.95
responseUnauthorizedMethod · 0.80
responseBadRequestMethod · 0.80
ErrorMethod · 0.65
WrapErrorSpanMethod · 0.65
InfoMethod · 0.65

Tested by

no test coverage detected