Notification connector
Design & Implementation
Module Information
Module Name:
openg2p-g2p-bridge-notification-connectorsLocation:
/openg2p-g2p-bridge-notification-connectors/Primary Implementation:
NovuNotifier
Interface Definition
File: interface/notification_interface.py
class NotificationInterface(BaseService):
def send_notification(
self,
notification_id: str,
payload: Any,
notification_type: NotificationType,
recipient: Recipient,
) -> None:
"""
Send a notification to a list of recipients.
"""
passData Models
Method Parameters
notification_id (str): Unique identifier for the notification
payload (Any): Custom payload to include in the notification (can be dict or any JSON-serializable object)
notification_type (NotificationType): Type of notification (AGENCY, WAREHOUSE, or BENEFICIARY)
recipient (Recipient): Recipient details including email, phone, name
Return Value
NotificationResponse: Contains notification_id, response (str from Novu), and status (SUCCESS or FAILURE)
Reference Implementation: NovuNotifier
File: implementations/novu_notifier.py
Integration with Novu Platform
The implementation uses the novu_py library to send notifications through the Novu platform.
Algorithm
Key Characteristics
Novu Client Context Manager: Uses
with Novu(...)for proper resource cleanupWorkflow-Based: Maps notification types to configured Novu workflow IDs
Email-Based Delivery: Currently sends to
recipient.recipient_emailResponse Parsing: Checks
novu_response.result.status.valuefor success/failure determinationLogging: Uses logger name "novu_notifier_impl"
INFO: Notification sent, API key and workflow ID used, Novu response
No exception raising for Novu failures - returns FAILURE status instead
Factory Pattern
File: factory/notification_factory.py
Configuration
File: config.py
Configuration uses Pydantic Settings with environment variable prefix g2p_bridge_notification_connectors_:
Configuration Parameters
novu_url
http://localhost:3000
Novu server URL
novu_api_key
149f3f3dff5493729136246b9454f315
Novu API authentication key
novu_warehouse_workflow_id
warehouse-notification
Workflow ID for warehouse notifications
novu_agency_workflow_id
agency-notification
Workflow ID for agency notifications
novu_beneficiary_workflow_id
beneficiary-notification
Workflow ID for beneficiary notifications
Data Models Detail
Recipient Model
NotificationResponse Model
Supported Notification Types
The implementation supports three notification types via enum:
AGENCY_NOTIFICATION
Uses workflow_id from
novu_agency_workflow_idconfigUse case: Notifications sent to agencies/operational partners
WAREHOUSE_NOTIFICATION
Uses workflow_id from
novu_warehouse_workflow_idconfigUse case: Notifications sent to warehouse operators
BENEFICIARY_NOTIFICATION
Uses workflow_id from
novu_beneficiary_workflow_idconfigUse case: Notifications sent to direct beneficiaries
Novu Integration Details
TriggerEventRequestDto
The implementation creates a novu_py.TriggerEventRequestDto with:
workflow_id: The Novu workflow to trigger
payload: Custom data for the notification (dict or JSON-serializable)
to: Recipient email address (recipient.recipient_email)
overrides: Empty Overrides object (no custom overrides currently set)
Response Handling
Novu response processing:
Accesses
novu_response.result.status.valueto check if status is "processed"Returns status as SUCCESS if processed, FAILURE otherwise
Converts entire result object to string for response field
Error Handling
ValueError: Raised if notification_type is not one of the three supported types
Novu Exceptions: Would propagate from novu_py library if HTTP/network errors occur
Response Status Handling: Non-"processed" statuses result in FAILURE status, not exceptions
HTTP Client Configuration
Library:
novu_py(Python SDK for Novu platform)Server: Configured via
novu_urlsettingAuthentication: API key via
novu_api_keysettingContext Manager: Uses Python context manager for connection lifecycle
Logging
All logging uses logger name: novu_notifier_impl
INFO: Notification sending initiated with recipient email
INFO: API key and workflow ID being used
INFO: Novu response received and parsed
DEBUG: Response details from Novu
Integration Pattern
Key Implementation Notes
Email-only Delivery: Currently only sends to
recipient.recipient_email. Recipient phone is accepted in model but not used.Payload Flexibility: The payload parameter is
Anytype, allowing flexible data structuresNo Exception on Failure: Notification failures return FAILURE status in response rather than raising exceptions
Workflow Mapping: Notification type maps to pre-configured Novu workflow IDs, allowing different workflows per notification type
Context Manager: Novu client uses context manager to ensure proper resource cleanup
Async-Compatible: The synchronous implementation can be called from async contexts in Celery workers
Limitations/Considerations
Only sends to email addresses; SMS/push notification support would require workflow configuration in Novu
No retry logic in implementation; Celery task retries would handle failed sends
Payload is passed as-is to Novu; no validation or transformation of payload structure
No tracking of notification delivery status beyond initial trigger response
API key is hardcoded in default config; should be overridden via environment variable in production
Last updated
Was this helpful?