@@ -54,6 +54,13 @@ interface IReactionParams {
5454 from : IFbUser ;
5555}
5656
57+ interface IFacebookMessageSelector {
58+ facebookData : {
59+ postId ?: string ;
60+ commentId ?: string ;
61+ } ;
62+ }
63+
5764export interface IFacebookReply {
5865 text ?: string ;
5966 attachment ?: any ;
@@ -379,7 +386,7 @@ export class SaveWebhookResponse {
379386 /**
380387 * Increase or decrease like count
381388 */
382- public async updateLikeCount ( type : string , selector : any ) {
389+ public async updateLikeCount ( type : string , selector : IFacebookMessageSelector ) {
383390 let count = - 1 ;
384391
385392 if ( type === 'add' ) {
@@ -394,7 +401,7 @@ export class SaveWebhookResponse {
394401 /**
395402 * Updates reaction
396403 */
397- public async updateReactions ( type : string , selector : any , reactionType : string , from : IFbUser ) {
404+ public async updateReactions ( type : string , selector : IFacebookMessageSelector , reactionType : string , from : IFbUser ) {
398405 const reactionField = `facebookData.reactions.${ reactionType } ` ;
399406
400407 if ( type === 'add' ) {
@@ -413,14 +420,14 @@ export class SaveWebhookResponse {
413420 */
414421 public async handleReactions ( reactionParams : IReactionParams ) {
415422 const { verb, post_id, comment_id, reaction_type, item, from } = reactionParams ;
416- let selector = { } ;
423+ let selector : IFacebookMessageSelector = { facebookData : { } } ;
417424
418425 if ( post_id ) {
419- selector = { ' facebookData. postId' : post_id } ;
426+ selector = { facebookData : { postId : post_id } } ;
420427 }
421428
422429 if ( comment_id ) {
423- selector = { ' facebookData. commentId' : comment_id } ;
430+ selector = { facebookData : { commentId : comment_id } } ;
424431 }
425432
426433 // Receiving like
@@ -526,6 +533,7 @@ export class SaveWebhookResponse {
526533 let msgFacebookData = { } ;
527534
528535 // sending to comment handler if comment
536+ // TODO: prechecking is too costly.
529537 if ( item === 'comment' && comment_id ) {
530538 // if already saved then ignore it
531539 const conversationMessage = await ConversationMessages . findOne ( {
@@ -788,7 +796,6 @@ export const receiveWebhookResponse = async data => {
788796
789797 for ( const integration of integrations ) {
790798 const { facebookData } = integration ;
791-
792799 if ( ! facebookData ) {
793800 throw new Error ( 'Could not find integrations facebookData' ) ;
794801 }
0 commit comments