-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Francesco Cosentino
committed
Dec 28, 2023
1 parent
22acf4a
commit da45a49
Showing
7 changed files
with
278 additions
and
113 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
{ | ||
"python.analysis.typeCheckingMode": "off", | ||
"[python]": { | ||
"editor.defaultFormatter": "ms-python.black-formatter", | ||
"editor.formatOnSave": true | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
# Contributing Guidelines | ||
|
||
Thank you for being so interested in contributing to this bridge bwtween Telegram and Discord. I appreciate your willingness to share your knowledge and experience with me. | ||
|
||
The goal of this projet is to automate the process of sending messages from Telegram to Discord and soon other sources. This project is still in its early stages and I am looking for smart contributors to help me improve it. | ||
|
||
## How to Contribute | ||
|
||
### Reporting Issues | ||
|
||
One of the simplest ways to contribute is by reporting issues. If you encounter a problem with one of the tools, find a mistake in the documentation, or believe that a best practice needs to be updated, please open an issue on our GitHub repository. | ||
|
||
### Submitting Changes | ||
|
||
If you want to directly contribute to the project by adding new tools, updating documentation, or proposing new best practices, follow these steps: | ||
|
||
- **Fork the Repository:** Start by forking the project repository into your GitHub account. | ||
- **Create a Branch:** Create a new branch in your forked repository. It's good practice to name the branch according to the feature or fix you're implementing. | ||
- **Make Your Changes:** Add, edit, or delete files in your branch to implement the changes you want to make. | ||
- **Commit Your Changes:** Make sure to write clear, concise commit messages describing your changes. | ||
- **Push Your Changes:** Push your branch and its new commits to your forked repository on GitHub. | ||
- **Create a Pull Request:** Open a pull request from your forked repository to the main project repository. Please provide a detailed description of the changes you've made and the reasons behind them. | ||
|
||
## Reviewing Pull Requests | ||
|
||
Another way to contribute is by reviewing pull requests submitted by others. Look over the proposed changes, test them if possible, and leave feedback. | ||
|
||
## Contribution Guidelines | ||
|
||
To ensure that contributions are consistent and aligned with the project's objectives, please follow these guidelines: | ||
|
||
**Respect the Project's Scope:** All contributions should aim to improve the service stability, security, performance. Contributions that align with this objective may be accepted. | ||
|
||
**Follow Best Practices:** When contributing code, adhere to the coding style and practices established in the project. | ||
|
||
**Provide Detailed Information:** When reporting issues or submitting pull requests, provide as much relevant information as possible. This will help maintainers and other contributors understand your changes or your problems. | ||
|
||
**Respect Others:** Be kind and respectful towards other community members. Avoid disrespectful language and behaviour. | ||
|
||
## Conclusion | ||
|
||
Participating in open-source projects like this one can be an enriching experience. You have the opportunity to enhance your abilities while also making a valuable contribution to a resource that positively impacts the greater community. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,51 +1,48 @@ | ||
"""API controller for the Telegram bot.""" | ||
import os | ||
|
||
import httpx | ||
from fastapi import FastAPI, HTTPException | ||
from telegram import Bot | ||
from telegram.error import TelegramError | ||
|
||
app = FastAPI() | ||
from config import ConfigHandler | ||
|
||
# Assuming these are defined somewhere in your application | ||
TELEGRAM_TOKEN = os.getenv('TELEGRAM_TOKEN') | ||
TELEGRAM_API_URL = f"https://api.telegram.org/bot{TELEGRAM_TOKEN}/getMe" | ||
app = FastAPI() | ||
|
||
# You can add more service-specific URLs or checks here | ||
EXTERNAL_RESOURCES = [ | ||
"https://api.etherscan.io/api", | ||
TELEGRAM_API_URL # To check if the bot is still connected to Telegram API | ||
] | ||
config = ConfigHandler() | ||
|
||
|
||
@app.get("/health") | ||
async def health_check(): | ||
"""Health check endpoint.""" | ||
results = { | ||
"telegram_api": False, | ||
"external_resources": {} | ||
} | ||
results = {"telegram_api": False, "external_resources": {}} | ||
|
||
# Check Telegram Bot API connectivity | ||
try: | ||
bot = Bot(token=TELEGRAM_TOKEN) | ||
bot = Bot(token=config.telegram_token()) | ||
bot_info = await bot.get_me() | ||
results["telegram_api"] = bot_info is not None | ||
except TelegramError: | ||
results["telegram_api"] = False | ||
|
||
# Check external resources connectivity | ||
async with httpx.AsyncClient() as client: | ||
for url in EXTERNAL_RESOURCES: | ||
try: | ||
response = await client.get(url, timeout=5) | ||
results["external_resources"][url] = response.status_code == 200 | ||
except httpx.RequestError: | ||
results["external_resources"][url] = False | ||
|
||
if all(results["external_resources"].values()) and results["telegram_api"]: | ||
# Check Etherscan API health | ||
try: | ||
async with httpx.AsyncClient() as client: | ||
response = await client.get( | ||
config.etherscan_api_url(), | ||
params={"module": "stats", "action": "ping"}, | ||
timeout=5, | ||
) | ||
results["etherscan_api"] = ( | ||
response.status_code == 200 and response.json().get("message") == "OK" | ||
) | ||
except httpx.RequestError: | ||
results["etherscan_api"] = False | ||
|
||
# Overall health status | ||
if all(results.values()): | ||
return {"status": "healthy", "details": results} | ||
|
||
raise HTTPException(status_code=503, detail={ | ||
"status": "unhealthy", "details": results}) | ||
raise HTTPException( | ||
status_code=503, detail={"status": "unhealthy", "details": results} | ||
) |
Oops, something went wrong.