Merge branch 'fix/mizbansms-array-response'

This commit is contained in:
keyhan
2026-06-17 21:05:51 +03:30
+14 -2
View File
@@ -138,13 +138,15 @@ export class SmsService {
const message = this.mizbanMessage(kind, code);
const to = toLocalMobile(phoneE164); // 09XXXXXXXXX
// Field shapes per the API's validation: To is a string[] (many recipients)
// while Message is a single string shared by all of them.
const payload = {
Usertype: this.config.get<number>('sms.mizban.userType') ?? 2,
Username: this.config.get<string>('sms.mizban.username'),
Password: this.config.get<string>('sms.mizban.password'),
From: this.config.get<string>('sms.mizban.from'),
To: [to],
Message: [message],
Message: message,
Api: this.config.get<number>('sms.mizban.api'),
};
@@ -156,8 +158,18 @@ export class SmsService {
});
const raw = (await res.text()).trim();
// The API wraps its result in a JSON array, e.g. "[1008]" for an error or
// "[100002656565]" for a delivered message id. Unwrap to the bare code.
let codeStr = raw;
try {
const parsed = JSON.parse(raw);
codeStr = String(Array.isArray(parsed) ? parsed[0] : parsed);
} catch {
codeStr = raw.replace(/[[\]"\s]/g, '');
}
// Success returns a long numeric message id; failures are codes 10011011.
const reason = SmsService.MIZBAN_ERRORS[raw.replace(/^"|"$/g, '')];
const reason = SmsService.MIZBAN_ERRORS[codeStr];
if (!res.ok || reason) {
this.logger.error(
`MizbanSMS OTP send failed (${res.status}): ${reason ?? raw}`,