# Fetching Telegram messages for summary
## Overview
This project will fetch Telegram messages and produce summaries. There are two approaches: using the full Telegram API (client) or the Bot API. Each approach has different capabilities and constraints.
## Option 1 - Telegram Client (Telegram API)
**Capabilities**
* Acts as a Telegram client (e.g., using Telethon).
* Can fetch direct messages and group messages.
* Can retrieve messages from the last 24 hours and older (need to figure a good limit for message count though).
**Authentication and sessions**
* Requires user phone number, OTP, and password (if 2FA is enabled).
* The login flow must be interactive because the OTP is generated in real time.
* Login is one-time. A session file is created on the server so subsequent runs reuse the session and do not require re-login.
**Risks and policy**
* Be careful with usage. Improper or abusive usage can result in Telegram account bans.
* Relevant terms:
[https://core.telegram.org/api/terms](https://core.telegram.org/api/terms)
[https://telegram.org/tos/in](https://telegram.org/tos/in)
**Open questions / decisions**
1. How will we collect phone number, password, and OTP from users securely?
2. Will users deploy their own CVM enclave or VM for the backend to maintain session files?
3. Will users provide their own OpenAI API key when deploying a backend enclave? We cannot fund everyone.
4. How will users specify which DMs and channels to summarize?
5. How and where will the summary be delivered to the user?
## Option 2 - Bot API
**Limitations**
* Bots cannot access personal DMs. Attempting to fetch them raises errors like:
```
telethon.errors.rpcerrorlist.BotMethodInvalidError: The API access for bot users is restricted. The method you tried to invoke cannot be executed as a bot (caused by GetDialogsRequest)
```
* Bots cannot fetch full dialog history in the same way a user client can. For example:
```
telethon.errors.rpcerrorlist.BotMethodInvalidError: The API access for bot users is restricted. The method you tried to invoke cannot be executed as a bot (caused by GetHistoryRequest)
```
**Notes**
* Bot privacy mode must be disabled in a group if the bot should read messages from that group.
* Users must create a bot and provide a bot token to the backend.
**Open questions / decisions**
1. Will users provide their own OpenAI API key?
2. How will users specify which DMs and channels to summarize?
3. How and where will the summary be delivered to the user?
## Things I will need in future for further testing
1. Telegram account.
2. OpenAI API keys.