ninadk
ninadk
NNovu
Created by ninadk on 4/2/2024 in #💬│support
Delete subscriber does not delete their notifications
I am deleting the test subscribers when re-seeding the db with the following code:
export async function deleteSubscriber(subscriberId: string) {
try {
return await novu.subscribers.delete(subscriberId);
} catch (error: unknown) {
console.error(error);
return { error: 'Error deleting subscribers.' };
}
}

const subscribers = await getAllSubscribers();
const deletePromises: Promise<unknown>[] = [];

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

await Promise.all(deletePromises);
export async function deleteSubscriber(subscriberId: string) {
try {
return await novu.subscribers.delete(subscriberId);
} catch (error: unknown) {
console.error(error);
return { error: 'Error deleting subscribers.' };
}
}

const subscribers = await getAllSubscribers();
const deletePromises: Promise<unknown>[] = [];

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

await Promise.all(deletePromises);
The promises all seem to resolve successfully. But when I recreate the subscribers, the ones that take on an ID of a previously existing subscriber have their notifications show up. The docs suggest that deleting a subscriber will cascade on their notifications so I'm not sure what the problem is. Could it have to do with active/pending notifications? Note that even though the notification shows up and is returned from the get sub notifications API, when I tried to act on it, I got the following 400 error: message: "Message with the id: 660bd381d787d568ef3afe3b was not found for this environment. Make sure to address correct message before trying t…".
9 replies
NNovu
Created by ninadk on 3/17/2024 in #💬│support
User avatar not uploaded
I'm updating the user info passing in a link for the user avatar, but the avatar field doesn't show at all in the update response (or get), and the avatar doesn't display in the UI. Here's part of the code and the outputs from what the input and output data looks like:
const res = await novu.subscribers.update(subscriberId, {
firstName,
lastName,
email,
avatar: imageUrl,
});
const res = await novu.subscribers.update(subscriberId, {
firstName,
lastName,
email,
avatar: imageUrl,
});
{
subscriberId: '2',
firstName: 'Antonina',
lastName: 'K',
avatar: 'https://res.cloudinary.com/dwlk6urra/image/upload/v1710605561/profile-pics/2'
}
{
subscriberId: '2',
firstName: 'Antonina',
lastName: 'K',
avatar: 'https://res.cloudinary.com/dwlk6urra/image/upload/v1710605561/profile-pics/2'
}
{
subscriberInfo: {
_id: 'user-id',
_organizationId: 'my-id',
_environmentId: 'my-env-id',
firstName: 'Antonina',
lastName: 'K',
subscriberId: '2',
channels: [],
data: { username: 'antonina' },
deleted: false,
createdAt: '2024-03-13T08:30:28.218Z',
updatedAt: '2024-03-17T12:30:18.023Z',
__v: 0,
isOnline: false,
lastOnlineAt: '2024-03-17T12:30:17.661Z',
id: 'user-id'
}
}
{
subscriberInfo: {
_id: 'user-id',
_organizationId: 'my-id',
_environmentId: 'my-env-id',
firstName: 'Antonina',
lastName: 'K',
subscriberId: '2',
channels: [],
data: { username: 'antonina' },
deleted: false,
createdAt: '2024-03-13T08:30:28.218Z',
updatedAt: '2024-03-17T12:30:18.023Z',
__v: 0,
isOnline: false,
lastOnlineAt: '2024-03-17T12:30:17.661Z',
id: 'user-id'
}
}
Note that the other info is updated successfully. I've also activated the avatar and selected "user avatar" for this workflow in the dashboard. Am I missing something here?
30 replies
NNovu
Created by ninadk on 1/15/2024 in #💬│support
Hide action buttons after click
Is there a way to hide the action buttons below a notification after one of them is clicked? For example, when making a request, I want to hide the buttons after the receiver of the notification clicks "Accept" to accept it. Here's the related code so far:
const hanlderOnActionClick = async (temp: string, btnType: string, notification: IMessage) => {
if (temp === 'join-neighborhood' && btnType === 'primary') {
const { userId, neighborhoodId } = notification.payload;
try {
const res = await neighborhoodServices.connectUserToNeighborhood(
Number(userId),
Number(neighborhoodId),
);
if ('success' in res) notification.content = res.success;
} catch (error) {
console.log(error);
}
}
};

return (
<NovuProvider
initialFetchingStrategy={{ fetchNotifications: true }}
subscriberHash={user?.hashedSubscriberId}
subscriberId={String(user?.id)}
applicationIdentifier={'my app identifier'}>
<PopoverNotificationCenter
colorScheme={'light'}
onNotificationClick={handlerOnNotificationClick}
onActionClick={hanlderOnActionClick}>
{({ unseenCount }) => <NotificationBell unseenCount={unseenCount} />}
</PopoverNotificationCenter>
</NovuProvider>
);
const hanlderOnActionClick = async (temp: string, btnType: string, notification: IMessage) => {
if (temp === 'join-neighborhood' && btnType === 'primary') {
const { userId, neighborhoodId } = notification.payload;
try {
const res = await neighborhoodServices.connectUserToNeighborhood(
Number(userId),
Number(neighborhoodId),
);
if ('success' in res) notification.content = res.success;
} catch (error) {
console.log(error);
}
}
};

return (
<NovuProvider
initialFetchingStrategy={{ fetchNotifications: true }}
subscriberHash={user?.hashedSubscriberId}
subscriberId={String(user?.id)}
applicationIdentifier={'my app identifier'}>
<PopoverNotificationCenter
colorScheme={'light'}
onNotificationClick={handlerOnNotificationClick}
onActionClick={hanlderOnActionClick}>
{({ unseenCount }) => <NotificationBell unseenCount={unseenCount} />}
</PopoverNotificationCenter>
</NovuProvider>
);
I tried using useNotifications to update the status of the notification to see if that'd do it, but the hook returns null for some reason, even though I've set fetchNotifications to true. Thanks in advance!
8 replies