Options
All
  • Public
  • Public/Protected
  • All
Menu

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

gsOTP.com Node.js SDK

Documents

Full documentation is here.

Install

npm install gsotp

Send OTP Code Via WhatsApp Messenger

const { GsOTP } = require('gsotp')
const otp = new GsOTP(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 { GsOTP } = require('gsotp')
const otp = new GsOTP(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 { GsOTP, isGsOTPError } = require('gsotp')
const otp = new GsOTP(API_KEY)

otp.verify({
  mobile: '09333333333',
  otp: '3305',
})
.then(() => {
  console.log('Code is correct!')
})
.catch(error => {
  // handle Error
  if (isGsOTPError(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 (isGsOTPError(error)) {
      console.log(`Error ${error.code}: ${error.message}`)
    } else {
      console.error(error)
    }
  }
}

send()

Index

Type aliases

OTPMethod

OTPMethod: "sms" | "ivr" | "messenger"

OTP Sending type

OTPStatus

OTPStatus: "pending" | "sent" | "seen" | "operatorDelivered" | "notDelivered" | "failed"

OTP Status types

'pending': OTP not yet sent

'operatorDelivered': OTP sent to operator and waiting for delivery

'sent': User recieved OTP

'seen': OTP is seen by user (in messenger mode)

'notDelivered': OTP not delivered by operator

'failed': OTP failed to be delivered to operator

SendInput

SendInput<IsManual>: IsManual extends true ? SendManualyInput : SendAutomaticInput

Type parameters

  • IsManual: boolean

Functions

isGsOTPError

  • isGsOTPError(error: any): error is OTPError
  • Check whether an error is a gsOTP standard error or not
    These objects have two fields: code and message

    Parameters

    • error: any

      The error object to check

    Returns error is OTPError

    error is a standard gsOTP error

Legend

  • Property
  • Method

Generated using TypeDoc