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 {}; } }