نمونه کد Node.js
برای محیط Node.js، استفاده از کتابخانه axios به دلیل مدیریت بهتر Promiseها پیشنهاد میشود.
پیشنیازها
npm install axios
اسکریپت ارسال
send.js
const axios = require('axios');
const API_URL = '[https://gateway.ferzz.ir/send](https://gateway.ferzz.ir/send)';
const TOKEN = 'YOUR_ACCESS_TOKEN'; // توکن خود را وارد کنید
async function sendRequest(destination, action, payload) {
try {
const response = await axios.post(API_URL, {
token: TOKEN,
destination: destination,
action: action,
payload: payload
});
console.log('✅ درخواست موفق:', response.data);
} catch (error) {
if (error.response) {
// سرور پاسخ داده اما با کد خطا (4xx, 5xx)
console.error(`❌ خطا (${error.response.status}):`, error.response.data);
} else {
// خطای شبکه یا عدم دسترسی
console.error('❌ خطای شبکه:', error.message);
}
}
}
// --- اجرای تست ---
// ارسال به تلگرام (SAM)
sendRequest(
'989123456789',
'flashcall',
{
code: '25050',
}
);