Skip to content

Instantly share code, notes, and snippets.

@ihciah ihciah/README.MD
Last active Jan 29, 2019

What would you like to do?
A reverse proxy for Telegram Bot API on Aliyun Function Compute

A reverse proxy for Telegram Bot API on Aliyun Function Compute

To help users in China mainland access telegram api stably and conveniently with low cost, this script maybe the one you need.

The server-less means you don't have to run a server to proxy the requests, just pay as you go.


Edit key_prefix, set it to the prefix of you bot address can avoid abusing.

Tip: You should create the function in regions outside China mainland.

#!/usr/bin/env python
# coding=utf-8
from flask import Flask
from flask import request
from flask import make_response
import requests
from urllib.parse import urlparse
from urlparse import urlparse
app = Flask(__name__)
base_path = ''
key_prefix = "/bot"
telegram_api = ""
@app.route('/', defaults={'path': ''}, methods=['GET', 'POST'])
@app.route('/<path:path>', methods=['GET', 'POST'])
def home(path):
if not request.full_path.startswith(key_prefix):
return make_response("401 Unauthorized.", 401)
method = request.method
full_path = request.full_path
url = telegram_api + full_path
data = None if method.upper() == "GET" else request.form.to_dict()
req = requests.request(method, url, data=data)
return make_response(req.content, req.status_code)
def handler(environ, start_response):
parsed_tuple = urlparse(environ['fc.request_uri'])
li = parsed_tuple.path.split('/')
global base_path
if not base_path:
base_path = "/".join(li[0:5])
return app(environ, start_response)
import requests
data = {"chat_id":CHAT_ID, "text":"TEST"}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.