-
Notifications
You must be signed in to change notification settings - Fork 31
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #686 from chaynHQ/develop
Merge Develop onto Main
- Loading branch information
Showing
36 changed files
with
821 additions
and
336 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
import { Module } from '@nestjs/common'; | ||
import { TypeOrmModule } from '@nestjs/typeorm'; | ||
import { CrispService } from 'src/crisp/crisp.service'; | ||
import { EventLogEntity } from 'src/entities/event-log.entity'; | ||
import { UserEntity } from 'src/entities/user.entity'; | ||
import { EventLoggerService } from 'src/event-logger/event-logger.service'; | ||
import { CrispListenerService } from './crisp-listener.service'; | ||
|
||
@Module({ | ||
imports: [TypeOrmModule.forFeature([EventLogEntity, UserEntity])], | ||
providers: [CrispService, CrispListenerService, EventLoggerService], | ||
}) | ||
export class CrispListenerModule {} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
import { Injectable, Logger, OnModuleInit } from '@nestjs/common'; | ||
import Crisp from 'crisp-api'; | ||
import { EVENT_NAME } from 'src/crisp/crisp.interface'; | ||
import { CrispService } from 'src/crisp/crisp.service'; | ||
import { CrispEventDto } from 'src/crisp/dtos/crisp.dto'; | ||
import { crispPluginId, crispPluginKey } from 'src/utils/constants'; | ||
const CrispClient = new Crisp(); | ||
const logger = new Logger('CrispLogger'); | ||
|
||
// This service is split from CrispService due to CrispService being imported/initiated multiple times | ||
// To avoid creating duplicate listeners and events, this CrispListenerService was decoupled | ||
@Injectable() | ||
export class CrispListenerService implements OnModuleInit { | ||
constructor(private crispService: CrispService) { | ||
CrispClient.authenticateTier('plugin', crispPluginId, crispPluginKey); | ||
} | ||
|
||
onModuleInit() { | ||
logger.log(`Crisp service initiated`); | ||
|
||
try { | ||
const handleCrispEvent = async (message, eventName) => | ||
await this.crispService.handleCrispEvent(message, eventName); | ||
|
||
CrispClient.on('message:send', async function (message: CrispEventDto) { | ||
handleCrispEvent(message, EVENT_NAME.CHAT_MESSAGE_SENT); | ||
}) | ||
.then(function () { | ||
logger.log('Crisp service listening to sent messages'); | ||
}) | ||
.catch(function (error) { | ||
logger.error('Crisp service failed listening to sent messages:', error); | ||
}); | ||
|
||
CrispClient.on('message:received', function (message: CrispEventDto) { | ||
handleCrispEvent(message, EVENT_NAME.CHAT_MESSAGE_RECEIVED); | ||
}) | ||
.then(function () { | ||
logger.log('Crisp service listening to received messages'); | ||
}) | ||
.catch(function (error) { | ||
logger.error('Crisp service failed listening to sent messages:', error); | ||
}); | ||
} catch (error) { | ||
logger.error('Crisp service failed to initiate:', error); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
import { Module } from '@nestjs/common'; | ||
import { TypeOrmModule } from '@nestjs/typeorm'; | ||
import { EventLogEntity } from 'src/entities/event-log.entity'; | ||
import { UserEntity } from 'src/entities/user.entity'; | ||
import { EventLoggerService } from 'src/event-logger/event-logger.service'; | ||
import { CrispService } from './crisp.service'; | ||
|
||
@Module({ | ||
imports: [TypeOrmModule.forFeature([EventLogEntity, UserEntity])], | ||
providers: [CrispService, EventLoggerService], | ||
}) | ||
export class CrispModule {} |
Oops, something went wrong.