I have code which makes just one request and returns some data I want. Here it is:
let res = await axios({
method: 'get',
url: `https://www.instagram.com/p/${videoId}/?utm_source=ig_web_copy_link?&__a=1&__d=1`,
headers: {
'Cookie': cookie,
'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/114.0.0.0 Safari/537.36'
}
}).catch(e => console.log(e))
return {
url: res?.data.items[0].video_versions[0].url,
cover: res?.data.items[0].image_versions2.candidates[0].url
}
videoId variable is just what comes after /reels/videoId (sample: Ct8xziAqLKs). What it does is just returns a direct url to video from Instagram Reels. And when this code executes inside the onText function from node-telegram-bot-api it works just as expected. However, I also have bot.on('inline_query') realization, and when executed through inline query, the axios give me the following error with the exact same request saying that "AxiosError: Request failed with status code 401":
data: {
message: 'Please wait a few minutes before you try again.',
require_login: true,
status: 'fail'
}
I assume that inline_query runs somewhere behind a few times, and this may cause the problem. But each time I run the code above I have a console log which also runs just one time from onText as well as inline_query.
Just forgot to add cookie from env inside inline_query. Problem resolved.