Giter VIP home page Giter VIP logo

melipayamak's Introduction

AccessControl.js

GitHub tag (latest by date) GitHub GitHub contributors

melipayamak

This is a lib to handle sending sms from melipayamak

Installing

Using npm:

$ npm install node-melipayamak

Using yarn:

$ yarn add node-melipayamak

Building the package:

$ npm run tsc

Example js

const MeliPayamak = require('node-melipayamak');
const sms = new MeliPayamak(process.env.SMS_TOKEN);

Example typescript

import { MeliPayamak } from 'node-melipayamak';
const sms = new MeliPayamak(process.env.SMS_TOKEN);

Sending simple sms

let from = '5000****';
let to   = '0912*******';
let text = 'a test message';

sms.sendSimple({from, to, text}).then(res => {
  let { recId, status } = res;
  console.log(recId, status);
}).catch(error => {
  console.log(error);
});

output example:

{
  "recId": "3741437414",
  "status": "error message if occurred"
}

Sending advance sms

let from = '5000****';
let to   = ['0912*******', '0917******', ...];
let text = 'a test message';
let udh  = '';

sms.sendAdvance({from, to, text, udh}).then(res => {
  let { recIds, status } = res;
  console.log(recIds, status);
}).catch(error => {
  console.log(error);
});

output example:

{
  "recIds": ["3741437414", "3741437415"],
  "status": "error message if occurred"
}

Sending shared sms

(You should create a message template in the site first ex: 'Dear {0}, your registration code is {1}')

let to   = '0912*******';
let bodyId = 254;
let args = ['Mr Smith', '1911'];

sms.sendShared({to, bodyId, args}).then(res => {
  let { recId, status } = res;
  console.log(recIds, status);
}).catch(error => {
  console.log(error);
});

output example:

{
  "recId": "3741437414",
  "status": "error message if occurred"
}

Sending with domain sms

let from   = '5000****';
let to     = '0912*******';
let text   = 'a test message';
let domain = 'www.some-domain.com';

sms.sendWithDomain({from, to, text, domain}).then(res => {
  let { recId, status } = res;
  console.log(recIds, status);
}).catch(error => {
  console.log(error);
});

output example:

{
  "recId": "3741437414",
  "status": "error message if occurred"
}

Getting sms status with its refId

let recIds   = ['3741437414', '3741437415'];

sms.checkStatus({recIds}).then(res => {
  let { results, resultsAsCode,  status} = res;
  console.log(results, resultsAsCode,  status);
}).catch(error => {
  console.log(error);
});

output example:

{
  "results": ['ارسال شده' ,'ارسال نشده'],
  "resultsAsCode": [-1, 200],
  "status": "error message if occurred"
}

Getting messages from server

let type   = 'in';
let number = '5000****';
let index  = 0;
let count  = 100;

sms.receiveMessages({type, number, index, count}).then(res => {
  let { messages,  status} = res;
  console.log(messages,  status);
}).catch(error => {
  console.log(error);
});

output example:

{
  "messages": [{
    "msgID": 1075415042,
    "userID": 0,
    "linkID": 0,
    "numberID": 0,
    "tariff": 0,
    "msgType": 0,
    "body": "A test message",
    "udh": "",
    "sendDate": "2021-07-01T21:06:59.767",
    "sender": "917*******",
    "receiver": "5000****",
    "firstLocation": 1,
    "currentLocation": 1,
    "parts": 1,
    "isFlash": false,
    "isRead": false,
    "isUnicode": true,
    "credit": 0,
    "module": 0,
    "recCount": 1,
    "recFailed": 0,
    "recSuccess": 0,
    "isMoneyBack": false,
    "userStepedMaster": 0,
    "userMaster": 0,
    "moneyBackCount": 0,
    "moneyBackLevel": 0,
    "autoSpeechText": null,
    "shareServiceBodyID": null,
    "irancellBackCount": null
  }, ...],
  "status": "error message if occurred"
}

Getting messages count from server

let isRead   = true;

sms.countMessages({isRead}).then(res => {
  let { count,  status} = res;
  console.log(count,  status);
}).catch(error => {
  console.log(error);
});

output example:

{
  "count": 274,
  "status": "error message if occurred"
}

Getting account remaining credit from server

sms.getCredit().then(res => {
  let { amount,  status} = res;
  console.log(amount,  status);
}).catch(error => {
  console.log(error);
});

output example:

{
  "amount": 37414,
  "status": "error message if occurred"
}

Getting price for sending messages from server

let mtnCount   = 10;
let irancellCount = 20;
let from = '5000****';
let text   = 'a test message';

sms.getPrice({mtnCount, irancellCount, from, text}).then(res => {
  let { price,  status} = res;
  console.log(price,  status);
}).catch(error => {
  console.log(error);
});

output example:

{
  "price": 15000,
  "status": "error message if occurred"
}

API Documentation

https://console.melipayamak.com/send/simple

Support Me

melipayamak's People

Contributors

hrashidi avatar

Watchers

James Cloos avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.