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:
2026-10-17 21:23:07 +03:30
co-authored by Cursor
parent 9325d879a5
commit 23f8da2c65
16 changed files with 457 additions and 3 deletions
+9
View File
@@ -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,
+17
View File
@@ -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) {