diff --git a/.dockerignore b/.dockerignore new file mode 100644 index 00000000..369f4b8b --- /dev/null +++ b/.dockerignore @@ -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 diff --git a/README.md b/README.md index 558d2669..65833076 100644 --- a/README.md +++ b/README.md @@ -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 diff --git a/examples/echo.py b/examples/echo.py index ca195dc3..fec285b1 100644 --- a/examples/echo.py +++ b/examples/echo.py @@ -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"