-
Notifications
You must be signed in to change notification settings - Fork 7
Core updates #13
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Core updates #13
Changes from all commits
55945ad
b0e102b
3aed402
3943626
4c692d8
1cd583b
aeee546
4adced7
404b288
5715955
57df4a3
a3a45b8
be6c182
cfef1b0
52b6339
e3e52cf
bd25c47
a5f8595
259adcd
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,10 +1,12 @@ | ||
| from .constants import SyncDispatcher, EventType | ||
| from .constants import SyncDispatcher | ||
| from .error_messages import ErrorMessages | ||
| from .notification_channels import NotificationChannels | ||
| from .event_priority import EventPriority | ||
| from .event import EventType | ||
| from .database_tables import DatabaseTables | ||
| from .notification_request_log_status import NotificationRequestLogStatus | ||
| from .email import Email | ||
| from .whatsapp import VariableMappingKeys | ||
| from .providers import Providers, ProvidersStatus | ||
| from .providers_default_priority import ProvidersDefaultPriorityStatus | ||
| from .providers_dynamic_priority import ProvidersDynamicPriorityStatus |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,19 @@ | ||
| from enum import Enum | ||
| from commonutils.utils import CustomEnum | ||
|
|
||
|
|
||
| class EventPriority(CustomEnum): | ||
| CRITICAL = "critical" | ||
| HIGH = "high" | ||
| MEDIUM = "medium" | ||
| LOW = "low" | ||
|
|
||
| @classmethod | ||
| def _missing_(cls, _value): | ||
| return cls.LOW | ||
|
|
||
|
|
||
| class EventType(Enum): | ||
| PROMOTIONAL = "promotional" | ||
| TRANSACTIONAL = "transactional" | ||
| OTP = "otp" | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -16,14 +16,21 @@ def get_sent_to_for_channel(cls, channel, request_body) -> list: | |
| send_address = list() | ||
| if channel in [cls.EMAIL.value]: | ||
| send_address = request_body.get('to', {}).get('email') or list() | ||
| send_address = [send_address[0]] if send_address else list() | ||
| elif channel in [cls.SMS.value, cls.WHATSAPP.value]: | ||
| send_address = request_body.get('to', {}).get('mobile') or list() | ||
| send_address = [send_address[0]] if send_address else list() | ||
| elif channel in [cls.PUSH.value]: | ||
| send_address = request_body.get('to', {}).get('device') or list() | ||
| return send_address | ||
|
|
||
| @classmethod | ||
| def get_source_identifier_for_event(cls, request_body): | ||
| return request_body["source_identifier"] | ||
| def get_source_identifier_for_event(cls, event_name, request_body): | ||
| # TODO add more logic for other apps of needed | ||
| source_identifier = None | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Discuss? |
||
| if 'body' in request_body: | ||
| body = request_body['body'] or dict() | ||
| if 'order' in body: | ||
| order = body['order'] or dict() | ||
| if 'order_id' in order or 'appointment_id' in order: | ||
| source_identifier = order.get('order_id') or order.get('appointment_id') | ||
| return source_identifier | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -30,9 +30,7 @@ class Providers(CustomEnum): | |
| NotificationChannels.EMAIL.value | ||
| ], | ||
| "configuration": { | ||
| "API_KEY": "", | ||
| "AWS_ACCESS_KEY_ID": "", | ||
| "AWS_ACCESS_KEY_SECRET": "", | ||
| "API_KEY": "" | ||
| } | ||
| } | ||
|
|
||
|
|
@@ -63,10 +61,11 @@ class Providers(CustomEnum): | |
| NotificationChannels.SMS.value | ||
| ], | ||
| "configuration": { | ||
| "PLIVO_SMS_URL": "", | ||
| "PLIVO_AUTH_ID": "", | ||
| "PLIVO_AUTH_TOKEN": "", | ||
| "PLIVO_SENDER_ID": "", | ||
| "PLIVO_CALLBACK_URL": "" | ||
| "PLIVO_CALLBACK_URL": "", | ||
| } | ||
| } | ||
|
|
||
|
|
@@ -81,7 +80,13 @@ class Providers(CustomEnum): | |
| "SMS_COUNTRY_USERNAME": "", | ||
| "SMS_COUNTRY_PASSWORD": "", | ||
| "SMS_COUNTRY_SENDER_ID": "", | ||
| "SMS_COUNTRY_URL": "" | ||
| "SMS_COUNTRY_OTP_USERNAME": "", | ||
| "SMS_COUNTRY_OTP_PASSWORD": "", | ||
| "SMS_COUNTRY_OTP_SENDER_ID": "", | ||
| "SMS_COUNTRY_DROPLET_USERNAME": "", | ||
| "SMS_COUNTRY_DROPLET_PASSWORD": "", | ||
| "SMS_COUNTRY_DROPLET_SENDER_ID": "", | ||
| "SMS_COUNTRY_URL": "", | ||
| } | ||
| } | ||
|
|
||
|
|
@@ -93,7 +98,36 @@ class Providers(CustomEnum): | |
| NotificationChannels.PUSH.value | ||
| ], | ||
| "configuration": { | ||
| "AUTH_KEY": "" | ||
| "PROJECT_ID": "", | ||
| "TYPE": "", | ||
| "PRIVATE_KEY_ID": "", | ||
| "PRIVATE_KEY": "", | ||
| "CLIENT_EMAIL": "", | ||
| "CLIENT_ID": "", | ||
| "TOKEN_URI": "", | ||
| "AUTH_URI": "", | ||
| "AUTH_PROVIDER_X509_CERT_URL": "", | ||
| "CLIENT_X509_CERT_URL": "", | ||
| "UNIVERSE_DOMAIN": "" | ||
| } | ||
| } | ||
|
|
||
| APNS = { | ||
| "name": "Apple Push Notification Service", | ||
| "code": "APNS", | ||
| "logo": "https://raw.githubusercontent.com/tata1mg/notifyone-core/refs/heads/notifyone/issues/14/media/logo/apns.png", | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why? |
||
| "channels": [ | ||
| NotificationChannels.PUSH.value | ||
| ], | ||
| "configuration": { | ||
| "HOST": "", | ||
| "ENDPOINT": "", | ||
| "BUNDLE_IDENTIFIER": "", | ||
| "REFRESH_TOKEN_DELAY": 1800, | ||
| "ALGORITHM": "", | ||
| "TEAM_ID": "", | ||
| "KEY_ID": "", | ||
| "PRIVATE_KEY": "" | ||
| } | ||
| } | ||
|
|
||
|
|
@@ -105,8 +139,23 @@ class Providers(CustomEnum): | |
| NotificationChannels.WHATSAPP.value | ||
| ], | ||
| "configuration": { | ||
| "CAPACITY": 0, | ||
| "AUTHORIZATION_TOKEN": "" | ||
| "APP_AUTHORIZATIONS": { | ||
| "corporate-service": "CORPORATE", | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Should be in config and not part of code. |
||
| "diagnostics": "DIAGNOSTICS", | ||
| "health_records": "DIAGNOSTICS", | ||
| "off": "PHARMACY", | ||
| "ppmc_api": "CORPORATE", | ||
| "validation_service": "PHARMACY", | ||
| "verification": "PHARMACY" | ||
| }, | ||
| "AUTHORIZATION": { | ||
| "CORPORATE": "", | ||
| "DEFAULT": "", | ||
| "DIAGNOSTICS": "", | ||
| "PHARMACY": "" | ||
| }, | ||
| "HOST": "https://api.interakt.ai", | ||
| "PATH": "/v1/public/message/" | ||
| } | ||
| } | ||
|
|
||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,13 @@ | ||
| from enum import Enum | ||
|
|
||
|
|
||
| class ExecutionDetailsSource(str, Enum): | ||
| INTERNAL = "INTERNAL" | ||
| WEBHOOK = "WEBHOOK" | ||
|
|
||
|
|
||
| class ExecutionDetailsEventStatus(str, Enum): | ||
| QUEUED = "QUEUED" | ||
| PENDING = "PENDING" | ||
| SUCCESS = "SUCCESS" | ||
| FAILED = "FAILED" |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,4 +1,9 @@ | ||
| from enum import Enum | ||
| class Whatsapp: | ||
| CONTENT_COLUMNS=['id','event_id','name'] | ||
| NAME = 'name' | ||
|
|
||
|
|
||
| class VariableMappingKeys(Enum): | ||
| BODY = "body" | ||
| HEADER = "header" | ||
| BUTTON = "button" |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,6 +1,6 @@ | ||
| from torpedo import CONFIG | ||
| from torpedo.constants import ListenerEventTypes | ||
|
|
||
| from asyncio import BaseEventLoop | ||
| from app.repositories.content_log import ContentLogRepository | ||
| from app.services import SubscribeNotificationRequest, SubscribeStatusUpdate | ||
| from app.services.email import EmailHandler | ||
|
|
@@ -37,11 +37,34 @@ async def setup_repositories(app, loop): | |
| ) | ||
|
|
||
|
|
||
| def exc_handler(self: BaseEventLoop, context: dict) -> None: | ||
| """ | ||
| Custom exception handler to filter out specific messages. | ||
| :param self: The event loop instance | ||
| :param context: The context dictionary containing exception details | ||
| :return: None | ||
| """ | ||
| message = context.get("message") | ||
| if message not in ["Unclosed connector", "Unclosed client session"]: | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Need to check if this for excluding these only. |
||
| BaseEventLoop.default_exception_handler(self, context) | ||
|
|
||
|
|
||
| async def setup_custom_exc_handler(app, loop): | ||
| """ | ||
| Set up the custom exception handler for the event loop. | ||
| :param app: The current app instance | ||
| :param loop: The running event loop | ||
| :return: None | ||
| """ | ||
| loop.set_exception_handler(exc_handler) | ||
|
|
||
|
|
||
| listeners = [ | ||
| (subscribe_for_notification_requests, ListenerEventTypes.AFTER_SERVER_START.value), | ||
| (subscribe_for_status_updates, ListenerEventTypes.AFTER_SERVER_START.value), | ||
| (setup_notification_channel_handlers, ListenerEventTypes.AFTER_SERVER_START.value), | ||
| (initialize_jinja_environment, ListenerEventTypes.AFTER_SERVER_START.value), | ||
| (setup_repositories, ListenerEventTypes.AFTER_SERVER_START.value), | ||
| (setup_options, ListenerEventTypes.BEFORE_SERVER_START.value), | ||
| (setup_custom_exc_handler, ListenerEventTypes.BEFORE_SERVER_START.value), | ||
| ] | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -7,22 +7,31 @@ | |
|
|
||
| class BaseManager: | ||
| @classmethod | ||
| async def update_trigger_limit(cls, event_type: str, agent_id: str, **kwargs): | ||
| async def update_trigger_limit_or_actions(cls, event_type: str, agent_id: str, **kwargs): | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Should be two different methods |
||
| app_name = kwargs["payload"].get("app_name") | ||
| event_name = kwargs["payload"].get("event_name") | ||
| event_id = kwargs["payload"].get("event_id") | ||
| data = await cls.common_validation_checks(app_name, event_name, event_id) | ||
| event_limit = kwargs["payload"].get("triggers_limit") | ||
|
|
||
| event_action = kwargs["payload"].get("actions") | ||
| values = { | ||
| "updated_by": agent_id, | ||
| } | ||
|
|
||
| if event_limit: | ||
| triggers_limit = data.triggers_limit | ||
| # as in some cases trigger_limit is instance of str. | ||
| triggers_limit[event_type] = int(event_limit) | ||
| updated_trigger_limit = triggers_limit | ||
| values = { | ||
| "updated_by": agent_id, | ||
| "triggers_limit": json.dumps(updated_trigger_limit), | ||
| } | ||
| values["triggers_limit"] = triggers_limit | ||
|
|
||
| if 'actions' in kwargs["payload"] and event_action is not None: | ||
| actions = data.actions | ||
| # as in some cases actions is instance of str. | ||
| actions[event_type] = int(event_action) | ||
| values["actions"] = actions | ||
|
|
||
| if event_limit or 'actions' in kwargs["payload"] and event_action is not None: | ||
| await EventRepository.update_event(app_name, event_name, values=values) | ||
|
|
||
| @staticmethod | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Utilise the existing one