Wix Comments events are fired in your site's backend when certain events occur with plans. You can write event handlers that react to these events. Event handler functions receive data that corresponds to the event that has occurred. Use event handlers to create custom responses to pricing plan events.
Note: Backend events don't work when previewing your site.
To add a comments event handler, add an events.js file to the Backend section of your site if one does not already exist. All event handler functions for your site are defined in this file.
Event handler functions are defined using the following pattern:
export function <wixAppName>_<eventName>(event) { }
For example, an event handler that handles comment updates looks like this:
export function wixComments_onCommentUpdated(event) {}
This API is subject to change. Bug fixes and new features will be released based on developer feedback throughout the preview period.
function wixCommentsV2_onCommentDeleted(event: CommentDeleted): void;
export function wixCommentsV2_onCommentDeleted(event) {
const eventId = event.metadata.id;
const entityId = event.entity._id;
}
This method doesn’t return any custom errors, but may return standard errors. Learn more about standard Wix errors.
Triggered when a comment is created.
function wixComments_onCommentCreated(event: CommentCreated): void;
export function wixComments_onCommentCreated(event) {
const eventId = event.metadata.id;
const entityId = event.entity._id;
}
This method doesn’t return any custom errors, but may return standard errors. Learn more about standard Wix errors.
Triggered when a comment is deleted.
function wixComments_onCommentDeleted(event: CommentDeletedEvent): void;
export function wixCommentsV2_onCommentDeleted(event) {
const eventId = event.metadata.id;
const entityId = event.entity._id;
}
This method doesn’t return any custom errors, but may return standard errors. Learn more about standard Wix errors.
Triggered when a comment is marked.
function wixComments_onCommentMarked(event: CommentMarkedEvent): void;
export function wixComments_onCommentMarked(event) {
const eventId = event.metadata.id;
const entityId = event.data.comment._id;
}
This method doesn’t return any custom errors, but may return standard errors. Learn more about standard Wix errors.
Triggered when a comment is unmarked.
function wixComments_onCommentUnmarked(event: CommentUnmarkedEvent): void;
export function wixComments_onCommentUnmarked(event) {
const eventId = event.metadata.id;
const entityId = event.data.comment._id;
}
This method doesn’t return any custom errors, but may return standard errors. Learn more about standard Wix errors.