msgway
TypeScript icon, indicating that this package has built-in type declarations

1.3.2 • Public • Published

بسم الله الرّحمن الرّحیم

MsgWay.com Node.js SDK

Documents

Full documentation is here.

Install

npm install msgway

Send OTP Code Via WhatsApp Messenger

const { MsgWay } = require('msgway')
const otp = new MsgWay(API_KEY)

otp.sendWhatsAppMessage({
  mobile: '09333333333',
  templateID: 12,
  param1: 'Foo',
  length: 4,
})
.then(referenceID => {
  console.log(referenceID)
})
.catch(error => {
  console.error(error)
})

Send OTP Code Via SMS

const { MsgWay } = require('msgway')
const otp = new MsgWay(API_KEY)

otp.sendSMS({
  mobile: '09333333333',
  templateID: 12,
  param1: 'Foo',
  length: 4,
})
.then(referenceID => {
  console.log(referenceID)
})
.catch(error => {
  console.error(error)
})

Verify OTP Code

const { MsgWay, isMsgWayError } = require('msgway')
const otp = new MsgWay(API_KEY)

otp.verify({
  mobile: '09333333333',
  otp: '3305',
})
.then(() => {
  console.log('Code is correct!')
})
.catch(error => {
  // handle Error
  if (isMsgWayError(error)) {
    console.log(`Error ${error.code}: ${error.message}`)
  } else {
    // unknown error
    console.error(error)
  }
})

Use async functions

async function send() {
  try {
    const result = await otp.getStatus({ OTPReferenceID: 1628960593121007556n })
    console.log('Method: ' + result.OTPMethod)
    console.log('Status: ' + result.OTPStatus)
    console.log('Verified: ' + result.OTPVerified)
  } catch (error) {
    if (isMsgWayError(error)) {
      console.log(`Error ${error.code}: ${error.message}`)
    } else {
      console.error(error)
    }
  }
}

send()

Versions

Current Tags

  • Version
    Downloads (Last 7 Days)
    • Tag
  • 1.3.2
    1
    • latest

Version History

  • Version
    Downloads (Last 7 Days)
    • Published
  • 1.3.2
    1

Package Sidebar

Install

npm i msgway

Weekly Downloads

1

Version

1.3.2

License

MIT

Unpacked Size

12.2 kB

Total Files

6

Last publish

Collaborators

  • mojtaba74