generated from westfarn/web_django_template
Initial commit
This commit is contained in:
@@ -0,0 +1,24 @@
|
||||
"""Channel dispatch — email / SMS."""
|
||||
|
||||
from dataclasses import dataclass
|
||||
|
||||
from contacts.models import Channel
|
||||
from email_sms.models import Message
|
||||
from email_sms.providers.email.smtp2go import send_email
|
||||
from email_sms.providers.sms.smtp2go import send_sms
|
||||
|
||||
|
||||
@dataclass
|
||||
class ProviderResult:
|
||||
provider: str
|
||||
provider_id: str
|
||||
|
||||
|
||||
def dispatch_message(message: Message) -> ProviderResult:
|
||||
if message.channel == Channel.EMAIL:
|
||||
result = send_email(message)
|
||||
return ProviderResult(provider="smtp2go_email", provider_id=result)
|
||||
if message.channel == Channel.SMS:
|
||||
result = send_sms(message)
|
||||
return ProviderResult(provider="smtp2go_sms", provider_id=result)
|
||||
raise ValueError(f"Unsupported channel: {message.channel}")
|
||||
Reference in New Issue
Block a user