Skip to content

Commit 610906c

Browse files
fix: recipient
1 parent 1c50f23 commit 610906c

File tree

2 files changed

+17
-11
lines changed

2 files changed

+17
-11
lines changed

services/notifications/src/simcore_service_notifications/models/schemas.py

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,25 @@
1-
from typing import Any, TypeAlias
1+
from typing import Annotated, Any, Literal, TypeAlias
22

3-
from pydantic import BaseModel
3+
from pydantic import BaseModel, Field
44

55

6-
class SMSRecipient(BaseModel):
6+
class _BaseRecipient(BaseModel):
7+
type: str
8+
9+
10+
class SMSRecipient(_BaseRecipient):
11+
type: Literal["sms"]
712
phone_number: str
813

914

10-
class EmailRecipient(BaseModel):
11-
email: str
15+
class EmailRecipient(_BaseRecipient):
16+
type: Literal["email"]
17+
address: str
1218

1319

14-
Recipient: TypeAlias = SMSRecipient | EmailRecipient
20+
Recipient: TypeAlias = Annotated[
21+
EmailRecipient | SMSRecipient, Field(discriminator="type")
22+
]
1523

1624

1725
class NotificationMessage(BaseModel):

services/notifications/src/simcore_service_notifications/services/notifications_service.py

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,6 @@
55

66
from ..models.schemas import NotificationMessage, Recipient
77

8-
CHANNELS = {
9-
"email": "notifications.email",
10-
}
11-
128

139
class TaskQueues(StrEnum):
1410
DEFAULT = "notifications.default"
@@ -23,8 +19,10 @@ async def send_notification(
2319
for recipient in recipients:
2420
await task_manager.send_task(
2521
TaskMetadata(
26-
name="notifications.send_email",
22+
name=f"notifications.{recipient.type}",
2723
queue=TaskQueues.DEFAULT,
2824
),
2925
task_context=TaskContext(),
26+
message=message,
27+
recipient=recipient,
3028
)

0 commit comments

Comments
 (0)