A NodeJS SDK for the MessageWay API.
npm install messageway
const { MessageWay } = require('messageway')
const otp = new MessageWay(API_KEY)
otp.sendWhatsAppMessage({
mobile: '09333333333',
templateID: 12,
params: ['Foo'],
length: 4,
})
.then(referenceID => {
console.log(referenceID)
})
.catch(error => {
console.error(error)
})
const { MessageWay } = require('messageway')
const otp = new MessageWay(API_KEY)
otp.sendSMS({
mobile: '09333333333',
templateID: 12,
params: ['Foo'],
length: 4,
})
.then(referenceID => {
console.log(referenceID)
})
.catch(error => {
console.error(error)
})
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)
}
})
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 (isMessageWayError(error)) {
console.log(`Error ${error.code}: ${error.message}`)
} else {
console.error(error)
}
}
}
send()
OTP Status types 'pending': OTP not yet sent 'operatorDelivered': OTP sent to operator and waiting for delivery 'sent': User received OTP 'seen': OTP is seen by user (in messenger mode) 'notDelivered': OTP not delivered by operator 'failed': OTP failed to be delivered to operator
Check whether an error is a MessageWay standard error or not
These objects have two fields: code
and message
The error object to check
error
is a standard MessageWay error
Generated using TypeDoc
OTP Sending type