Skip to content

smsmanagercz/js-api

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

7 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

SmsManager JS API

A simple TypeScript/JavaScript library for sending SMS messages using the SMSManager API (https://smsmanager.com). Supports both Promise-based and callback-based usage, and returns message ID information. Source code available on GitHub.

Installation

npm install smsmanager-js-api

Building the Project

To build the project, follow these steps:

  1. Install dependencies:

    npm install
  2. Build the project:

    npm run build

The compiled JavaScript files will be output to the dist directory.

Usage

Promise-based (TypeScript)

import SmsManager from 'smsmanager-js-api';

const sender = new SmsManager('your-api-key-here');

async function sendMessage() {
  const result = await sender.send('phone-number-here', 'Your message text');
  if (result.success) {
    console.log('SMS sent successfully. Message ID:', result.messageId);
  } else {
    console.log('Failed to send SMS');
  }
}

sendMessage();

Callback-based (TypeScript)

import SmsManager from 'smsmanager-js-api';

const sender = new SmsManager('your-api-key-here');

sender.send('phone-number-here', 'Your message text', (error, result) => {
  if (error) {
    console.error('Error sending SMS:', error);
  } else if (result.success) {
    console.log('SMS sent successfully. Message ID:', result.messageId);
  } else {
    console.log('Failed to send SMS');
  }
});

Promise-based (JavaScript)

const SmsManager = require('smsmanager-js-api');

const sender = new SmsManager('your-api-key-here');

sender.send('phone-number-here', 'Your message text')
  .then(result => {
    if (result.success) {
      console.log('SMS sent successfully. Message ID:', result.messageId);
    } else {
      console.log('Failed to send SMS');
    }
  })
  .catch(error => {
    console.error('Error sending SMS:', error);
  });

Callback-based (JavaScript)

const SmsManager = require('smsmanager-js-api');

const sender = new SmsManager('your-api-key-here');

sender.send('phone-number-here', 'Your message text', (error, result) => {
  if (error) {
    console.error('Error sending SMS:', error);
  } else if (result.success) {
    console.log('SMS sent successfully. Message ID:', result.messageId);
  } else {
    console.log('Failed to send SMS');
  }
});

API

new SmsManager(apiKey: string)

Creates a new instance of the SmsManager class.

  • apiKey (string): Your SMSManager API key

sender.send(phoneNumber: string, message: string): Promise<SMSResult>

sender.send(phoneNumber: string, message: string, callback: (error: Error | null, result: SMSResult) => void): void

Sends an SMS message.

  • phoneNumber (string): The recipient's phone number
  • message (string): The text message to send
  • callback (optional function): A callback function to handle the result

Returns a Promise that resolves to an SMSResult object or calls the callback with the result. The SMSResult object has the following structure:

interface SMSResult {
  success: boolean;
  messageId: string | null;
}
  • success: true if the message was sent successfully, false otherwise.
  • messageId: A string containing the message ID if the send was successful, null otherwise.

License

MIT

About

No description, website, or topics provided.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors