Get notification data from params
This commit is contained in:
@ -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
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -8,13 +8,17 @@ interface RequestData {
|
||||
notificationType?: string
|
||||
}
|
||||
|
||||
export interface NotificationData {
|
||||
body: string
|
||||
title?: string
|
||||
image?: string
|
||||
data?: Record<string, string>
|
||||
}
|
||||
|
||||
export const sendNotification = async (
|
||||
apiEndpoint: string,
|
||||
auth: string,
|
||||
body: string,
|
||||
title?: string,
|
||||
image?: string,
|
||||
data?: Record<string, string>
|
||||
{ body, title, image, data }: NotificationData
|
||||
) => {
|
||||
const requestData: RequestData = {
|
||||
body,
|
||||
|
||||
@ -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)
|
||||
)
|
||||
}
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user