Add title and image url in notification
This commit is contained in:
@ -19,9 +19,10 @@ interface PubSubRequestBody {
|
||||
}
|
||||
|
||||
export interface PubSubData {
|
||||
subscription: string
|
||||
userId: string
|
||||
type: EntityType
|
||||
subscription?: string
|
||||
image?: string
|
||||
}
|
||||
|
||||
enum EntityType {
|
||||
|
||||
@ -94,7 +94,14 @@ export const triggerActions = async (
|
||||
console.log('No notification messages provided')
|
||||
continue
|
||||
}
|
||||
await sendNotification(userId, action.params, apiEndpoint, jwtSecret)
|
||||
await sendNotification(
|
||||
userId,
|
||||
data.subscription,
|
||||
action.params,
|
||||
apiEndpoint,
|
||||
jwtSecret,
|
||||
data.image
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -102,16 +109,21 @@ export const triggerActions = async (
|
||||
|
||||
export const sendNotification = async (
|
||||
userId: string,
|
||||
subscription: string,
|
||||
messages: string[],
|
||||
apiEndpoint: string,
|
||||
jwtSecret: string
|
||||
jwtSecret: string,
|
||||
image?: string
|
||||
) => {
|
||||
const title = `📫 - ${subscription} has published a new article`
|
||||
// get device tokens by calling api
|
||||
const tokens = await getDeviceTokens(userId, apiEndpoint, jwtSecret)
|
||||
|
||||
const batchMessages = getBatchMessages(
|
||||
title,
|
||||
messages,
|
||||
tokens.map((t) => t.token)
|
||||
tokens.map((t) => t.token),
|
||||
image
|
||||
)
|
||||
|
||||
return sendBatchPushNotifications(batchMessages)
|
||||
|
||||
@ -56,8 +56,10 @@ export const getDeviceTokens = async (
|
||||
}
|
||||
|
||||
export const getBatchMessages = (
|
||||
title: string,
|
||||
messages: string[],
|
||||
tokens: string[]
|
||||
tokens: string[],
|
||||
imageUrl?: string
|
||||
): Message[] => {
|
||||
const batchMessages: Message[] = []
|
||||
messages.forEach((message) => {
|
||||
@ -65,7 +67,9 @@ export const getBatchMessages = (
|
||||
batchMessages.push({
|
||||
token,
|
||||
notification: {
|
||||
title,
|
||||
body: message,
|
||||
imageUrl,
|
||||
},
|
||||
})
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user