Interactive Push Notifications

I’m trying to send interactive push notifications (notifications with buttons). I can send normal remote and local push notifications fine, however I cannot send remote interactive push notifications only local ones.

As per this section in the docs, I create a category:

Notifications.createCategoryAsync('daily_question', [
    {
        actionId: 'yes',
        buttonTitle: 'Yes',
    },
    {
        actionId: 'no',
        buttonTitle: 'No',
    },
]);

And on the backend I add the _category key to the message object as per this section in the docs.

For the _category key in the message object I’ve tried both daily_question and @username/appName:daily_question for the values, but neither add the interactive buttons.

So far, as a work around, I have two notifications show, one remote and one local (with the interactive buttons in the notification card) but this doesn’t seem like a good solution as I really only want to send one notification to the user. My solution for this is as follows:

let notificationReceived = false;

Notifications.addListener(() => {
    if (notificationReceived) {
        return;
    }

    notificationReceived = true;

    Notifications.presentLocalNotificationAsync({
        title: '...',
        body: '...',
        categoryId: 'daily_question',
    });
});

Is there a way to send a message, to the app, from the server, in a background process (without showing a notification) and then let the app handle showing a local notification with interactive buttons?

@finervision
I have the same problem, I can only generate interactive notification locally but not remotely.
you can remove the remote notification in the listener function and add only the interactive local one use this API

Notifications.dismissNotificationAsync(notification.notificationId);

Before generating the interactive local notification.

the problem now is if the app is neither foreground nor background. if the app is closed the listener function will not be called except when you tab the remote notification in the notification bar.

the question is can I directly generate interactive remote notification using expo ?

1 Like

This topic was automatically closed 15 days after the last reply. New replies are no longer allowed.