diff --git a/pkg/lib/config/feature_messaging.go b/pkg/lib/config/feature_messaging.go index 0a044ddc81..e2f55a3745 100644 --- a/pkg/lib/config/feature_messaging.go +++ b/pkg/lib/config/feature_messaging.go @@ -7,8 +7,7 @@ var _ = FeatureConfigSchema.Add("MessagingFeatureConfig", ` "properties": { "rate_limits": { "$ref": "#/$defs/MessagingRateLimitsFeatureConfig" }, "sms_usage": { "$ref": "#/$defs/UsageLimitConfig" }, - "email_usage": { "$ref": "#/$defs/UsageLimitConfig" }, - "whatsapp_usage": { "$ref": "#/$defs/UsageLimitConfig" } + "email_usage": { "$ref": "#/$defs/UsageLimitConfig" } } } `) @@ -16,9 +15,8 @@ var _ = FeatureConfigSchema.Add("MessagingFeatureConfig", ` type MessagingFeatureConfig struct { RateLimits *MessagingRateLimitsFeatureConfig `json:"rate_limits,omitempty"` - SMSUsage *UsageLimitConfig `json:"sms_usage,omitempty"` - EmailUsage *UsageLimitConfig `json:"email_usage,omitempty"` - WhatsappUsage *UsageLimitConfig `json:"whatsapp_usage,omitempty"` + SMSUsage *UsageLimitConfig `json:"sms_usage,omitempty"` + EmailUsage *UsageLimitConfig `json:"email_usage,omitempty"` } func (c *MessagingFeatureConfig) SetDefaults() { @@ -36,13 +34,6 @@ func (c *MessagingFeatureConfig) SetDefaults() { Quota: 100000, } } - if c.WhatsappUsage.Enabled == nil { - c.WhatsappUsage = &UsageLimitConfig{ - Enabled: newBool(true), - Period: UsageLimitPeriodMonth, - Quota: 100000, - } - } } var _ = FeatureConfigSchema.Add("MessagingRateLimitsFeatureConfig", ` diff --git a/pkg/lib/config/testdata/default_feature.yaml b/pkg/lib/config/testdata/default_feature.yaml index 5445e436fc..ccc9feaa3d 100644 --- a/pkg/lib/config/testdata/default_feature.yaml +++ b/pkg/lib/config/testdata/default_feature.yaml @@ -101,10 +101,6 @@ messaging: enabled: true period: month quota: 100000 - whatsapp_usage: - enabled: true - period: month - quota: 100000 collaborator: {} web3: nft: diff --git a/pkg/lib/messaging/limits.go b/pkg/lib/messaging/limits.go index 9b12651099..eb06567ba7 100644 --- a/pkg/lib/messaging/limits.go +++ b/pkg/lib/messaging/limits.go @@ -8,9 +8,8 @@ import ( ) const ( - usageLimitEmail usage.LimitName = "Email" - usageLimitSMS usage.LimitName = "SMS" - usageLimitWhatsapp usage.LimitName = "Whatsapp" + usageLimitEmail usage.LimitName = "Email" + usageLimitSMS usage.LimitName = "SMS" ) const ( @@ -165,52 +164,3 @@ func (l *Limits) checkSMS(phoneNumber string) (msg *message, err error) { return } - -func (l *Limits) checkWhatsapp(phoneNumber string) (msg *message, err error) { - msg = &message{ - logger: l.Logger, - rateLimiter: l.RateLimiter, - usageLimiter: l.UsageLimiter, - } - defer func() { - if err != nil { - // Return reserved tokens - msg.Close() - msg = nil - } - }() - - msg.usageLimit, err = l.UsageLimiter.Reserve(usageLimitWhatsapp, l.FeatureConfig.WhatsappUsage) - if err != nil { - return - } - - // TODO: Use whatsapp specific rate limits - msg.rateLimits, err = l.check(msg.rateLimits, - l.EnvConfig.SMSPerIP, l.FeatureConfig.RateLimits.SMSPerIP, l.Config.SMSPerIP, - MessagingSMSPerIP, string(l.RemoteIP), - ) - if err != nil { - return - } - - // TODO: Use whatsapp specific rate limits - msg.rateLimits, err = l.check(msg.rateLimits, - l.EnvConfig.SMSPerTarget, l.FeatureConfig.RateLimits.SMSPerTarget, l.Config.SMSPerTarget, - MessagingSMSPerTarget, phoneNumber, - ) - if err != nil { - return - } - - // TODO: Use whatsapp specific rate limits - msg.rateLimits, err = l.check(msg.rateLimits, - l.EnvConfig.SMS, l.FeatureConfig.RateLimits.SMS, l.Config.SMS, - MessagingSMS, - ) - if err != nil { - return - } - - return -} diff --git a/pkg/lib/messaging/sender.go b/pkg/lib/messaging/sender.go index e2d95541d5..d2da6971f2 100644 --- a/pkg/lib/messaging/sender.go +++ b/pkg/lib/messaging/sender.go @@ -58,7 +58,8 @@ func (s *Sender) PrepareSMS(phoneNumber string, msgType nonblocking.MessageType) } func (s *Sender) PrepareWhatsapp(phoneNumber string, msgType nonblocking.MessageType) (*WhatsappMessage, error) { - msg, err := s.Limits.checkWhatsapp(phoneNumber) + // FIXME: Should use a separated limit + msg, err := s.Limits.checkSMS(phoneNumber) if err != nil { return nil, err }