From 07c8cfb35ffa631f6ad353f57602d076f2a6594f Mon Sep 17 00:00:00 2001 From: Anna Hughes Date: Tue, 29 Oct 2024 10:45:05 +0000 Subject: [PATCH] fix: prevent crisp resolved events (#689) --- src/crisp/crisp.service.ts | 23 +++++++++++------------ 1 file changed, 11 insertions(+), 12 deletions(-) diff --git a/src/crisp/crisp.service.ts b/src/crisp/crisp.service.ts index 1a6c878a..57e47dfd 100644 --- a/src/crisp/crisp.service.ts +++ b/src/crisp/crisp.service.ts @@ -1,7 +1,5 @@ -import { Injectable, Logger } from '@nestjs/common'; +import { Injectable } from '@nestjs/common'; import Crisp from 'crisp-api'; -import { sendMailchimpUserEvent } from 'src/api/mailchimp/mailchimp-api'; -import { MAILCHIMP_CUSTOM_EVENTS } from 'src/api/mailchimp/mailchimp-api.interfaces'; import { EventLoggerService } from 'src/event-logger/event-logger.service'; import { crispPluginId, crispPluginKey, crispWebsiteId } from 'src/utils/constants'; import { @@ -15,7 +13,6 @@ import { import { CrispEventDto } from './dtos/crisp.dto'; const CrispClient = new Crisp(); -const logger = new Logger('CrispLogger'); @Injectable() export class CrispService { @@ -25,6 +22,16 @@ export class CrispService { async handleCrispEvent(message: CrispEventDto, eventName: EVENT_NAME) { try { + if ( + eventName === EVENT_NAME.CHAT_MESSAGE_RECEIVED && + typeof message.content !== 'string' && + 'namespace' in message.content + ) { + // When a conversation is resolved on crisp, the message:received event is fired with + // message.content.namespace = "state:resolved" + // Prevent our events being logged for conversation resolved events + return; + } const sessionMetaData = await CrispClient.website.getConversationMetas( message.website_id, message.session_id, @@ -34,14 +41,6 @@ export class CrispService { event: eventName, date: new Date(), }); - - if (eventName === EVENT_NAME.CHAT_MESSAGE_RECEIVED) { - sendMailchimpUserEvent( - sessionMetaData.email, - MAILCHIMP_CUSTOM_EVENTS.CRISP_MESSAGE_RECEIVED, - ); - logger.log('Crisp service: CRISP_MESSAGE_RECEIVED event sent to mailchimp'); - } } catch (error) { throw new Error(`Failed to handle crisp event for ${eventName}: ${error}`); }