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

@rytass/sms

v0.2.0

Published

Rytass Utils SMS Gateway

Readme

Rytass Utils - SMS

A unified SMS service interface for the Rytass ecosystem. Provides a standardized way to send SMS messages across different SMS providers including Every8D and other Taiwan SMS service providers.

Features

  • [x] Unified SMS service interface
  • [x] Multiple SMS provider support
  • [x] Single and batch SMS sending
  • [x] Multi-target messaging
  • [x] TypeScript with strict typing
  • [x] Response status tracking
  • [x] Error handling

Installation

npm install @rytass/sms
# or
yarn add @rytass/sms

Available Adapters

Basic Usage

Using Every8D Adapter

import { SMSServiceEvery8D } from '@rytass/sms-adapter-every8d';

const smsService = new SMSServiceEvery8D({
  username: 'your-username',
  password: 'your-password',
});

// Send single SMS
const response = await smsService.send({
  mobile: '+886912345678',
  text: 'Hello, this is a test message!',
});

console.log('SMS sent:', response.status);

Batch SMS Sending

// Send multiple SMS messages
const responses = await smsService.send([
  {
    mobile: '+886912345678',
    text: 'Message for first recipient',
  },
  {
    mobile: '+886987654321',
    text: 'Message for second recipient',
  },
]);

responses.forEach(response => {
  console.log(`SMS to ${response.mobile}: ${response.status}`);
});

Multi-Target Messaging

// Send same message to multiple recipients
const responses = await smsService.send({
  mobileList: ['+886912345678', '+886987654321', '+886555666777'],
  text: 'Same message for all recipients',
});

responses.forEach(response => {
  console.log(`SMS to ${response.mobile}: ${response.status}`);
});

Core Concepts

SMSService Interface

interface SMSService<Request, SendResponse, MultiTarget> {
  send(request: Request[]): Promise<SendResponse[]>;
  send(request: Request): Promise<SendResponse>;
  send(request: MultiTarget): Promise<SendResponse[]>;
}

Request Types

interface SMSRequest {
  mobile: string;
  text: string;
}

interface MultiTargetRequest {
  mobileList: string[];
  text: string;
}

Response Types

enum SMSRequestResult {
  SUCCESS = 'SUCCESS',
  FAILED = 'FAILED',
}

interface SMSSendResponse {
  messageId?: string;
  status: SMSRequestResult;
  mobile: string;
}

Advanced Usage

Custom SMS Service Implementation

import { SMSService, SMSRequest, SMSSendResponse, MultiTargetRequest, SMSRequestResult } from '@rytass/sms';

interface CustomSMSRequest extends SMSRequest {
  priority?: 'low' | 'normal' | 'high';
  scheduledTime?: Date;
}

interface CustomSMSResponse extends SMSSendResponse {
  cost?: number;
  deliveryTime?: Date;
}

class CustomSMSService implements SMSService<CustomSMSRequest, CustomSMSResponse, MultiTargetRequest> {
  async send(request: CustomSMSRequest): Promise<CustomSMSResponse>;
  async send(request: CustomSMSRequest[]): Promise<CustomSMSResponse[]>;
  async send(request: MultiTargetRequest): Promise<CustomSMSResponse[]>;
  async send(request: any): Promise<any> {
    if (Array.isArray(request)) {
      // Handle batch sending
      return Promise.all(request.map(req => this.sendSingle(req)));
    }

    if ('mobileList' in request) {
      // Handle multi-target sending
      return Promise.all(request.mobileList.map(mobile => this.sendSingle({ mobile, text: request.text })));
    }

    // Handle single SMS
    return this.sendSingle(request);
  }

  private async sendSingle(request: CustomSMSRequest): Promise<CustomSMSResponse> {
    try {
      // Implement your SMS sending logic here
      const messageId = `msg_${Date.now()}_${Math.random()}`;

      return {
        messageId,
        status: SMSRequestResult.SUCCESS,
        mobile: request.mobile,
        cost: 0.05,
        deliveryTime: new Date(),
      };
    } catch (error) {
      return {
        status: SMSRequestResult.FAILED,
        mobile: request.mobile,
      };
    }
  }
}

Integration Examples

Express.js API

import express from 'express';
import { SMSServiceEvery8D } from '@rytass/sms-adapter-every8d';

const app = express();
app.use(express.json());

const smsService = new SMSServiceEvery8D({
  username: process.env.EVERY8D_USERNAME!,
  password: process.env.EVERY8D_PASSWORD!,
});

app.post('/send-sms', async (req, res) => {
  try {
    const { mobile, text } = req.body;

    const response = await smsService.send({ mobile, text });

    res.json({
      success: response.status === 'SUCCESS',
      messageId: response.messageId,
      mobile: response.mobile,
      status: response.status,
    });
  } catch (error) {
    res.status(500).json({
      error: 'Failed to send SMS',
      message: error.message,
    });
  }
});

NestJS Service

import { Injectable } from '@nestjs/common';
import { ConfigService } from '@nestjs/config';
import { SMSServiceEvery8D } from '@rytass/sms-adapter-every8d';
import { SMSRequestResult } from '@rytass/sms';

@Injectable()
export class NotificationService {
  private smsService: SMSServiceEvery8D;

  constructor(private configService: ConfigService) {
    this.smsService = new SMSServiceEvery8D({
      username: this.configService.get('EVERY8D_USERNAME')!,
      password: this.configService.get('EVERY8D_PASSWORD')!,
    });
  }

  async sendVerificationCode(mobile: string, code: string): Promise<boolean> {
    const response = await this.smsService.send({
      mobile,
      text: `Your verification code is: ${code}. This code will expire in 10 minutes.`,
    });

    return response.status === SMSRequestResult.SUCCESS;
  }

  async sendBulkNotification(mobiles: string[], message: string) {
    const responses = await this.smsService.send({
      mobileList: mobiles,
      text: message,
    });

    return {
      successful: responses.filter(r => r.status === SMSRequestResult.SUCCESS).length,
      failed: responses.filter(r => r.status === SMSRequestResult.FAILED).length,
    };
  }
}

Error Handling

import { SMSRequestResult } from '@rytass/sms';

async function safeSendSMS(smsService: any, mobile: string, text: string) {
  try {
    const response = await smsService.send({ mobile, text });

    if (response.status === SMSRequestResult.SUCCESS) {
      console.log(`SMS sent successfully to ${mobile}`);
      return { success: true, messageId: response.messageId };
    } else {
      console.warn(`SMS failed to send to ${mobile}`);
      return { success: false, error: 'SMS sending failed' };
    }
  } catch (error) {
    console.error(`Error sending SMS to ${mobile}:`, error);
    return { success: false, error: error.message };
  }
}

API Reference

SMSService Interface

interface SMSService<Request, SendResponse, MultiTarget> {
  send(request: Request[]): Promise<SendResponse[]>;
  send(request: Request): Promise<SendResponse>;
  send(request: MultiTarget): Promise<SendResponse[]>;
}

Types and Enums

| Type | Description | | -------------------- | ------------------------------------------------------- | | SMSRequestResult | 'SUCCESS' \| 'FAILED' | | SMSRequest | Basic SMS request with mobile and text | | SMSSendResponse | Response with status and optional messageId | | MultiTargetRequest | Request for sending same message to multiple recipients |

License

MIT