Merge pull request #1526 from omnivore-app/recommend-push-notification

recommend push notification
This commit is contained in:
Hongbo Wu 2022-12-09 11:17:05 +08:00 committed by GitHub
commit 7111581b67
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 38 additions and 12 deletions

View file

@ -221,7 +221,14 @@ export const createLabelAndRuleForGroup = async (
},
{
type: RuleActionType.SendNotification,
params: [groupName],
params: [
`
{
"title": "New page recommended in ${groupName}",
"body": "A new page was added to the group ${groupName}"
}
`,
],
},
],
filter: `recommendedBy:"${groupName}"`,

View file

@ -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
}
}
}

View file

@ -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,

View file

@ -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,25 @@ 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 library',
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.body
data.title = param.title || data.title
data.image = param.image || data.image
}
return actionPromises.push(
sendNotification(
apiEndpoint,
authToken,
'New page added to your feed'
)
sendNotification(apiEndpoint, authToken, data)
)
}
}
})
}