diff --git a/app.js b/app.js index 7205cc1..f47f15f 100644 --- a/app.js +++ b/app.js @@ -1,9 +1,10 @@ require('dotenv').config(); var request = require("request"); -cachedRequest = require('cached-request')(request) -cacheDirectory = "./cache"; -cachedRequest.setCacheDirectory(cacheDirectory); +var throttledRequest = require('throttled-request')(request); +throttledRequest.configure({requests: 8, milliseconds: 60000}); //send 1 request per second +cachedRequest = require('cached-request')(throttledRequest); +cachedRequest.setCacheDirectory("./cache"); const logger = require('perfect-logger'); const TelegramBot = require('node-telegram-bot-api'); @@ -84,6 +85,7 @@ bot.on('message', (msg) => { }; cachedRequest(options, function (error, response, body) { + console.log(response) if (error) throw new Error(error); // console.log(body); @@ -123,6 +125,8 @@ bot.on('message', (msg) => { }; request(options, function (error, response, body) { + console.log(response) + if (error) throw new Error(error); let jsonBody = JSON.parse(body) bot.sendMessage(msg.chat.id, jsonBody.content) diff --git a/package-lock.json b/package-lock.json index ea25466..2d515e2 100644 --- a/package-lock.json +++ b/package-lock.json @@ -772,6 +772,11 @@ "resolved": "https://registry.npmjs.org/supports-color/-/supports-color-1.2.0.tgz", "integrity": "sha1-/x7R5hFp0Gs88tWI4YixjYhH4X4=" }, + "throttled-request": { + "version": "0.1.1", + "resolved": "https://registry.npmjs.org/throttled-request/-/throttled-request-0.1.1.tgz", + "integrity": "sha1-QUa3C3elrsozxGMyzxPrnHkelxs=" + }, "to-iso-string": { "version": "0.0.2", "resolved": "https://registry.npmjs.org/to-iso-string/-/to-iso-string-0.0.2.tgz", diff --git a/package.json b/package.json index 9259c35..5f26e1c 100644 --- a/package.json +++ b/package.json @@ -19,6 +19,7 @@ "node-telegram-bot-api": "^0.50.0", "perfect-logger": "^2.0.1", "rapidapi-connect": "0.0.6", - "request": "^2.88.2" + "request": "^2.88.2", + "throttled-request": "^0.1.1" } }