Skip to content

Official Node.js & TypeScript SDK ​

The official zero-dependency TypeScript & Node.js SDK for PingoLine. Works seamlessly in Node.js 18+, Next.js (App & Pages router), Express, Fastify, and edge runtimes.

npm version

Installation ​

bash
npm install pingoline
bash
pnpm add pingoline
bash
yarn add pingoline

Initialization ​

typescript
import { PingoLine } from 'pingoline';

const pingoline = new PingoLine({
  apiKey: process.env.PINGOLINE_API_KEY!,
  webhookSecret: process.env.PINGOLINE_WEBHOOK_SECRET, // optional, for webhooks
});

Usage ​

Order Confirmation Call ​

typescript
const call = await pingoline.createOrderCall({
  phone: '01712345678',
  order_id: 'ORD-5544',
  customer_name: 'Tanvir Hossain',
  amount: 1750,
  language: 'bn',
  send_sms: true,
});

SMS Gateway ​

typescript
// Single SMS
await pingoline.sendSms({
  phone: '01700000000',
  message: 'Your verification OTP is 458921.',
  type: 'otp',
});

// Bulk SMS
await pingoline.sendBulkSms({
  recipients: ['01700000000', '01800000000'],
  message: 'Special sale discount!',
});

Webhook Verification (Express) ​

typescript
import express from 'express';
import { PingoLine } from 'pingoline';

const app = express();
const pingoline = new PingoLine({
  apiKey: process.env.PINGOLINE_API_KEY!,
  webhookSecret: process.env.PINGOLINE_WEBHOOK_SECRET!,
});

app.post('/api/webhooks/pingoline', express.raw({ type: 'application/json' }), (req, res) => {
  const signature = req.headers['x-pingoline-signature'] as string;
  const rawBody = req.body.toString('utf8');

  try {
    const event = pingoline.constructEvent(rawBody, signature);

    if (event.isOrderCallCompleted()) {
      if (event.isConfirmed()) {
        console.log(`Order ${event.getOrderId()} confirmed!`);
      }
    }

    return res.status(200).json({ received: true });
  } catch (err) {
    return res.status(403).json({ error: 'Invalid signature' });
  }
});

Released under the MIT License.