mirror of
https://github.com/zitadel/zitadel.git
synced 2024-12-15 12:27:59 +00:00
5bdf1a4547
# Which Problems Are Solved Send SMS messages as a HTTP call to a relay, for own logic on handling different SMS providers. # How the Problems Are Solved Add HTTP as SMS provider type and handling of webhook messages in the notification handlers. # Additional Changes Clean up old Twilio events, which were supposed to handle the general SMS providers with deactivate, activate and remove. # Additional Context Partially closes #8270 --------- Co-authored-by: Livio Spring <livio.a@gmail.com>
63 lines
1.8 KiB
Go
63 lines
1.8 KiB
Go
package senders
|
|
|
|
import (
|
|
"context"
|
|
|
|
"github.com/zitadel/logging"
|
|
|
|
"github.com/zitadel/zitadel/internal/api/authz"
|
|
"github.com/zitadel/zitadel/internal/notification/channels"
|
|
"github.com/zitadel/zitadel/internal/notification/channels/fs"
|
|
"github.com/zitadel/zitadel/internal/notification/channels/instrumenting"
|
|
"github.com/zitadel/zitadel/internal/notification/channels/log"
|
|
"github.com/zitadel/zitadel/internal/notification/channels/sms"
|
|
"github.com/zitadel/zitadel/internal/notification/channels/twilio"
|
|
"github.com/zitadel/zitadel/internal/notification/channels/webhook"
|
|
)
|
|
|
|
const twilioSpanName = "twilio.NotificationChannel"
|
|
|
|
func SMSChannels(
|
|
ctx context.Context,
|
|
smsConfig *sms.Config,
|
|
getFileSystemProvider func(ctx context.Context) (*fs.Config, error),
|
|
getLogProvider func(ctx context.Context) (*log.Config, error),
|
|
successMetricName,
|
|
failureMetricName string,
|
|
) (chain *Chain, err error) {
|
|
channels := make([]channels.NotificationChannel, 0, 3)
|
|
if smsConfig.TwilioConfig != nil {
|
|
channels = append(
|
|
channels,
|
|
instrumenting.Wrap(
|
|
ctx,
|
|
twilio.InitChannel(*smsConfig.TwilioConfig),
|
|
twilioSpanName,
|
|
successMetricName,
|
|
failureMetricName,
|
|
),
|
|
)
|
|
}
|
|
if smsConfig.WebhookConfig != nil {
|
|
webhookChannel, err := webhook.InitChannel(ctx, *smsConfig.WebhookConfig)
|
|
logging.WithFields(
|
|
"instance", authz.GetInstance(ctx).InstanceID(),
|
|
"callurl", smsConfig.WebhookConfig.CallURL,
|
|
).OnError(err).Debug("initializing JSON channel failed")
|
|
if err == nil {
|
|
channels = append(
|
|
channels,
|
|
instrumenting.Wrap(
|
|
ctx,
|
|
webhookChannel,
|
|
webhookSpanName,
|
|
successMetricName,
|
|
failureMetricName,
|
|
),
|
|
)
|
|
}
|
|
}
|
|
channels = append(channels, debugChannels(ctx, getFileSystemProvider, getLogProvider)...)
|
|
return ChainChannels(channels...), nil
|
|
}
|