npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

@thinkcove-lib/communication

v1.0.3

Published

Reusable communication module for internal HTTP requests and templating.

Readme

📲 @thinkcove/communication

A TypeScript utility to send SMS messages using Pay2SMS. Built for backend services, this library supports templated messages, custom Axios options, and integrates seamlessly with your server applications using Axios and Mustache.


🚀 Features

  • ✅ Simple and reliable SMS sending via Pay2SMS
  • 📄 Supports templated messages using Mustache ({{variable}})
  • 🔧 Customizable via Axios options (headers, timeouts, etc.)
  • 🔐 Designed for secure backend usage
  • 🧪 Typed interfaces for safer development

📦 Installation

npm install @thinkcove/communication

🛠️ Usage

1. Import the function

import { sendPay2sms } from "@thinkcove/communication";

2. Configure your Pay2SMS credentials

const smsConfig = {
  smsUrl: "https://pay4sms.in/sendsms/", // Pay2SMS API endpoint
  senderId: "ABCDEF",                       // Registered sender ID
  creditType: "1",                          // "1" = Transactional, "2" = Promotional
  communicationToken: "YOUR_API_TOKEN",    // Token from Pay2SMS
  templateId: "DLT_TEMPLATE_ID"            // Approved DLT template ID
};

3. Prepare your SMS input

const input = {
  phoneNumber: "1010101010",
  template: "Hi {{name}}, your OTP is {{otp}}.",
  templateData: {
    name: "John",
    otp: "123456"
  }
};

4. (Optional) Add Axios configuration

// Optional: Customize Axios request
const axiosOptions = {
  timeout: 7000, // custom timeout (ms)
  method: "GET", // override method (default is GET)
  headers: {
    "X-App-Source": "billing-system",
    "Accept": "application/json"
  }
};

5. Send the SMS

const result = await sendPay2sms(input, smsConfig, axiosOptions);

if (result.success) {
  console.log("✅ SMS sent successfully:", result.response?.data);
} else {
  console.error("❌ SMS sending failed:", result.error);
}

🧩 Template Engine

This package uses mustache to render message templates.

Example:

template: "Hi {{name}}, your OTP is {{otp}}.",
templateData: {
  name: "Alice",
  otp: "789456"
}

Output:

Hi Alice, your OTP is 789456.

📄 API Reference

sendPay2sms(input, smsConfig, axiosOptions?)

Send an SMS using Pay2SMS with a templated message.

➤ Parameters

  • input: SmsSendInput
  • smsConfig: SmsConfigProps
  • axiosOptions (optional): Additional Axios configuration (method, headers, etc.)

➤ Returns

  • A Promise<SmsResponse> containing success status, message, and response/error.

🧾 Types

SmsSendInput

type SmsSendInput = {
  phoneNumber: string;
  template: string;
  templateData: Record<string, string | number | boolean>;
};

SmsConfigProps

type SmsConfigProps = {
  smsUrl: string;
  senderId: string;
  creditType: string;
  communicationToken: string;
  templateId: string;
};

SmsResponse

type SmsResponse = {
  success: boolean;
  message: string;
  response?: AxiosResponse;
  error?: any;
};

🔐 Security Best Practices

  • Do not expose your communicationToken on the frontend.
  • Store credentials securely using environment variables:
PAY2SMS_TOKEN=your_api_token
SENDER_ID=your_sender_id
TEMPLATE_ID=your_dlt_template_id
  • Load environment variables using dotenv:
import dotenv from "dotenv";
dotenv.config();

📎 Useful Links


📝 License

ISC License