Files
boursecu_user/src/utils/supportMessenger.ts
T

92 lines
2.6 KiB
TypeScript
Raw Normal View History

2026-06-06 17:28:48 +03:30
import { ref } from 'vue'
import { getSettings } from '@/api/configuration'
export type SupportMessengerType =
| 'bale'
| 'telegram'
| 'whatsapp'
| 'rubika'
| 'eitaa'
| 'soroush'
export interface SupportMessengerSettings {
messenger?: SupportMessengerType | string
messengerId?: string
messengerText?: string
2026-06-15 15:41:50 +03:30
depositSmsSupportNumber?: string
2026-06-06 17:28:48 +03:30
}
export const supportMessengerSettings = ref<SupportMessengerSettings>({})
export const DEFAULT_SUPPORT_MESSENGER_TEXT =
2026-06-16 19:47:28 +03:30
'جهت شارژ حساب کاربری خود، کلمه «شماره حساب» را برای پشتیبانی ارسال نمایید.'
2026-06-13 22:28:29 +03:30
function getSupportSettingValue(
settings: Array<{ key?: string; is_active?: boolean | number; value?: unknown }>,
key: string
) {
const setting = settings.find((item) => item?.key === key)
if (!setting) return ''
const value = setting.value
2026-06-06 17:28:48 +03:30
if (value === undefined || value === null) return ''
2026-06-13 22:28:29 +03:30
2026-06-06 17:28:48 +03:30
return String(value).trim()
}
export function buildSupportMessengerUrl(messenger?: string, messengerId?: string) {
const id = (messengerId ?? '').trim()
if (!id) return ''
if (/^https?:\/\//i.test(id)) return id
2026-06-14 19:11:37 +03:30
const type = (messenger ?? '').trim().toLowerCase()
2026-06-06 17:28:48 +03:30
const username = id.replace(/^@/, '')
2026-06-14 19:11:37 +03:30
if (!type) return ''
2026-06-06 17:28:48 +03:30
switch (type) {
case 'bale':
if (id.includes('ble.ir')) {
return id.startsWith('http') ? id : `https://${id.replace(/^\/\//, '')}`
}
return `https://ble.ir/${username}`
case 'telegram':
return `https://t.me/${username}`
case 'whatsapp':
return `https://wa.me/${username.replace(/\D/g, '')}`
case 'rubika':
return `https://rubika.ir/${username}`
case 'eitaa':
return `https://eitaa.com/${username}`
case 'soroush':
return `https://splus.ir/splus/${username}`
default:
2026-06-14 19:11:37 +03:30
return ''
2026-06-06 17:28:48 +03:30
}
}
2026-06-15 15:41:50 +03:30
export function buildDepositSmsUrl(phoneNumber?: string) {
const digits = (phoneNumber ?? '').replace(/\D/g, '')
if (!digits) return ''
const body = encodeURIComponent('شماره حساب')
return `sms:${digits}?body=${body}`
}
2026-06-06 17:28:48 +03:30
export async function loadSupportMessengerFromSettings() {
try {
const settings = await getSettings()
if (!settings || !Array.isArray(settings)) return
supportMessengerSettings.value = {
2026-06-14 19:11:37 +03:30
messenger: getSupportSettingValue(settings, 'support_messenger'),
2026-06-13 22:28:29 +03:30
messengerId: getSupportSettingValue(settings, 'support_messenger_id'),
messengerText: getSupportSettingValue(settings, 'support_messenger_text'),
2026-06-15 15:41:50 +03:30
depositSmsSupportNumber: getSupportSettingValue(settings, 'deposit_sms_support_number'),
2026-06-06 17:28:48 +03:30
}
} catch (e) {
console.log(e)
}
}