NovuN
Novuβ€’2w agoβ€’
7 replies
DEV-OTDC

Send push notification but without trigger browser notification

I understand that when I trigger a workflow, it will trigger browser to display a notification. But I want to do different with workflow, I want like in-app, where user click at that notification, it will redirect user to my site instead of disappear when click on notification.

I tried already with small scripts but doesn't work:
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);
});
Was this page helpful?