messageway
v1.2.0
Published
MessageWay nodeJS library
Downloads
29
Readme
MessageWay NodeJS SDK
A NodeJS SDK for the MessageWay API.
Documents
Install
npm i messageway
Send Message Via WhatsApp Messenger
const { MessageWay } = require('messageway')
const message = new MessageWay(API_KEY)
message.sendWhatsAppMessage({
mobile: '09333333333',
templateID: 12,
params: ['Foo'],
length: 4,
})
.then(referenceID => {
console.log(referenceID)
})
.catch(error => {
console.error(error)
})
Send Message Via SMS
const { MessageWay } = require('messageway')
const message = new MessageWay(API_KEY)
message.sendSMS({
mobile: '09333333333',
templateID: 12,
params: ['Foo'],
length: 4,
expireTime: 120,
})
.then(referenceID => {
console.log(referenceID)
})
.catch(error => {
console.error(error)
})
Verify OTP Code
const { MessageWay, isMessageWayError } = require('messageway')
const otp = new MessageWay(API_KEY)
otp.verify({
mobile: '09333333333',
otp: '3305',
})
.then(() => {
console.log('Code is correct!')
})
.catch(error => {
// handle Error
if (isMessageWayError(error)) {
console.log(`Error ${error.code}: ${error.message}`)
} else {
// unknown error
console.error(error)
}
})
Use async functions
async function getStatus() {
try {
const result = await otp.getStatus({ OTPReferenceID: '1628960593121007556' })
console.log('Method: ' + result.OTPMethod)
console.log('Status: ' + result.OTPStatus)
console.log('Verified: ' + result.OTPVerified)
} catch (error) {
if (isMessageWayError(error)) {
console.log(`Error ${error.code}: ${error.message}`)
} else {
console.error(error)
}
}
}
getStatus()