thaibulksms-api
Version:
วิธีส่ง SMS ง่ายๆด้วย Thaibulksms API ทั้งแบบข้อความและ OTP
41 lines (35 loc) • 959 B
JavaScript
const axios = require('axios');
class TBS_SMS {
constructor(options) {
this.configs = {
api: `https://api-v2.thaibulksms.com`,
...options
}
}
sendSMS(body) {
return new Promise((resolve, reject) => {
let endpoint = `${this.configs.api}/sms`
axios.post(endpoint, {
...body
}, {
auth: {
username: this.configs.apiKey,
password: this.configs.apiSecret
}
}).then(function (response) {
resolve(response.data);
}).catch(function (error) {
if (error.response) {
error = {
...error.response
}
}
reject(error);
})
})
}
}
const sms = (options) => {
return new TBS_SMS(options)
}
module.exports = sms