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

Method sendSMS

api/pkg/handlers/discord_handler.go:300–418  ·  view source on GitHub ↗
(ctx context.Context, c fiber.Ctx, payload map[string]any)

Source from the content-addressed store, hash-verified

298}
299
300func (h *DiscordHandler) sendSMS(ctx context.Context, c fiber.Ctx, payload map[string]any) error {
301 _, span, ctxLogger := h.tracer.StartWithLogger(ctx, h.logger)
302 defer span.End()
303
304 discord, err := h.service.GetByServerID(ctx, payload["guild_id"].(string))
305 if err != nil {
306 msg := fmt.Sprintf("cannot get discord integration by server ID [%s]", payload["guild_id"].(string))
307 ctxLogger.Error(h.tracer.WrapErrorSpan(span, stacktrace.Propagate(err, msg)))
308 return c.JSON(
309 fiber.Map{
310 "type": 4,
311 "data": fiber.Map{
312 "content": "**⚠️ error while sending message**",
313 "embeds": []fiber.Map{
314 {
315 "title": "We cannot find the link to your discord server to an account on [httpsms.com](https://httpsms.com/settings).",
316 "color": 14681092,
317 },
318 },
319 },
320 },
321 )
322 }
323
324 request := h.createRequest(payload)
325 messageEmbed := fiber.Map{
326 "fields": []fiber.Map{
327 {
328 "name": "From:",
329 "value": request.From,
330 "inline": true,
331 },
332 {
333 "name": "To:",
334 "value": request.To,
335 "inline": true,
336 },
337 {
338 "name": "Content:",
339 "value": request.Content,
340 },
341 },
342 }
343
344 if errors := h.messageValidator.ValidateMessageSend(ctx, discord.UserID, request.Sanitize()); len(errors) != 0 {
345 msg := fmt.Sprintf("validation errors [%s], while sending payload [%s]", spew.Sdump(errors), c.Body())
346 ctxLogger.Warn(stacktrace.NewError(msg))
347
348 var embeds []fiber.Map
349 for _, value := range errors {
350 embeds = append(embeds, fiber.Map{
351 "title": value[0],
352 "color": 14681092,
353 })
354 }
355
356 return c.JSON(
357 fiber.Map{

Callers 1

EventMethod · 0.95

Calls 11

createRequestMethod · 0.95
GetByServerIDMethod · 0.80
ValidateMessageSendMethod · 0.80
SendMessageMethod · 0.80
StartWithLoggerMethod · 0.65
ErrorMethod · 0.65
WrapErrorSpanMethod · 0.65
WarnMethod · 0.65
SanitizeMethod · 0.45
IsEntitledMethod · 0.45
ToMessageSendParamsMethod · 0.45

Tested by

no test coverage detected