mirror of
https://github.com/Tria-plc/edr-platform.git
synced 2026-08-28 07:51:02 +00:00
37 lines
986 B
TypeScript
37 lines
986 B
TypeScript
import { Inject, Injectable, Logger, OnApplicationBootstrap } from '@nestjs/common';
|
|
import { ClientProxy } from '@nestjs/microservices';
|
|
import { BulkMessagesDto, SendMessage } from './dtos/sms.dto';
|
|
|
|
@Injectable()
|
|
export class SmsClientService implements OnApplicationBootstrap {
|
|
private readonly logger = new Logger(SmsClientService.name);
|
|
|
|
constructor(
|
|
@Inject('SMS_SERVICE')
|
|
private readonly smsClient: ClientProxy,
|
|
) {}
|
|
|
|
async onApplicationBootstrap() {
|
|
this.smsClient
|
|
.connect()
|
|
.then(() => this.logger.log('Connected to SMS service'))
|
|
.catch((err) => this.logger.error('Error connecting to SMS service', err));
|
|
}
|
|
|
|
async sendSms(dto: SendMessage) {
|
|
this.smsClient.emit('send-sms', {
|
|
...dto,
|
|
appKey: 'EDR-PASSENGER-API',
|
|
});
|
|
return {};
|
|
}
|
|
|
|
async sendBulkMessages(dto: BulkMessagesDto) {
|
|
this.smsClient.emit('ozeking-bulk-sms', {
|
|
...dto,
|
|
appKey: 'EDR-PASSENGER-API',
|
|
});
|
|
return {};
|
|
}
|
|
}
|