Add caching CNAM
This commit is contained in:
parent
988bbb71e6
commit
e3d4007f31
27
index.js
27
index.js
|
@ -13,20 +13,27 @@ const fs = require('fs');
|
||||||
const app = express();
|
const app = express();
|
||||||
app.use(express.json());
|
app.use(express.json());
|
||||||
|
|
||||||
|
cnamCache = {};
|
||||||
|
|
||||||
app.post('/sms', async (req, res) => {
|
app.post('/sms', async (req, res) => {
|
||||||
data = req.body;
|
data = req.body;
|
||||||
// Get the CNAM record for the number
|
// Get the CNAM record for the number
|
||||||
cnam = data.From;
|
if (cnamCache[data.From]) {
|
||||||
await axios.get(`https://cnam.bulkvs.com/?id=${config.bulkvs.id}&did=${data.From}&format=json`, {
|
cnam = cnamCache[data.From];
|
||||||
headers: {
|
} else {
|
||||||
'Content-Type': 'application/json'
|
cnam = data.From;
|
||||||
}
|
await axios.get(`https://cnam.bulkvs.com/?id=${config.bulkvs.id}&did=${data.From}&format=json`, {
|
||||||
}).then(function (response) {
|
headers: {
|
||||||
cnam = response.data.name;
|
'Content-Type': 'application/json'
|
||||||
|
}
|
||||||
|
}).then(function (response) {
|
||||||
|
cnam = response.data.name;
|
||||||
|
|
||||||
}).catch(function (error) {
|
}).catch(function (error) {
|
||||||
console.log(error);
|
console.log(error);
|
||||||
});
|
});
|
||||||
|
cnamCache[data.From] = cnam;
|
||||||
|
}
|
||||||
if (data.MediaURLs) { // It's an MMS
|
if (data.MediaURLs) { // It's an MMS
|
||||||
out = {
|
out = {
|
||||||
"text": "",
|
"text": "",
|
||||||
|
|
Loading…
Reference in a new issue