diff --git a/packages/rule-handler/src/filter.ts b/packages/rule-handler/src/filter.ts index 907c8d88f..76ed4d6bd 100644 --- a/packages/rule-handler/src/filter.ts +++ b/packages/rule-handler/src/filter.ts @@ -17,6 +17,8 @@ interface Page { labels?: Label[] // labels is optional in the API response isArchived: boolean readingProgressPercent: number + title: string + image?: string } interface Label { @@ -41,6 +43,8 @@ export const search = async ( } isArchived readingProgressPercent + title + image } } } diff --git a/packages/rule-handler/src/notification.ts b/packages/rule-handler/src/notification.ts index a03ddc323..79c5c2a52 100644 --- a/packages/rule-handler/src/notification.ts +++ b/packages/rule-handler/src/notification.ts @@ -8,13 +8,17 @@ interface RequestData { notificationType?: string } +export interface NotificationData { + body: string + title?: string + image?: string + data?: Record +} + export const sendNotification = async ( apiEndpoint: string, auth: string, - body: string, - title?: string, - image?: string, - data?: Record + { body, title, image, data }: NotificationData ) => { const requestData: RequestData = { body, diff --git a/packages/rule-handler/src/rule.ts b/packages/rule-handler/src/rule.ts index e8e5a7ce0..605fa4e83 100644 --- a/packages/rule-handler/src/rule.ts +++ b/packages/rule-handler/src/rule.ts @@ -1,4 +1,4 @@ -import { sendNotification } from './notification' +import { NotificationData, sendNotification } from './notification' import { getAuthToken, PubSubData } from './index' import axios, { AxiosResponse } from 'axios' import { setLabels } from './label' @@ -122,14 +122,26 @@ export const triggerActions = async ( filteredPage.readingProgressPercent < 100 && actionPromises.push(markPageAsRead(apiEndpoint, authToken, data.id)) ) - case RuleActionType.SendNotification: + case RuleActionType.SendNotification: { + const data: NotificationData = { + title: 'New page added to your feed', + body: filteredPage.title, + image: filteredPage.image, + } + + const params = action.params + if (params.length > 0) { + const param = JSON.parse(params[0]) as NotificationData + data.body = param.body + data.title = param.title + data.image = param.image + data.data = param.data + } + return actionPromises.push( - sendNotification( - apiEndpoint, - authToken, - 'New page added to your feed' - ) + sendNotification(apiEndpoint, authToken, data) ) + } } }) }