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

Method Send

api/pkg/services/webhook_service.go:182–208  ·  view source on GitHub ↗

Send an event to a subscribed webhook

(ctx context.Context, userID entities.UserID, event cloudevents.Event, phoneNumber string)

Source from the content-addressed store, hash-verified

180
181// Send an event to a subscribed webhook
182func (service *WebhookService) Send(ctx context.Context, userID entities.UserID, event cloudevents.Event, phoneNumber string) error {
183 ctx, span, ctxLogger := service.tracer.StartWithLogger(ctx, service.logger)
184 defer span.End()
185
186 webhooks, err := service.repository.LoadByEvent(ctx, userID, event.Type(), phoneNumber)
187 if err != nil {
188 msg := fmt.Sprintf("cannot load webhooks for userID [%s] and event [%s]", userID, event.Type())
189 return service.tracer.WrapErrorSpan(span, stacktrace.PropagateWithCode(err, stacktrace.GetCode(err), msg))
190 }
191
192 if len(webhooks) == 0 {
193 ctxLogger.Info(fmt.Sprintf("user [%s] has no webhook subscription to event [%s]", userID, event.Type()))
194 return nil
195 }
196
197 var wg sync.WaitGroup
198 for _, webhook := range webhooks {
199 wg.Add(1)
200 go func(webhook *entities.Webhook) {
201 defer wg.Done()
202 service.sendNotification(ctx, event, phoneNumber, webhook)
203 }(webhook)
204 }
205 wg.Wait()
206
207 return nil
208}
209
210func (service *WebhookService) sendNotification(ctx context.Context, event cloudevents.Event, owner string, webhook *entities.Webhook) {
211 ctx, span, ctxLogger := service.tracer.StartWithLogger(ctx, service.logger)

Callers

nothing calls this directly

Calls 5

sendNotificationMethod · 0.95
StartWithLoggerMethod · 0.65
LoadByEventMethod · 0.65
WrapErrorSpanMethod · 0.65
InfoMethod · 0.65

Tested by

no test coverage detected