Help Center संदेश स्थिति जांचें

संदेश स्थिति जांचें

Track delivery status of your messages using the status check endpoint.

पोलिंग के बजाय स्थितियों को स्वचालित रूप से प्राप्त करने के लिए, देखें Delivery callbacks.

एन्डपॉइंट

GET /bat/message/{messageId}

अनुरोध

URL पैरामीटर

पैरामीटरप्रकारआवश्यकविवरण
messageIdstringYesभेज प्रतिक्रिया से अद्वितीय संदेश पहचानकर्ता

प्रमाणीकरण

तीन प्रमाणीकरण विधियों में से कोई भी उपयोग करें:

curl -X GET https://restapi.smsbat.com/bat/message/abc123def456 \
  -H "X-Authorization-Key: your-api-key"

प्रतिक्रिया

बेसिक प्रतिक्रिया

{
  "messagelistId": 123456,
  "messageId": "abc123def456",
  "deliverystatus": "delivered",
  "partscount": 1,
  "cost": 0.05
}

प्रतिक्रिया फ़ील्ड्स

फ़ील्डप्रकारविवरण
messagelistIdintegerबैच पहचानकर्ता
messageIdstringअद्वितीय संदेश पहचानकर्ता
deliverystatusstringवर्तमान डिलीवरी स्थिति
partscountintegerसंदेश भागों की संख्या
costnumberसंदेश की लागत मुद्रा इकाइयों में

विस्तारित प्रतिक्रिया (फ़ॉलबैक के साथ)

जब फ़ॉलबैक कॉन्फ़िगर किया जाता है, प्रतिक्रिया में अतिरिक्त फ़ील्ड शामिल होते हैं:

{
  "messagelistId": 123456,
  "messageId": "abc123def456",
  "deliverystatus": "delivered",
  "partscount": 1,
  "cost": 0.05,
  "fallbacks": [
    {
      "type": "sms",
      "status": "not_used"
    }
  ],
  "extendedStatuses": {
    "viber": "delivered",
    "sms": "not_used"
  },
  "rate": 0.05,
  "rateAmount": 0.05,
  "rateCurrency": "USD",
  "billAmount": 0.05,
  "billCurrency": "USD"
}

डिलीवरी स्थिति मान

स्थितिविवरण
scheduledभेजने के लिए कतारबद्ध
processingवर्तमान में भेजा जा रहा है
deliveredसफलतापूर्वक वितरित
undeliverableडिलीवरी विफल, संदेश अस्वीकृत
permanenterrorलगातार त्रुटि के कारण कतार से हटाया गया

स्थिति जीवनचक्र

graph LR
    A[scheduled] --> B[processing]
    B --> C[delivered]
    B --> D[undeliverable]
    B --> E[permanenterror]

नियोजित

संदेश स्वीकार किया गया और डिलीवरी के लिए कतारबद्ध किया गया:

{
  "deliverystatus": "scheduled",
  "partscount": 1
}

प्रसंस्करण

संदेश वर्तमान में प्राप्तकर्ता को भेजा जा रहा है:

{
  "deliverystatus": "processing",
  "partscount": 1
}

वितरित

संदेश सफलतापूर्वक प्राप्तकर्ता को वितरित किया गया:

{
  "deliverystatus": "delivered",
  "partscount": 1,
  "cost": 0.05
}

अवितरित

संदेश डिलीवर नहीं हो सका (अमान्य नंबर, नेटवर्क त्रुटि):

{
  "deliverystatus": "undeliverable",
  "partscount": 1,
  "cost": 0.00
}

स्थायी त्रुटि

स्थायी डिलीवरी समस्याओं के कारण संदेश को कतार से हटा दिया गया:

{
  "deliverystatus": "permanenterror",
  "partscount": 1,
  "cost": 0.00
}

कई संदेशों की जाँच करें

अपने एप्लिकेशन में कई संदेशों की स्थिति जाँचें:

// JavaScript example
async function checkMessageStatuses(messageIds) {
  const statuses = await Promise.all(
    messageIds.map(async (messageId) => {
      const response = await fetch(
        `https://restapi.smsbat.com/bat/message/${messageId}`,
        {
          headers: {
            'X-Authorization-Key': 'your-api-key'
          }
        }
      );
      return response.json();
    })
  );

  return statuses;
}

// Usage
const messageIds = ['abc123', 'def456', 'ghi789'];
const statuses = await checkMessageStatuses(messageIds);

statuses.forEach(status => {
  console.log(`Message ${status.messageId}: ${status.deliverystatus}`);
});

स्थिति अपडेट के लिए पोलिंग

डिलीवरी ट्रैक करने के लिए स्थिति एन्डपॉइंट को पोल करें:

// Poll every 5 seconds until delivered
async function waitForDelivery(messageId, maxAttempts = 12) {
  for (let i = 0; i < maxAttempts; i++) {
    const response = await fetch(
      `https://restapi.smsbat.com/bat/message/${messageId}`,
      {
        headers: { 'X-Authorization-Key': 'your-api-key' }
      }
    );

    const status = await response.json();

    if (status.deliverystatus === 'delivered') {
      return { success: true, status };
    }

    if (status.deliverystatus === 'undeliverable' ||
        status.deliverystatus === 'permanenterror') {
      return { success: false, status };
    }

    // Wait 5 seconds before next check
    await new Promise(resolve => setTimeout(resolve, 5000));
  }

  // Timeout after 60 seconds
  return { success: false, timeout: true };
}

वेबहुक विकल्प

पोलिंग के बजाय, वास्तविक समय की स्थिति अपडेट के लिए वेबहुक का उपयोग करें:

POST https://your-server.com/webhook
{
  "messageId": "abc123def456",
  "deliverystatus": "delivered",
  "timestamp": "2025-01-23T10:30:00Z",
  "cost": 0.05
}

वेबहुक URL कॉन्फ़िगर करने के लिए अपने अकाउंट मैनेजर से संपर्क करें।

कार्यान्वयन उदाहरण

Python

import requests
import time

def check_status(message_id, api_key):
    url = f"https://restapi.smsbat.com/bat/message/{message_id}"
    headers = {"X-Authorization-Key": api_key}

    response = requests.get(url, headers=headers)
    return response.json()

def wait_for_delivery(message_id, api_key, timeout=60):
    """Poll until delivered or timeout"""
    start_time = time.time()

    while time.time() - start_time < timeout:
        status = check_status(message_id, api_key)

        if status['deliverystatus'] == 'delivered':
            return {'success': True, 'status': status}

        if status['deliverystatus'] in ['undeliverable', 'permanenterror']:
            return {'success': False, 'status': status}

        time.sleep(5)

    return {'success': False, 'timeout': True}

# Usage
message_id = "abc123def456"
result = wait_for_delivery(message_id, "your-api-key")

if result['success']:
    print(f"Message delivered! Cost: {result['status']['cost']}")
else:
    print("Message delivery failed or timeout")

PHP

<?php

function checkStatus($messageId, $apiKey) {
    $url = "https://restapi.smsbat.com/bat/message/" . $messageId;

    $ch = curl_init($url);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
    curl_setopt($ch, CURLOPT_HTTPHEADER, [
        "X-Authorization-Key: " . $apiKey
    ]);

    $response = curl_exec($ch);
    curl_close($ch);

    return json_decode($response, true);
}

function waitForDelivery($messageId, $apiKey, $timeout = 60) {
    $startTime = time();

    while (time() - $startTime < $timeout) {
        $status = checkStatus($messageId, $apiKey);

        if ($status['deliverystatus'] === 'delivered') {
            return ['success' => true, 'status' => $status];
        }

        if (in_array($status['deliverystatus'],
                    ['undeliverable', 'permanenterror'])) {
            return ['success' => false, 'status' => $status];
        }

        sleep(5);
    }

    return ['success' => false, 'timeout' => true];
}

// Usage
$messageId = "abc123def456";
$result = waitForDelivery($messageId, "your-api-key");

if ($result['success']) {
    echo "Message delivered! Cost: " . $result['status']['cost'];
} else {
    echo "Message delivery failed or timeout";
}

Node.js

const axios = require('axios');

async function checkStatus(messageId, apiKey) {
  const response = await axios.get(
    `https://restapi.smsbat.com/bat/message/${messageId}`,
    {
      headers: { 'X-Authorization-Key': apiKey }
    }
  );

  return response.data;
}

async function waitForDelivery(messageId, apiKey, timeout = 60000) {
  const startTime = Date.now();

  while (Date.now() - startTime < timeout) {
    const status = await checkStatus(messageId, apiKey);

    if (status.deliverystatus === 'delivered') {
      return { success: true, status };
    }

    if (['undeliverable', 'permanenterror'].includes(
      status.deliverystatus
    )) {
      return { success: false, status };
    }

    // Wait 5 seconds
    await new Promise(resolve => setTimeout(resolve, 5000));
  }

  return { success: false, timeout: true };
}

// Usage
const messageId = 'abc123def456';
const result = await waitForDelivery(messageId, 'your-api-key');

if (result.success) {
  console.log(`Message delivered! Cost: ${result.status.cost}`);
} else {
  console.log('Message delivery failed or timeout');
}

सर्वोत्तम प्रथाएँ

पोलिंग आवृत्ति

  • ✅ हर 5-10 सेकंड में पोल करें
  • ✅ एक्सपोनेंशियल बैकऑफ़ लागू करें
  • ✅ उचित टाइमआउट सेट करें (60-120 सेकंड)
  • ❌ एक सेकंड में एक बार से अधिक पोल न करें
  • ❌ अनिश्चितकाल तक पोल न करें

त्रुटि प्रबंधन

async function checkStatusWithRetry(messageId, apiKey, retries = 3) {
  for (let i = 0; i < retries; i++) {
    try {
      const response = await fetch(
        `https://restapi.smsbat.com/bat/message/${messageId}`,
        {
          headers: { 'X-Authorization-Key': apiKey }
        }
      );

      if (!response.ok) {
        throw new Error(`HTTP ${response.status}`);
      }

      return await response.json();
    } catch (error) {
      if (i === retries - 1) throw error;

      // Wait before retry (exponential backoff)
      await new Promise(resolve =>
        setTimeout(resolve, Math.pow(2, i) * 1000)
      );
    }
  }
}

कैशिंग

API कॉल्स कम करने के लिए स्थिति परिणामों को कैश करें:

const statusCache = new Map();

async function getCachedStatus(messageId, apiKey, cacheTTL = 30000) {
  const cached = statusCache.get(messageId);

  if (cached && Date.now() - cached.timestamp < cacheTTL) {
    return cached.status;
  }

  const status = await checkStatus(messageId, apiKey);

  statusCache.set(messageId, {
    status,
    timestamp: Date.now()
  });

  return status;
}

बैच प्रोसेसिंग

कई संदेशों की जाँच करते समय, बैच अनुरोध करें:

async function checkBatchStatus(messageIds, apiKey, batchSize = 10) {
  const results = [];

  for (let i = 0; i < messageIds.length; i += batchSize) {
    const batch = messageIds.slice(i, i + batchSize);
    const batchResults = await Promise.all(
      batch.map(id => checkStatus(id, apiKey))
    );
    results.push(...batchResults);

    // Rate limiting
    if (i + batchSize < messageIds.length) {
      await new Promise(resolve => setTimeout(resolve, 1000));
    }
  }

  return results;
}

उपयोग के मामले

ऑर्डर पुष्टि

ऑर्डर पुष्टि संदेशों की डिलीवरी ट्रैक करें:

const orderMessage = await sendMessage({
  to: customer.phone,
  text: `Order #${orderId} confirmed`
});

// Wait for delivery
const result = await waitForDelivery(orderMessage.messageId, apiKey);

if (result.success) {
  await updateOrder(orderId, { notificationSent: true });
} else {
  await scheduleRetry(orderId);
}

दो-कारक प्रमाणीकरण

समय समाप्ति से पहले OTP डिलीवरी सत्यापित करें:

const otpMessage = await sendOTP(userPhone, otpCode);

// Poll for delivery
const delivered = await waitForDelivery(
  otpMessage.messageId,
  apiKey,
  30 // 30 second timeout
);

if (!delivered.success) {
  // Send via alternative channel
  await sendEmailOTP(userEmail, otpCode);
}

मार्केटिंग अभियान

अभियान संदेश डिलीवरी दरों को ट्रैक करें:

const messageIds = await sendCampaign(recipientList);

// Check all statuses after 5 minutes
setTimeout(async () => {
  const statuses = await checkBatchStatus(messageIds, apiKey);

  const delivered = statuses.filter(s =>
    s.deliverystatus === 'delivered'
  ).length;

  console.log(`Delivery rate: ${delivered / statuses.length * 100}%`);
}, 5 * 60 * 1000);

अगले कदम

  • Send Message - संदेश भेजने के तरीके जानें
  • Delivery Status Guide - डिलीवरी स्थितियों को समझें
  • Fallback Strategies - फॉलबैक कॉन्फ़िगर करें