-
Notifications
You must be signed in to change notification settings - Fork 15
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor: add send notification method to service
Signed-off-by: Sai Ranjit Tummalapalli <[email protected]>
- Loading branch information
Showing
4 changed files
with
53 additions
and
62 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,32 +1,18 @@ | ||
import type { ForwardMessageEvent } from '@aries-framework/core' | ||
|
||
import { RecordDuplicateError, RoutingEventTypes } from '@aries-framework/core' | ||
import { sendNotificationEvent } from './PushNotificationEvent' | ||
import { RoutingEventTypes } from '@aries-framework/core' | ||
import { MediatorAgent } from '../agent' | ||
|
||
export const routingEvents = async (agent: MediatorAgent) => { | ||
agent.events.on(RoutingEventTypes.ForwardMessageEvent, async (event: ForwardMessageEvent) => { | ||
try { | ||
const record = event.payload.connectionRecord | ||
|
||
// Get device info from PushNotificationsFcmRecord | ||
const fcmDeviceInfoRecord = await agent.modules.pushNotificationsFcm.getDeviceInfoByConnectionId(record.id) | ||
|
||
if (fcmDeviceInfoRecord?.deviceToken) { | ||
agent.config.logger.info(`Sending notification to ${fcmDeviceInfoRecord.connectionId}`) | ||
// Send notification to device | ||
await sendNotificationEvent(fcmDeviceInfoRecord, agent.config.logger) | ||
} else { | ||
agent.config.logger.info(`No device token found for connectionId so skipping send notification event`) | ||
} | ||
await agent.modules.pushNotificationsFcm.sendNotification(record.id) | ||
} catch (error) { | ||
if (error instanceof RecordDuplicateError) { | ||
agent.config.logger.error(`Multiple device info found for connectionId ${event.payload.connectionRecord.id}`) | ||
} else { | ||
agent.config.logger.error(`Error sending notification`, { | ||
cause: error, | ||
}) | ||
} | ||
agent.config.logger.error(`Error sending notification`, { | ||
cause: error, | ||
}) | ||
} | ||
}) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters