const payload = {
characterName: 'Emma',
characterImage: 'https://imagedelivery.net/your-account/character-emma/public',
message: 'Hey! I miss chatting with you... ๐',
unreadCount: 3,
ctaUrl: 'https://bonza.chat/chat/emma',
// Add title/body for Novu workflow template variables
title: 'Emma sent you a message ๐',
body: 'Hey! I miss chatting with you... ๐'
};
await novu.trigger({
workflowId: "test",
to: [
{
type: 'Topic',
topicKey: TOPIC_ID,
channels: [
{ ProviderId: 'fcm' }
]
}],
payload,
overrides: {
fcm: {
// Send data-only message (no notification field)
// This ensures ONLY the service worker handles the notification
data: {
title: String(payload.title),
body: String(payload.body),
characterName: String(payload.characterName),
characterImage: String(payload.characterImage),
message: String(payload.message),
unreadCount: String(payload.unreadCount),
ctaUrl: String(payload.ctaUrl)
}
}
}
}).then((response) => {
console.log('โ
Notification triggered successfully:', response);
console.log('๐ฆ Payload sent:', payload);
}).catch((error) => {
console.error('โ Failed to trigger notification:', error);
});
const payload = {
characterName: 'Emma',
characterImage: 'https://imagedelivery.net/your-account/character-emma/public',
message: 'Hey! I miss chatting with you... ๐',
unreadCount: 3,
ctaUrl: 'https://bonza.chat/chat/emma',
// Add title/body for Novu workflow template variables
title: 'Emma sent you a message ๐',
body: 'Hey! I miss chatting with you... ๐'
};
await novu.trigger({
workflowId: "test",
to: [
{
type: 'Topic',
topicKey: TOPIC_ID,
channels: [
{ ProviderId: 'fcm' }
]
}],
payload,
overrides: {
fcm: {
// Send data-only message (no notification field)
// This ensures ONLY the service worker handles the notification
data: {
title: String(payload.title),
body: String(payload.body),
characterName: String(payload.characterName),
characterImage: String(payload.characterImage),
message: String(payload.message),
unreadCount: String(payload.unreadCount),
ctaUrl: String(payload.ctaUrl)
}
}
}
}).then((response) => {
console.log('โ
Notification triggered successfully:', response);
console.log('๐ฆ Payload sent:', payload);
}).catch((error) => {
console.error('โ Failed to trigger notification:', error);
});