From b446c21afc2cb0fdb02926785b50aced337f036d Mon Sep 17 00:00:00 2001 From: mohammad sedighi Date: Sun, 19 Jul 2026 01:11:37 +0330 Subject: [PATCH] change sms option --- src/api/customerDirectSms.ts | 90 ++++++-- .../components/CustomerDirectSmsModal.vue | 202 ++++++++++++++---- 2 files changed, 238 insertions(+), 54 deletions(-) diff --git a/src/api/customerDirectSms.ts b/src/api/customerDirectSms.ts index 62c7445..0a77741 100644 --- a/src/api/customerDirectSms.ts +++ b/src/api/customerDirectSms.ts @@ -1,4 +1,3 @@ -import type { Customer } from '@/model/customer' import useAxios from '@core/utils/useAxios' export const sendCustomerDirectSms = async (payload: { @@ -6,23 +5,82 @@ export const sendCustomerDirectSms = async (payload: { message: string }) => useAxios.post<{ ok: boolean }>('/admin/messages/send_customer', payload) -export type DirectSmsSnippet = { - key: string - label: string - insert: string +export const DIRECT_SMS_MAX_LENGTH = 700 + +export type DirectSmsTemplateContext = { + appUrl: string + appName: string } -/** دکمه‌های آماده برای درج در متن پیامک */ -export function buildDirectSmsSnippets(customer?: Customer | null, appName = '', appUrl = ''): DirectSmsSnippet[] { - const name = (customer?.name ?? '').trim() || 'مشتری' - return [ - { key: 'name', label: 'نام مشتری', insert: name }, - { key: 'app_name', label: 'نام اپ', insert: appName || 'اپ' }, - { key: 'app_url', label: 'لینک اپ', insert: appUrl || '' }, - { key: 'name_ph', label: '%نام%', insert: '%نام%' }, - { key: 'app_name_ph', label: '%نام_اپ%', insert: '%نام_اپ%' }, - { key: 'app_url_ph', label: '%لینک_اپ%', insert: '%لینک_اپ%' } - ].filter((s) => s.insert !== '') +export type DirectSmsTemplate = { + key: string + label: string + /** بدنهٔ پیام (بدون نام و نام اپ — آن‌ها خودکار اضافه می‌شوند) */ + body: (ctx: DirectSmsTemplateContext) => string + /** اگر true باشد و لینک اپ خالی باشد، قالب غیرفعال است */ + requiresAppUrl?: boolean +} + +/** قالب‌های آماده — همیشه با «نام عزیز» شروع و با «نام اپ» تمام می‌شوند */ +export const DIRECT_SMS_TEMPLATES: DirectSmsTemplate[] = [ + { + key: 'app_login_link', + label: 'لینک ورود به اپ', + requiresAppUrl: true, + body: ({ appUrl }) => + ['برای ورود به اپلیکیشن از لینک زیر استفاده کنید:', appUrl].join('\n') + }, + { + key: 'invite_app', + label: 'دعوت به استفاده از اپ', + requiresAppUrl: true, + body: ({ appUrl }) => + [ + 'از شما دعوت می‌کنیم وارد اپلیکیشن شوید و از خدمات خرید و فروش طلا بهره‌مند شوید.', + 'لینک ورود:', + appUrl + ].join('\n') + }, + { + key: 'complete_kyc', + label: 'تکمیل احراز هویت', + body: () => 'لطفاً برای ادامه فعالیت، احراز هویت خود را در اپلیکیشن تکمیل کنید.' + }, + { + key: 'charge_wallet', + label: 'یادآوری شارژ حساب', + body: () => 'برای شارژ حساب و ادامه معاملات، از بخش کیف پول در اپلیکیشن اقدام کنید.' + }, + { + key: 'welcome', + label: 'خوش‌آمدگویی', + body: () => 'به جمع کاربران ما خوش آمدید. امیدواریم تجربهٔ خوبی از خدمات ما داشته باشید.' + } +] + +/** + * فرمت اجباری همهٔ پیامک‌ها: + * خط ۱: «نام عزیز» + * خط‌های میانی: متن + * خط آخر: نام اپ + */ +export function formatDirectSms(params: { + customerName: string + body: string + appName: string +}): string { + const name = (params.customerName ?? '').trim() || 'مشتری' + const app = (params.appName ?? '').trim() || 'اپ' + const body = (params.body ?? '').trim() + if (!body) return `${name} عزیز\n${app}` + return `${name} عزیز\n${body}\n${app}` +} + +export function resolveTemplateBody( + template: DirectSmsTemplate, + ctx: DirectSmsTemplateContext +): string { + return template.body(ctx).trim() } const BLOCKED = [ diff --git a/src/pages/menuPages/customers/base/components/CustomerDirectSmsModal.vue b/src/pages/menuPages/customers/base/components/CustomerDirectSmsModal.vue index f4250d7..ac10370 100644 --- a/src/pages/menuPages/customers/base/components/CustomerDirectSmsModal.vue +++ b/src/pages/menuPages/customers/base/components/CustomerDirectSmsModal.vue @@ -1,7 +1,7 @@