HackerOne users: Testing against this community violates our program's Terms of Service and will result in your bounty being denied.
Options

How to send vanilla notifications via API?

I have a PHP Chat integrated very nicely, and I wondering how to tap into the Vanilla's notification system.

I am working on some code that will sniff @mentions in the chat, but I can't find any docs on how to finalize it so it can send the notification.

I have spend time digging into the core and other plugins.

Thanks in advance

Comments

  • Options
    charrondevcharrondev Developer Lead (PHP, JS) Montreal Vanilla Staff
    edited February 2019

    About Notifications & ActivityModel

    Our notification system is due for a revamp relatively soon, but in the meantime our mention system is relatively unchanged and undocumented. Notifications currently work through the ActivityModel (see the related tables in the DB). 2.8 adds endpoints for getting notifications:

    but we haven't built out the ones for sending them yet. This will likely happen in a near future release.

    How to do it right now

    You can find an example in the discussions model (comment model as well).

    And a code snippet:

    $user = $userModel->getByUsername($username);
    if (!$user) {
    continue;
    }
    // Check user can still see the discussion.
    if (!$this->canView($fields, $user->UserID)) {
        continue;
    }
    $activity['HeadlineFormat'] = t('HeadlineFormat.Mention', '{ActivityUserID,user} mentioned you in <a href="{Url,html}">{Data.Name,text}</a>');
    $activity['NotifyUserID'] = val('UserID', $user);
    $activityModel->queue($activity, 'Mention');
    
Sign In or Register to comment.