Created
March 7, 2021 14:01
-
-
Save rupython/4020bd50ff8c58343f5d5f3b753bc911 to your computer and use it in GitHub Desktop.
From: Alik Like
This file contains hidden or 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
from flask import Flask, request, jsonify | |
import requests | |
import json | |
import flask_cors | |
app = Flask(__name__) | |
flask_cors.CORS(app, resources={r"/*": {"origins": "*"}}) | |
bot_url = "https://api.telegram.org/botтутмойтокен/" | |
admin_log_chat_id = "-тутchatid" | |
# http://127.0.0.1:5000/new_form request body {text:"anystring"} returns message_id | |
@app.route('/new_form', methods=['POST']) | |
@flask_cors.cross_origin() | |
def hello(): | |
req_body = request.form | |
myobj = {"chat_id": admin_log_chat_id, "text": req_body["text"]} | |
x = requests.post(bot_url + "sendMessage", data=myobj) | |
print(x.text) | |
data = json.loads(x.text) | |
return jsonify({"ok": "Da", "message_id": data["result"]["message_id"]}) | |
# http://127.0.0.1:5000/update_form request body {text:"anystring",message_id:"string_that_parses_to_int"} returns message_id | |
@app.route('/update_form', methods=['POST']) | |
@flask_cors.cross_origin() | |
def login(): | |
req_body = request.form | |
myobj = {"chat_id": '-1001156275317', "text": req_body["text"], "message_id": req_body["message_id"]} | |
x = requests.post(bot_url + "editMessageText", data=myobj) | |
print(x.text) | |
return jsonify({"ok": "Yes"}) | |
if __name__ == '__main__': | |
app.run() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment