1
- import { Injectable , Logger } from '@nestjs/common' ;
1
+ import { Injectable } from '@nestjs/common' ;
2
2
import Crisp from 'crisp-api' ;
3
- import { sendMailchimpUserEvent } from 'src/api/mailchimp/mailchimp-api' ;
4
- import { MAILCHIMP_CUSTOM_EVENTS } from 'src/api/mailchimp/mailchimp-api.interfaces' ;
5
3
import { EventLoggerService } from 'src/event-logger/event-logger.service' ;
6
4
import { crispPluginId , crispPluginKey , crispWebsiteId } from 'src/utils/constants' ;
7
5
import {
@@ -15,7 +13,6 @@ import {
15
13
import { CrispEventDto } from './dtos/crisp.dto' ;
16
14
17
15
const CrispClient = new Crisp ( ) ;
18
- const logger = new Logger ( 'CrispLogger' ) ;
19
16
20
17
@Injectable ( )
21
18
export class CrispService {
@@ -25,6 +22,16 @@ export class CrispService {
25
22
26
23
async handleCrispEvent ( message : CrispEventDto , eventName : EVENT_NAME ) {
27
24
try {
25
+ if (
26
+ eventName === EVENT_NAME . CHAT_MESSAGE_RECEIVED &&
27
+ typeof message . content !== 'string' &&
28
+ 'namespace' in message . content
29
+ ) {
30
+ // When a conversation is resolved on crisp, the message:received event is fired with
31
+ // message.content.namespace = "state:resolved"
32
+ // Prevent our events being logged for conversation resolved events
33
+ return ;
34
+ }
28
35
const sessionMetaData = await CrispClient . website . getConversationMetas (
29
36
message . website_id ,
30
37
message . session_id ,
@@ -34,14 +41,6 @@ export class CrispService {
34
41
event : eventName ,
35
42
date : new Date ( ) ,
36
43
} ) ;
37
-
38
- if ( eventName === EVENT_NAME . CHAT_MESSAGE_RECEIVED ) {
39
- sendMailchimpUserEvent (
40
- sessionMetaData . email ,
41
- MAILCHIMP_CUSTOM_EVENTS . CRISP_MESSAGE_RECEIVED ,
42
- ) ;
43
- logger . log ( 'Crisp service: CRISP_MESSAGE_RECEIVED event sent to mailchimp' ) ;
44
- }
45
44
} catch ( error ) {
46
45
throw new Error ( `Failed to handle crisp event for ${ eventName } : ${ error } ` ) ;
47
46
}
0 commit comments