0.0.6 • Published 1 year ago

msegat v0.0.6

Weekly downloads
-
License
ISC
Repository
github
Last release
1 year ago

Msegat TarmeezTech

Sponsored & Supported by TarmeezTech

Msegat

npm npm npm GitHub Msegat

A Node.js package for interacting with the Msegat API to send SMS messages, calculate message costs, and more.

Installation

You can install the msegat package using npm:

npm install msegat

Usage

Importing the Package

To use the msegat package, import it into your Node.js application:

const { Msegat } = require('msegat');
import { Msegat } from 'msegat';

Configuration

Create an instance of the Msegat class by providing your Msegat credentials:

const msegat = new Msegat('YOUR_USERNAME', 'YOUR_API_KEY', 'YOUR_USER_SENDER');

Methods

sendMessage(number: string, message: string): Promise<any>

Send a message to a single number.

  • Parameters:

    • number (string): The recipient's phone number.
    • message (string): The message content.
  • Returns: A promise that resolves with the API response.

Example:

msegat.sendMessage('1234567890', 'Hello, World!')
  .then(response => console.log(response))
  .catch(error => console.error(error));

sendPersonalizedMessages(numbers: string[], msg: string, vars: object[], options?: object): Promise<any>

Send personalized messages to multiple numbers with variables.

  • Parameters:

    • numbers (string[]): An array of recipient phone numbers.
    • msg (string): The message content.
    • vars (object[]): An array of variables for message personalization.
    • options (object, optional): Additional options (e.g., timeToSend, exactTime, msgEncoding, reqBulkId, reqFilter).
  • Returns: A promise that resolves with the API response.

Example:

const numbers = ['1234567890', '0987654321'];
const msg = 'Hello, {name}!';
const vars = [{ name: 'John' }, { name: 'Jane' }];

msegat.sendPersonalizedMessages(numbers, msg, vars)
  .then(response => console.log(response))
  .catch(error => console.error(error));

calculateMessageCost(contactType: string, contacts: string, msg: string, by: string, msgEncoding: string): Promise<any>

Calculate the cost of sending a message.

  • Parameters:

    • contactType (string): Type of contacts (e.g., 'single', 'bulk').
    • contacts (string): Contact details.
    • msg (string): The message content.
    • by (string): Calculation method.
    • msgEncoding (string): Message encoding (e.g., 'UTF8').
  • Returns: A promise that resolves with the API response.

Example:

msegat.calculateMessageCost('single', '1234567890', 'Hello, World!', 'per_sms', 'UTF8')
  .then(response => console.log(response))
  .catch(error => console.error(error));

Error Handling

The methods will throw an error if the request fails. Make sure to handle errors using try...catch or .catch().

msegat.sendMessage('1234567890', 'Hello, World!')
  .then(response => console.log(response))
  .catch(error => console.error('Error:', error.message));

License

This package is licensed under the MIT License.

0.0.6

1 year ago

0.0.5

1 year ago

0.0.41

1 year ago

0.0.4

1 year ago

0.0.33

1 year ago

0.0.32

1 year ago

0.0.31

1 year ago

0.0.3

1 year ago

0.0.2

1 year ago

0.0.1

1 year ago