ninadk
ninadk
NNovu
Created by ninadk on 4/2/2024 in #💬│support
Delete subscriber does not delete their notifications
Sure. Environment id: 659fb61f76272e378b87e463, subscriber id 4.
9 replies
NNovu
Created by ninadk on 4/2/2024 in #💬│support
Delete subscriber does not delete their notifications
Here's my code including how I re-create the subscribers after deleting.
// Delete all existing subscribers
const subscribers = await getAllSubscribers();
const deletePromises: Promise<unknown>[] = [];

subscribers.forEach(subscriber => {
deletePromises.push(deleteSubscriber(subscriber.subscriberId));
});

await Promise.all(deletePromises);

// Create subscribers from users
const addSubscriberPromises: Promise<unknown>[] = [];
users.forEach(user => {
addSubscriberPromises.push(createSubscriber(String(user.id), user.username, user.first_name || '', user.last_name || ''));
});

await Promise.all(addSubscriberPromises);
// Delete all existing subscribers
const subscribers = await getAllSubscribers();
const deletePromises: Promise<unknown>[] = [];

subscribers.forEach(subscriber => {
deletePromises.push(deleteSubscriber(subscriber.subscriberId));
});

await Promise.all(deletePromises);

// Create subscribers from users
const addSubscriberPromises: Promise<unknown>[] = [];
users.forEach(user => {
addSubscriberPromises.push(createSubscriber(String(user.id), user.username, user.first_name || '', user.last_name || ''));
});

await Promise.all(addSubscriberPromises);
9 replies
NNovu
Created by ninadk on 3/17/2024 in #💬│support
User avatar not uploaded
I tried updating the lastName this time, but it didn't work.
30 replies
NNovu
Created by ninadk on 3/17/2024 in #💬│support
User avatar not uploaded
Still no lack... Here's the updated code:
const subscriberInfo = { firstName, lastName, email, avatar };

const options = {
method: 'PUT',
headers: { Authorization: `ApiKey ${NOVU_API_KEY}` },
body: subscriberInfo as unknown as BodyInit,
};

const res = await fetch(`https://api.novu.co/v1/subscribers/${subscriberId}`, options)
.then((response) => response.json())
.then((response) => response.data)
.catch((err) => {
console.error(err);
return { error: `Could not update subscriber ${subscriberId}.` };
});
const subscriberInfo = { firstName, lastName, email, avatar };

const options = {
method: 'PUT',
headers: { Authorization: `ApiKey ${NOVU_API_KEY}` },
body: subscriberInfo as unknown as BodyInit,
};

const res = await fetch(`https://api.novu.co/v1/subscribers/${subscriberId}`, options)
.then((response) => response.json())
.then((response) => response.data)
.catch((err) => {
console.error(err);
return { error: `Could not update subscriber ${subscriberId}.` };
});
And what subscriberInfo looks like:
{
firstName: 'Radu',
lastName: 'A C',
avatar: 'https://hips.hearstapps.com/hmg-prod/images/beautiful-smooth-haired-red-cat-lies-on-the-sofa-royalty-free-image-1678488026.jpg'
}
{
firstName: 'Radu',
lastName: 'A C',
avatar: 'https://hips.hearstapps.com/hmg-prod/images/beautiful-smooth-haired-red-cat-lies-on-the-sofa-royalty-free-image-1678488026.jpg'
}
The image URL is random.
30 replies
NNovu
Created by ninadk on 3/17/2024 in #💬│support
User avatar not uploaded
Could you help me out re the fetch call? Am I doing something wrong there?
30 replies
NNovu
Created by ninadk on 3/17/2024 in #💬│support
User avatar not uploaded
Good to know! It's a valid url though.
30 replies
NNovu
Created by ninadk on 3/17/2024 in #💬│support
User avatar not uploaded
It is valid.
subscriberInfo: {
firstName: 'shwetank',
lastName: '',
avatar: 'https://res.cloudinary.com/dwlk6urra/image/upload/v1710605561/profile-pics/antonina:2'
}
subscriberInfo: {
firstName: 'shwetank',
lastName: '',
avatar: 'https://res.cloudinary.com/dwlk6urra/image/upload/v1710605561/profile-pics/antonina:2'
}
And the other information is not updated either with the fetch.
30 replies
NNovu
Created by ninadk on 3/17/2024 in #💬│support
User avatar not uploaded
Yes I just checked. Though i wasn't able to do the same using a fetch request programmatically:
const subscriberInfo = { firstName, lastName, email, avatar: imageUrl };

const options = {
method: 'PUT',
headers: { Authorization: `ApiKey ${NOVU_API_KEY}` },
body: JSON.stringify(subscriberInfo),
};

const res = await fetch(`https://api.novu.co/v1/subscribers/${subscriberId}`, options)
.then((response) => response.json())
.then((response) => response.data)
.catch((err) => {
console.error(err);
return { error: `Could not update subscriber ${subscriberId}.` };
});
const subscriberInfo = { firstName, lastName, email, avatar: imageUrl };

const options = {
method: 'PUT',
headers: { Authorization: `ApiKey ${NOVU_API_KEY}` },
body: JSON.stringify(subscriberInfo),
};

const res = await fetch(`https://api.novu.co/v1/subscribers/${subscriberId}`, options)
.then((response) => response.json())
.then((response) => response.data)
.catch((err) => {
console.error(err);
return { error: `Could not update subscriber ${subscriberId}.` };
});
30 replies
NNovu
Created by ninadk on 3/17/2024 in #💬│support
User avatar not uploaded
That worked! I tried it directly on your website. Should I use a fetch instead of the update method then?
30 replies
NNovu
Created by ninadk on 3/17/2024 in #💬│support
User avatar not uploaded
I just tried again. I can see the other information I'm updating on my subscribers dashboard, but not the avatar.
30 replies
NNovu
Created by ninadk on 3/17/2024 in #💬│support
User avatar not uploaded
Yes, I did. This could be because every time I re-seed the database I also delete all subscribers and re-create them.
30 replies
NNovu
Created by ninadk on 3/17/2024 in #💬│support
User avatar not uploaded
sure 659fb61f76272e378b87e463
30 replies
NNovu
Created by ninadk on 3/17/2024 in #💬│support
User avatar not uploaded
This is my code for triggering the notification:
await novu.trigger('join-neighborhood', {
to: {
subscriberId: adminId,
},
actor: {
subscriberId: userId,
},
payload: {
neighborhoodId,
neighborhoodName,
username,
userId,
},
});
await novu.trigger('join-neighborhood', {
to: {
subscriberId: adminId,
},
actor: {
subscriberId: userId,
},
payload: {
neighborhoodId,
neighborhoodName,
username,
userId,
},
});
I believe the issue is that the avatar doesn't even get set, though, as shown in the return of the update method I pasted above (3rd snippet).
30 replies
NNovu
Created by ninadk on 3/17/2024 in #💬│support
User avatar not uploaded
Yeap
30 replies
NNovu
Created by ninadk on 1/15/2024 in #💬│support
Hide action buttons after click
thank you, that worked! I also removed QueryClientProvider altogether, afterwords, it seems it's not necessary anymore.
8 replies
NNovu
Created by ninadk on 1/15/2024 in #💬│support
Hide action buttons after click
Thank you for your response! I added the code as suggested to mark the action as done after a click, but it still seemed to only remove the buttons when I marked the notifications as read. I opted to mark the notification as read programmatically after the action button is clicked, and bumped into this error: No QueryClient set, use QueryClientProvider to set one. After wrapping the application with QueryClientProvider it doesn't seem to go away. Any ideas?
import {QueryClient, QueryClientProvider} from '@tanstack/react-query';
const queryClient = new QueryClient();
root.render(
<UserContextProvider>
<React.StrictMode>
<QueryClientProvider client={queryClient}>
<App />
</QueryClientProvider>
</React.StrictMode>
</UserContextProvider>,
);
import {QueryClient, QueryClientProvider} from '@tanstack/react-query';
const queryClient = new QueryClient();
root.render(
<UserContextProvider>
<React.StrictMode>
<QueryClientProvider client={queryClient}>
<App />
</QueryClientProvider>
</React.StrictMode>
</UserContextProvider>,
);
const Notification = () => {
const handleOnActionClick = async (temp: string, btnType: string, notification: IMessage) => {
if (temp === 'join-neighborhood' && btnType === 'primary') {
const {userId, neighborhoodId} = notification.payload;
try {
await neighborhoodServices.connectUserToNeighborhood(+userId,+neighborhoodId);
} catch (e) {
console.log(e);
} finally {
markNotificationsAs({ messageId: notification._id, read: true, seen: true });
await notificationServices.updateAction(notification._id, btnType, MessageActionStatusEnum.DONE);
}
}
};
return (
<NovuProvider
initialFetchingStrategy={{ fetchNotifications: true }}
subscriberHash={user?.hashedSubscriberId} subscriberId={String(user?.id)} applicationIdentifier={'my app id'}>
<PopoverNotificationCenter
colorScheme={'light'}
onNotificationClick={handleOnNotificationClick}
onActionClick={handleOnActionClick}>
{({ unseenCount }) => <NotificationBell unseenCount={unseenCount} />}
</PopoverNotificationCenter>
</NovuProvider>
);
};
const Notification = () => {
const handleOnActionClick = async (temp: string, btnType: string, notification: IMessage) => {
if (temp === 'join-neighborhood' && btnType === 'primary') {
const {userId, neighborhoodId} = notification.payload;
try {
await neighborhoodServices.connectUserToNeighborhood(+userId,+neighborhoodId);
} catch (e) {
console.log(e);
} finally {
markNotificationsAs({ messageId: notification._id, read: true, seen: true });
await notificationServices.updateAction(notification._id, btnType, MessageActionStatusEnum.DONE);
}
}
};
return (
<NovuProvider
initialFetchingStrategy={{ fetchNotifications: true }}
subscriberHash={user?.hashedSubscriberId} subscriberId={String(user?.id)} applicationIdentifier={'my app id'}>
<PopoverNotificationCenter
colorScheme={'light'}
onNotificationClick={handleOnNotificationClick}
onActionClick={handleOnActionClick}>
{({ unseenCount }) => <NotificationBell unseenCount={unseenCount} />}
</PopoverNotificationCenter>
</NovuProvider>
);
};
8 replies