The News Analysis Telegram Bot fetches and transforms news headlines from newsapi.org and analyses them using TextRazor and sends them back to the user as a bot message using Fluvio Node.js Client and Stateful Dataflow(sdf) pipeline.
- Basic understanding of Event-Driven Architecture and APIs.
- Windows(WSL-Ubuntu) or Linux OS
- Rust 1.80 or beyond installed
- Node.js 16.11.0 or beyond installed
- Telegram Web-hooks
- Fluvio CLI
- Stateful Dataflows(sdf)
- Express.js
- ngrok
- NewsAPI(Free Tier) - To fetch News Articles
- TextRazor(Free Tier) - To classify News Articles
- Telegram Bot API - To communicate with bot
- ngrok - To create secure tunneling
- To install Fluvio, open terminal and run
curl -fsS https://hub.infinyon.cloud/install/install.sh | bash
- Add fluvio to your path and source the new .bashrc file
echo 'export PATH="${HOME}/.fvm/bin:${HOME}/.fluvio/bin:${PATH}"' >> ~/.bashrc
echo 'source "${HOME}/.fvm/env"' >> ~/.bashrc
source ~/.bashrc
- Start fluvio cluster by running command below
fluvio cluster start
- Installing wasm32-wasip1
rustup target add wasm32-wasip1
- Currently sdf is in beta mode so lets install it using fvm
fvm install sdf-beta1.1
- Validating if prerequisites of sdf got installed correctly
sdf setup
- Create the SDF worker
sdf worker create main
- Run the SDF with the required API keys which will compile and run the dataflow.
sdf run --ui --ephemeral -e NEWS_ORG=YOUR_NEWS_ORG_API_KEY -e TEXTRAZOR_KEY=YOUR_TEXTRAZOR_API_KEY -e BOT_TOKEN=YOUR_TELEGRAM_BOT_KEY
- Alternatively, you can run the SDF without the ui
sdf run --ephemeral -e NEWS_ORG=YOUR_NEWS_ORG_API_KEY -e TEXTRAZOR_KEY=YOUR_TEXTRAZOR_API_KEY -e BOT_TOKEN=YOUR_TELEGRAM_BOT_KEY
- Now checkout to server folder
cd server
- Install the required Node.js dependencies
npm install
- Set your API keys of Telegram Bot (follow Instructions) and ngrok in .env file.
- Start the server to receive events from Telegram
npx ts-node index.ts
- As your server is up and running you can now use the Telegram bot to get updates using /start and /updates commands.
- Note: If you want to get news articles of different country other than India you can do that by changing below url in dataflow.yaml file.
https://newsapi.org/v2/top-headlines?country=<COUNTRY_CODE>
news topic - Sample consumed event Sample consumed Response Format
{
"chatid": "5048923407",
"results": [
{
"author": "NDTV",
"published_at": "2024-08-25T11:25:15Z",
"source": {
"id": "google-news",
"name": "Google News"
},
"title": "On Haryana Poll Postponement Request, BJP Leader's Clarification - NDTV",
"url": "some url"
}
]
}
summarized-articles topic - Sample consumed event Sample consumed Response Format
{
"counts": [
{
"author": "WION",
"count": 1
},
{
"author": "NDTV Movies",
"count": 1
},
{
"author": "NDTV Sports",
"count": 1
},
{
"author": "The Economic Times",
"count": 1
},
{
"author": "Onmanorama",
"count": 1
},
{
"author": "TOI Etimes",
"count": 1
},
{
"author": "Mint",
"count": 1
},
{
"author": "Al Jazeera English",
"count": 1
},
{
"author": "Moneycontrol",
"count": 1
},
{
"author": "NDTV",
"count": 3
},
{
"author": "Hindustan Times",
"count": 5
},
{
"author": "BusinessLine",
"count": 1
},
{
"author": "The Indian Express",
"count": 1
},
{
"author": "The Hindu",
"count": 1
}
]
}
classified-articles topic - Sample consumed event Sample consumed Response Format
{
"chatid": "1234567890",
"results": [
{
"categories": [
{
"label": "Politics",
"score": 0.7437
},
{
"label": "Politics>Elections",
"score": 0.5229
}
],
"text": "On Haryana Poll Postponement Request, BJP Leader's Clarification - NDTV"
},
{
"categories": [
{
"label": "Science",
"score": 0.9956
},
{
"label": "Science>Space and Astronomy",
"score": 0.7291
}
],
"text": "NASA Hubble captures 'candy-floss' in space. Meet our cosmic neighbours - Hindustan Times"
}
]
}
The bot sends analyzed messages in the following format:
Classifying News Articles from the Past 24 hours:
Article: <Article_Title>
Classified Labels:
- <Label>: <Probability_Score>
- <Label>: <Score>
Article: <Article_Title>
Classified Labels:
- <Label>: <Score>
- <Label>: <Score>