Fix #3: Add python echo server - download file

This commit is contained in:
allburov committed 2021-01-02 00:46:19 +07:00
1 parent 864574fd89
commit 7d3611c517
3 files changed
+55 -6

No files matched your search

+38
View File
@@ -0,0 +1,38 @@
tokens
files
venv
# compiled output
/dist
/node_modules
# Logs
logs
*.log
npm-debug.log*
yarn-debug.log*
yarn-error.log*
lerna-debug.log*
# OS
.DS_Store
# Tests
/coverage
/.nyc_output
# IDEs and editors
/.idea
.project
.classpath
.c9/
*.launch
.settings/
*.sublime-workspace
# IDE - VSCode
.vscode/*
!.vscode/settings.json
!.vscode/tasks.json
!.vscode/launch.json
!.vscode/extensions.json
+2
View File
@@ -98,6 +98,8 @@ docker run -it -v `pwd`/tokens:/app/tokens --network=host -e WHATSAPP_HOOK_ONMES
Now go ahead, open the second whatsapp and send to our WhatsApp HTTP API a text message! It must reply the same text.
If you try to send an image the "echo server" will send a path to the downloaded file.
# Environment variables
## Common
+15 -6
View File
@@ -17,13 +17,22 @@ def whatsapp_webhook():
data = request.get_json()
pprint(data)
# The text
body = data['body']
text = data["body"]
# Number in format 791111111@c.us
from_ = data['from']
from_ = data["from"]
if data.get("clientUrl", None):
# Download file and set text to path
client_url = data["clientUrl"]
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": body
})
response = requests.post(
"http://localhost:3000/api/sendText", json={"chatId": from_, "text": text}
)
response.raise_for_status()
return "OK"