শুরু করুন

SMS API কোড স্যাম্পল: curl, Node.js, Python, PHP, Go

প্রতিটি স্যাম্পল একটি সম্পূর্ণ প্রোগ্রাম যা শুধু তার ভাষার স্ট্যান্ডার্ড লাইব্রেরি ব্যবহার করে (Node.js 18+ fetch-এর জন্য, Python 3, curl এক্সটেনশনসহ PHP, Go 1.20+)। প্রথমে এনভায়রনমেন্টে BULKSMSAPI_KEY সেট করুন।

একটি মেসেজ পাঠান

curl https://bulksmsapi.cc/v1/messages \
  -H "Authorization: Bearer $BULKSMSAPI_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "to": "+14155550123",
    "text": "Your Northwind code is 482913. It expires in 10 minutes.",
    "reference": "login-7781"
  }'

ব্যাচ পাঠান

curl https://bulksmsapi.cc/v1/batches \
  -H "Authorization: Bearer $BULKSMSAPI_KEY" \
  -H "Content-Type: application/json" \
  -H "Idempotency-Key: spring-sale-0412" \
  -d '{
    "name": "Spring sale",
    "text": "Spring sale at Northwind: 20% off until Sunday. Opt out: northwind.example/sms",
    "to": [
      "+14155550123",
      "+447400123456",
      "+4915123456789"
    ]
  }'

একটি মেসেজ স্ট্যাটাস পড়ুন

curl https://bulksmsapi.cc/v1/messages/msg_8F3K2Q9TZ1MX \
  -H "Authorization: Bearer $BULKSMSAPI_KEY"

ব্যালেন্স চেক করুন

curl https://bulksmsapi.cc/v1/balance \
  -H "Authorization: Bearer $BULKSMSAPI_KEY"

দাম পড়ুন

# Public: no key needed
curl https://bulksmsapi.cc/v1/pricing/DE

একটি ওয়েবহুক যাচাই করুন

Node.js স্যাম্পল Express এবং Python স্যাম্পল Flask ব্যবহার করে, HTTP এন্ডপয়েন্টের সাধারণ ছোট ফ্রেমওয়ার্ক; সিগনেচার চেক নিজেই শুধু স্ট্যান্ডার্ড লাইব্রেরি।

// Express: keep the raw body, check the signature, then answer 2xx quickly
import crypto from "node:crypto";
import express from "express";

const app = express();
const secret = process.env.BULKSMSAPI_WEBHOOK_SECRET; // whsec_...

app.post("/hooks/sms", express.raw({ type: "application/json" }), (req, res) => {
  const id = req.header("webhook-id");
  const ts = req.header("webhook-timestamp");
  const key = Buffer.from(secret.slice("whsec_".length), "base64url");
  const expected = crypto.createHmac("sha256", key).update(`${id}.${ts}.${req.body}`).digest("base64");
  const sent = (req.header("webhook-signature") || "").split(" ").map((s) => s.replace(/^v1,/, ""));
  const fresh = Math.abs(Date.now() / 1000 - Number(ts)) < 300;
  if (!fresh || !sent.some((s) => s.length === expected.length && crypto.timingSafeEqual(Buffer.from(s), Buffer.from(expected)))) {
    return res.status(401).end();
  }
  const event = JSON.parse(req.body);
  console.log(event.type, event.data.id, event.data.status);
  res.status(204).end();
});
app.listen(3000);
SMS API কোড স্যাম্পল: curl, Node.js, Python, PHP, Go | BulkSMSAPI ডক্স