Substitute org name and balance tokens in outbound SMS so templates no longer leave {از طرف} literal.
EOF Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
@@ -56,7 +56,8 @@ import { GamificationService } from '../gamification/gamification.service';
|
||||
import { parseBirthDate } from '../common/excel';
|
||||
import { SmsGatewayService } from '../sms-billing/sms-gateway.service';
|
||||
import { selectMonthBirthdays } from './birthday-month';
|
||||
import { renderSmsText } from '../common/sms-text';
|
||||
import { renderSmsText, smsBalanceTexts } from '../common/sms-text';
|
||||
import { extractMandehRaw } from '../integrations/tahesab/tahesab-methods';
|
||||
import { normalizeTags } from '../common/tags';
|
||||
import { buildSearchWhere, ci, splitCsv } from '../common/search';
|
||||
import {
|
||||
@@ -763,6 +764,7 @@ export class PeopleService implements OnModuleInit {
|
||||
lastName: true,
|
||||
mobile: true,
|
||||
phone: true,
|
||||
position: true,
|
||||
ownerId: true,
|
||||
birthDate: true,
|
||||
company: { select: { name: true } },
|
||||
@@ -836,12 +838,15 @@ export class PeopleService implements OnModuleInit {
|
||||
);
|
||||
}
|
||||
}
|
||||
const message = renderSmsText(body, {
|
||||
name: fullName,
|
||||
phone: mobile,
|
||||
title: fullName,
|
||||
company: person.company?.name ?? '',
|
||||
});
|
||||
const message = renderSmsText(
|
||||
body,
|
||||
await this.personSmsVars(actor.organizationId, person.id, {
|
||||
name: fullName,
|
||||
phone: mobile,
|
||||
title: person.position?.trim() || '',
|
||||
company: person.company?.name ?? '',
|
||||
}),
|
||||
);
|
||||
if (!message) throw new BadRequestException('متن پیامک خالی است.');
|
||||
const result = await this.sms.send({
|
||||
organizationId: actor.organizationId,
|
||||
@@ -902,12 +907,15 @@ export class PeopleService implements OnModuleInit {
|
||||
const person = await this.get(actor, personId);
|
||||
const mobile = person.mobile || person.phone;
|
||||
if (!mobile) throw new BadRequestException('برای این مشتری شماره موبایل ثبت نشده است.');
|
||||
const message = renderSmsText(body, {
|
||||
name: person.fullName,
|
||||
phone: mobile,
|
||||
title: person.fullName,
|
||||
company: person.company?.name ?? '',
|
||||
});
|
||||
const message = renderSmsText(
|
||||
body,
|
||||
await this.personSmsVars(actor.organizationId, person.id, {
|
||||
name: person.fullName,
|
||||
phone: mobile,
|
||||
title: person.position?.trim() || '',
|
||||
company: person.company?.name ?? '',
|
||||
}),
|
||||
);
|
||||
if (!message) throw new BadRequestException('متن پیامک خالی است.');
|
||||
const result = await this.sms.send({
|
||||
organizationId: actor.organizationId,
|
||||
@@ -937,6 +945,52 @@ export class PeopleService implements OnModuleInit {
|
||||
return { ok: true };
|
||||
}
|
||||
|
||||
/** نام سازمان + ماندههای کششدهٔ تهحساب برای توکنهای پیامک */
|
||||
private async personSmsVars(
|
||||
organizationId: string,
|
||||
personId: string,
|
||||
base: {
|
||||
name: string;
|
||||
phone: string;
|
||||
title: string;
|
||||
company: string;
|
||||
},
|
||||
) {
|
||||
const [org, link] = await Promise.all([
|
||||
this.prisma.organization.findUnique({
|
||||
where: { id: organizationId },
|
||||
select: { name: true },
|
||||
}),
|
||||
this.prisma.personAccountingLink.findFirst({
|
||||
where: { personId, connection: { organizationId } },
|
||||
orderBy: [
|
||||
{ connection: { isDefault: 'desc' } },
|
||||
{ linkedAt: 'desc' },
|
||||
],
|
||||
include: { balanceCache: true },
|
||||
}),
|
||||
]);
|
||||
let rialBalance = '';
|
||||
let metalBalance = '';
|
||||
const cache = link?.balanceCache;
|
||||
if (cache) {
|
||||
const rawView = extractMandehRaw(cache.rawResponse);
|
||||
const bal = smsBalanceTexts({
|
||||
mandehFields: rawView.fields,
|
||||
rialBalance: cache.rialBalance,
|
||||
goldBalance: cache.goldBalance,
|
||||
});
|
||||
rialBalance = bal.rialBalance;
|
||||
metalBalance = bal.metalBalance;
|
||||
}
|
||||
return {
|
||||
...base,
|
||||
from: org?.name?.trim() || '',
|
||||
rialBalance,
|
||||
metalBalance,
|
||||
};
|
||||
}
|
||||
|
||||
listSmsHistory(actor: Actor, personId: string, limit?: number) {
|
||||
return this.get(actor, personId).then(() =>
|
||||
this.outboundSms.historyForPerson(actor.organizationId, personId, limit),
|
||||
|
||||
Reference in New Issue
Block a user