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 🙏

© 2024 – Pkg Stats / Ryan Hefner

sms-mobizen

v1.0.4

Published

Package for sending SMS using the Mobizen API, developed in Angular and TypeScript

Downloads

8

Readme

SMS Mobizen

An npm package to simplify sending SMS messages using the Mobizen service.

To use this package, you nedd a Mobizen API KEY. You get a Mobizen API KEY in this link.

Installation

To install and use this package in your project, you can run the following npm command:

npm install sms-mobizen

Or if you prefer Yarn:

yarn add sms-mobizen

Usage

Before using the service, make sure to properly configure environment variables or configuration constants in your project as needed.

Configuration using Environment Variables

  1. Environment Variables in the Terminal:

    You can set environment variables directly in the terminal before starting your application. For example, on Linux/MacOS:

    export MOBIZEN_API_KEY='YOUR_MOBIZEN_API_KEY'
    export MOBIZEN_API_SERVER='https://api.mobizon.com.br'
    export MOBIZEN_API_VERSION='v1'
    export MOBIZEN_API_FORMAT='json'

    On Windows, the command is similar:

    set MOBIZEN_API_KEY=YOUR_MOBIZEN_API_KEY
    set MOBIZEN_API_SERVER=https://api.mobizon.com.br
    set MOBIZEN_API_VERSION=v1
    set MOBIZEN_API_FORMAT=json

    Then, your code can access these environment variables using process.env:

    const apiKey = process.env.MOBIZEN_API_KEY;
    const apiServer = process.env.MOBIZEN_API_SERVER;
    const apiVersion = process.env.MOBIZEN_API_VERSION;
    const format = process.env.MOBIZEN_API_FORMAT;
    
    const smsMobizen = new smsMobizen(apiKey, apiServer, apiVersion, format);
    
    // Now you can use smsMobizen.sendSms(...) to send SMS
  2. Configuration in the .env file:

    You can create a .env file at the root of your project to store your environment variables:

    MOBIZEN_API_KEY=YOUR_MOBIZEN_API_KEY
    MOBIZEN_API_SERVER=https://api.mobizon.com.br
    MOBIZEN_API_VERSION=v1
    MOBIZEN_API_FORMAT=json

    Then, you can use a library like dotenv to load these environment variables:

Install dotenv

npm install dotenv

Import dotenv and instantiate the module


import * as dotenv from 'dotenv';
dotenv.config();

const apiKey = process.env.MOBIZEN_API_KEY;
const apiServer = process.env.MOBIZEN_API_SERVER;
const apiVersion = process.env.MOBIZEN_API_VERSION;
const format = process.env.MOBIZEN_API_FORMAT;

const smsMobizen = new smsMobizen(apiKey, apiServer, apiVersion, format);

// Now you can use smsMobizen.sendSms(...) to send SMS

Configuration using Constants in the Code

If you prefer to configure variables directly in the code, you can create a configuration file (config.ts, for example) and import it where needed:

// config.ts
export const config = {
    apiKey: 'YOUR_MOBIZEN_API_KEY',
    apiServer: 'https://api.mobizon.com.br',
    apiVersion: 'v1',
    format: 'json',
};

In your service or where you need to configure SMS

import SmsMobizen from 'sms-mobizen';

import { config } from './config';

const smsMobizen = new SmsMobizen(config.apiKey, config.apiServer, config.apiVersion, config.format);

// Now you can use smsMobizen.sendSms(...) to send SMS

Sending SMS

To use the SMS service, import and instantiate the SmsMobizen class, passing the necessary configurations:

import SmsMobizen from 'sms-mobizen';

const smsMobizen = new SmsMobizen(apiKey, apiServer, apiVersion, format);

// Example of sending SMS
const recipients = ['+5511987654321'];
const text = 'Hello, world!';
smsMobizen.sendSms(recipients, text)
  .then(results => {
    console.log('Messages sent successfully:', results);
  })
  .catch(error => {
    console.error('Error sending messages:', error);
  });
// Using callbacks

import SmsMobizen from 'sms-mobizen';

const smsMobizen = new SmsMobizen(apiKey, apiServer, apiVersion, format);

const recipients = ['+5511987654321'];
const text = 'Hello, world!';

smsMobizen.sendSms(recipients, text, (error, results) => {
  if (error) {
    console.error('Error sending messages:', error);
  } else {
    console.log('Messages sent successfully:', results);
  }
});
// Using Async/Await

import SmsMobizen from 'sms-mobizen';

async function sendSms() {
  const smsMobizen = new SmsMobizen(apiKey, apiServer, apiVersion, format);

  const recipients = ['+5511987654321'];
  const text = 'Olá, mundo!';

  try {
    const results = await smsMobizen.sendSms(recipients, text);
    console.log('Messages sent successfully:', results);
  } catch (error) {
    console.error('Error sending messages:', error);
  }
}

sendSms();

Make sure to replace apiKey, apiServer, apiVersion, and format with your specific Mobizen values.

Contributions

Contributions are welcome! If you find any issues or want to improve this package, feel free to open an issue or submit a pull request on GitHub.

License

This project is licensed under the MIT License.

Author

Developed by Rodrigo Zan