feat: log outbound SMS and show history in compose modal
Persist manual, campaign, and automation SMS; expose history APIs for people and leads. Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
@@ -379,6 +379,15 @@ export class LeadsController {
|
||||
return this.leads.move(user, id, dto.stageId, dto.position);
|
||||
}
|
||||
|
||||
@Get(':id/sms-history')
|
||||
smsHistory(
|
||||
@CurrentUser() user: Actor,
|
||||
@Param('id') id: string,
|
||||
@Query('limit') limit?: string,
|
||||
) {
|
||||
return this.leads.listSmsHistory(user, id, limit ? Number(limit) : 50);
|
||||
}
|
||||
|
||||
@Post(':id/sms')
|
||||
sms(
|
||||
@CurrentUser() user: Actor,
|
||||
|
||||
@@ -23,6 +23,7 @@ import { FILTERED_IDS_MAX } from '@mento/shared';
|
||||
import { PrismaService } from '../prisma/prisma.service';
|
||||
import { SmsService } from '../common/sms.service';
|
||||
import { renderSmsText } from '../common/sms-text';
|
||||
import { OutboundSmsLogService } from '../outbound-sms/outbound-sms-log.service';
|
||||
import {
|
||||
type Actor,
|
||||
elevated,
|
||||
@@ -87,6 +88,7 @@ export class LeadsService {
|
||||
private readonly files: LocalFileStorage,
|
||||
private readonly game: GamificationService,
|
||||
private readonly sms: SmsService,
|
||||
private readonly outboundSms: OutboundSmsLogService,
|
||||
) {}
|
||||
|
||||
private gameEvent(
|
||||
@@ -1290,6 +1292,16 @@ export class LeadsService {
|
||||
});
|
||||
if (!message) throw new BadRequestException('متن پیامک خالی است.');
|
||||
const result = await this.sms.sendSmsDetailed(mobile, message);
|
||||
await this.outboundSms.record({
|
||||
organizationId: actor.organizationId,
|
||||
leadId: id,
|
||||
mobile,
|
||||
body: message,
|
||||
source: 'manual',
|
||||
status: result.ok ? 'sent' : 'failed',
|
||||
error: result.ok ? null : result.reason,
|
||||
actorUserId: actor.userId,
|
||||
});
|
||||
if (!result.ok) {
|
||||
throw new ServiceUnavailableException(
|
||||
result.reason === 'SMS not configured'
|
||||
@@ -1301,6 +1313,11 @@ export class LeadsService {
|
||||
return { ok: true };
|
||||
}
|
||||
|
||||
async listSmsHistory(actor: Actor, id: string, limit?: number) {
|
||||
await this.findAccessible(actor, id);
|
||||
return this.outboundSms.historyForLead(actor.organizationId, id, limit);
|
||||
}
|
||||
|
||||
async openLogo(actor: Actor, id: string) {
|
||||
const existing = await this.findAccessible(actor, id);
|
||||
if (!existing.logoStorageKey) {
|
||||
|
||||
Reference in New Issue
Block a user