UNPKG

bottender-facebook

Version:

Facebook connector for Bottender.

167 lines (125 loc) 3.33 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.default = void 0; var _bottender = require("bottender"); class FacebookEvent extends _bottender.MessengerEvent { constructor(rawEvent, options = {}) { super(rawEvent, options); this._pageId = options.pageId; } get isConversation() { return this.rawEvent.field === 'conversation'; } get isFeed() { return this.rawEvent.field === 'feed'; } get isStatus() { return this.isFeed && this.rawEvent.value.item === 'status'; } get isStatusAdd() { return this.isStatus && this.rawEvent.value.verb === 'add'; } get isStatusEdited() { return this.isStatus && this.rawEvent.value.verb === 'edited'; } get status() { if (this.isStatus) { return this.rawEvent.value; } return null; } get isPost() { return this.isFeed && this.rawEvent.value.item === 'post'; } get isPostRemove() { return this.isPost && this.rawEvent.value.verb === 'remove'; } get post() { if (this.isPost) { return this.rawEvent.value; } return null; } get isComment() { return this.isFeed && this.rawEvent.value.item === 'comment'; } get isCommentAdd() { return this.isComment && this.rawEvent.value.verb === 'add'; } get isCommentEdited() { return this.isComment && this.rawEvent.value.verb === 'edited'; } get isCommentRemove() { return this.isComment && this.rawEvent.value.verb === 'remove'; } get isFirstLayerComment() { if (!this.isComment) return false; const comment = this.comment; return comment.parent_id === comment.post_id; } get comment() { if (this.isComment) { return this.rawEvent.value; } return null; } get isLike() { return this.isFeed && this.rawEvent.value.item === 'like'; } get isLikeAdd() { return this.isLike && this.rawEvent.value.verb === 'add'; } get isLikeRemove() { return this.isLike && this.rawEvent.value.verb === 'remove'; } get like() { if (this.isLike) { return this.rawEvent.value; } return null; } get isReaction() { return this.isFeed && this.rawEvent.value.item === 'reaction'; } get isReactionAdd() { return this.isReaction && this.rawEvent.value.verb === 'add'; } get isReactionEdit() { return this.isReaction && this.rawEvent.value.verb === 'edit'; } get isReactionRemove() { return this.isReaction && this.rawEvent.value.verb === 'remove'; } get reaction() { if (this.isReaction) { return this.rawEvent.value; } return null; } get pageId() { return this._pageId || null; } get isSentByPage() { // TODO: should we treat Messenger echo events as `isSentByPage`? if (!this.isFeed) { return false; } if (this.rawEvent.value.from && this.rawEvent.value.from.id === this.pageId) { return true; } return false; } // Notifications for Page likes will only be sent for Pages that have fewer than 10K likes. // ref: https://developers.facebook.com/docs/graph-api/webhooks/reference/page/#feed get isPageLike() { if (!this.isFeed) { return false; } if (!this.rawEvent.value.from) { return true; } return false; } } exports.default = FacebookEvent;