Note
This project is a work in progress.
This is a simple Telegram bot that forwards user requests to OpenAI's models, enabling access in regions where ChatGPT is unavailable.
This branch is for traditional (hosted) deployment. It can be run for free on Oracle Cloud (always free tier) and CockroachDB Cloud (free tier).
For a serverless deployment in AWS, see the aws-serverless branch.
- A paid OpenAI account. Where do I find my OpenAI API Key?
- A registered Telegram Bot. How Do I Create a Bot?
- A server to run the bot on, such as an Oracle Cloud (always free tier) instance.
- A Database server, such as CockroachDB Cloud (free tier).
- .NET 9.
- Copy the
appsettings*.json.example
files toappsettings*.json
files. - Set the
OPENAI_API_KEY
,TELEGRAM_BOT_TOKEN
, andTELEGRAM_BOT_SECRET
to actual values either in theappsettings*.json
files or via environment variables:OPENAI_API_KEY
- the OpenAI API that will be used by the application.TELEGRAM_BOT_TOKEN
- Telegram Bot token received from @BotFather.TELEGRAM_BOT_SECRET
- an arbitrary string of up to 256 characters, containing onlyA-Z
,a-z
,0-9
,-
, and_
. This secret verifies that requests to AWS originate from your Telegram webhook.
dotnet test
dotnet run --project ./TunnelGPT
See the Configure application settings section.
dotnet test
dotnet publish ./TunnelGPT -c Release -r linux-x64 --self-contained false -p:ContinuousIntegrationBuild=true -o ./publish
A TLS certificate is required for the server to listen on HTTPS.
The appsettings.json
configuration expects PEM-formatted files named tunnelgpt-cert.pem
and tunnelgpt-cert.key
.
Place them in the publish
directory after renaming.
A 100-year self-signed certificate example:
country="my-country"
organization="my-organization"
servername="my-servername"
openssl req -x509 -newkey rsa:4096 -sha256 -nodes -days 36500 \
-keyout ./publish/tunnelgpt-cert.key \
-out ./publish/tunnelgpt-cert.pem \
-subj "/C=$country=/O=$organization/CN=$servername"
- Upload the content of the
publish
directory to the target VM. - If you run the application as a non-root user on ports below 1024, ensure that
dotnet
binary has permission to bind to those ports:sudo setcap CAP_NET_BIND_SERVICE=+eip $(readlink -f /usr/bin/dotnet)
- Ensure the firewall allows incoming connections to the application ports (
iptables
example for 80 and 443):for port in 80 443; do if iptables -C INPUT -m state --state NEW -p tcp --dport $port -j ACCEPT 2>/dev/null; then echo "A rule allowing port $port already exists. No changes made."; else echo "No rule found for port $port. Adding rule..."; iptables -I INPUT 6 -m state --state NEW -p tcp --dport $port -j ACCEPT netfilter-persistent save fi done
- Ensure ASP.NET Core Runtime 9.0 is installed. See Install .NET on Linux.
- Start the application:
For production deployment, you may want to register a service in
dotnet <application_home_dir>/TunnelGPT.dll
systemd
.