Skip to content

Instantly share code, notes, and snippets.

@akash-joshi
Created December 26, 2020 10:56
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save akash-joshi/5b6d7fc0a61885fc84004892a45b23b9 to your computer and use it in GitHub Desktop.
Save akash-joshi/5b6d7fc0a61885fc84004892a45b23b9 to your computer and use it in GitHub Desktop.
const sendHn = async (ids) => {
const currentDate = new Date();
currentDate.setDate(currentDate.getDate() - 1);
const hnResponse = await axios.get(
`https://hn.algolia.com/api/v1/search?tags=story&numericFilters=created_at_i>${
currentDate.valueOf() / 1000
}`
);
const message = `
Today's top HN stories were:
${hnResponse.data.hits
.map(
(hit, index) =>
`\n\n${index + 1}. ${hit.title}\nhttps://news.ycombinator.com/item?id=${
hit.objectID
}\nPoints: ${hit.points}`
)
.join("")}
`;
for (const id of ids) {
bot.telegram.sendMessage(id, message);
}
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment