N
Novu2w ago
loup

Best way to sync subscribers settings with Postgres database

I have my backedn using postgres db. I have a table user :
id
username
avatar_url
language
id
username
avatar_url
language
How can I sync this table with the subscriber setting in Novu ? I could use Postgres trigger when there is a change in postgres db and make the request too Novu ?
7 Replies
Novu_Bot
Novu_Bot2w ago
@loup, you just advanced to level 1!
Tomer Barnea
Tomer Barnea2w ago
Hi @loup looking on the docs about subscribers (https://docs.novu.co/concepts/subscribers), there multiple fields that fit your needs. Check out the image
Novu
What is Novu - Novu
Novu is a full-stack (UI Components, API, and Framework) open source notification infrastructure platform for building, managing, delivering, and monitoring all types of end-user notifications.
No description
loup
loupOP2w ago
Im using Supabase as backend so my idea is when user table is updated, I launch an edge function which gonna update the subscriber in Novu
Tomer Barnea
Tomer Barnea2w ago
Makes sense 👍
loup
loupOP2w ago
Btw, when Novu send a notification, its raw msg right ? I means by that. Imagine I have translation for each notification. The user have as main language 'en-US'. So he receive an english notification. But 2 days later he change to 'fr-FR', the previous notifications wouldnt be translated right ?
Pawan Jain
Pawan Jain4d ago
@loup Yes you are right, old message will not be translated to fr-FR @loup Do you need more help in this?
loup
loupOP4d ago
There is my solution. Ive created an ExpressJS api to make communicate my backend (Supabase) with Novu. And inside this express if create a worflow with the new code based method, there is an example :
export const guidelistSentWorkflow = workflow('guidelist_sent', async ({ payload, step, subscriber }) => {
await step.inApp('notify-in-app', () => ({
subject: translationService.translate('guidelist.sent.in_app.subject', subscriber.locale),
body: translationService.translate('guidelist.sent.in_app.body', subscriber.locale, {
userUsername: payload.sender.username,
movieTitle: payload.movie.title,
movieSlug: payload.movie.slug
}),
avatar: payload.sender.avatar || undefined,
redirect: {
url: `/collection/guidelist#${payload.id}`
}
}));

await step.push('notify-push', () => ({
subject: translationService.translate('guidelist.sent.push.subject', subscriber.locale),
body: translationService.translate('guidelist.sent.push.body', subscriber.locale, {
userUsername: payload.sender.username,
movieTitle: payload.movie.title
}),
}));
}, {
tags: ['guidelist'],
payloadSchema: z.object({
id: z.number().int().describe('The ID of the guidelist'),
sender: z.object({
username: z.string().describe('The user who sent the guidelist'),
avatar: z
.string()
.nullable()
.optional()
.describe('The avatar of the user who sent the guidelist')
}),
movie: z.object({
title: z.string().describe('The movie that was recommended'),
slug: z.string().describe('The slug of the movie that was recommended')
}),
})
});
export const guidelistSentWorkflow = workflow('guidelist_sent', async ({ payload, step, subscriber }) => {
await step.inApp('notify-in-app', () => ({
subject: translationService.translate('guidelist.sent.in_app.subject', subscriber.locale),
body: translationService.translate('guidelist.sent.in_app.body', subscriber.locale, {
userUsername: payload.sender.username,
movieTitle: payload.movie.title,
movieSlug: payload.movie.slug
}),
avatar: payload.sender.avatar || undefined,
redirect: {
url: `/collection/guidelist#${payload.id}`
}
}));

await step.push('notify-push', () => ({
subject: translationService.translate('guidelist.sent.push.subject', subscriber.locale),
body: translationService.translate('guidelist.sent.push.body', subscriber.locale, {
userUsername: payload.sender.username,
movieTitle: payload.movie.title
}),
}));
}, {
tags: ['guidelist'],
payloadSchema: z.object({
id: z.number().int().describe('The ID of the guidelist'),
sender: z.object({
username: z.string().describe('The user who sent the guidelist'),
avatar: z
.string()
.nullable()
.optional()
.describe('The avatar of the user who sent the guidelist')
}),
movie: z.object({
title: z.string().describe('The movie that was recommended'),
slug: z.string().describe('The slug of the movie that was recommended')
}),
})
});
To manage translation I have a dictionnaries (en-US.json, fr-FR.json, ...). And the language depend of the user language. Is it a good configuration ?
Want results from more Discord servers?
Add your server