Skip to content

Instantly share code, notes, and snippets.

@mib32
Created January 22, 2021 14:12
Show Gist options
  • Save mib32/f833400a6620f2c6ec9968360cf35412 to your computer and use it in GitHub Desktop.
Save mib32/f833400a6620f2c6ec9968360cf35412 to your computer and use it in GitHub Desktop.
How to fetch message views using TaaS
async function taasRequest(data) {
data.api_key = "xxxxxx:xxxxxxxx";
let res = await fetch('https://api.t-a-a-s.ru',
method: 'POST',
body: JSON.generate(data)
)
res = await res.json();
return res;
}
const channelToScan = "profunctor_io";
let res;
// First we get chat_id from username
res = taasRequest({
"@type": "searchPublicChat",
"username": channelToScan
})
const chatId = res.chat_id;
// Then we get necessary messages
res = taasRequest({
"@type": "getChatHistory",
"chat_id": chatId,
"limit": "100",
"offset": "0",
"from_message_id": "0"
})
const messageIds = res.messages.map(m => m.id);
// View messages is necessary for view counter to update, otherwise it's stalled
taasRequest({
"@type": "viewMessages",
"chat_id": chatId,
"message_ids": messageIds
})
res = taasRequest({
"@type": "getMessages",
"chat_id": chatId,
"message_ids": messageIds
})
// Finally print views counts
res.forEach(message => console.log(message.interaction_info.views_count))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment