Big changes - change engine, split core\plus version

This commit is contained in:
allburov committed 2022-11-11 12:31:07 +07:00
1 parent a7fe444166
commit 0b6058654e
174 files changed
+17851 -1803

No files matched your search

+44
View File
@@ -0,0 +1,44 @@
from pprint import pprint
import requests
from flask import Flask
from flask import request
app = Flask(__name__)
@app.route("/")
def whatsapp_echo():
return "WhatsApp HTTP API Echo server is ready!"
@app.route("/message", methods=["GET", "POST"])
def whatsapp_webhook():
data = request.get_json()
if not data:
return "WhatsApp HTTP API Echo server is ready!"
pprint(data)
if data['event'] != "message":
return f"Unknown event {data['event']}"
payload = data["payload"]
# The text
text = payload["body"]
# Number in format 791111111@c.us
from_ = payload["from"]
if payload.get("mediaUrl", None):
# Download file and set text to path
client_url = payload["mediaUrl"]
filename = client_url.split("/")[-1]
path = "/tmp/" + filename
r = requests.get(client_url)
open(path, "wb").write(r.content)
text = f"We have downloaded file here: {path}"
# Send a text back via WhatsApp HTTP API
response = requests.post(
"http://localhost:3000/api/sendText", json={"chatId": from_, "text": text}
)
response.raise_for_status()
return "OK"
+2
View File
@@ -0,0 +1,2 @@
flask
requests