From bde26ff2e5927c60fdf775df19279277a55086b3 Mon Sep 17 00:00:00 2001 From: bel Date: Sun, 26 Mar 2023 14:28:04 -0600 Subject: [PATCH] configurable BODY when using URL --- whisper-2023/hotwords.py | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/whisper-2023/hotwords.py b/whisper-2023/hotwords.py index aa201d1..1098282 100644 --- a/whisper-2023/hotwords.py +++ b/whisper-2023/hotwords.py @@ -187,6 +187,7 @@ class Actor(threading.Thread): self.url = environ["URL"] self.handle = self.handle_url self.headers = [i.split("=")[:2] for i in environ.get("HEADERS", "").split("//") if i] + self.body = environ.get("BODY", '{"hotword":"{{hotword}}","context":"{{context}}"}') log(self.headers) def run(self): @@ -219,8 +220,12 @@ class Actor(threading.Thread): value = value.replace("{{hotword}}", hotword) value = value.replace("{{context}}", context) headers[key] = value - log("POST", self.url, headers, hotword, context) - requests.post(self.url, json={"hotword":hotword, "context":context}, headers=headers) + body = self.body + body = body.replace("{{hotword}}", hotword) + body = body.replace("{{context}}", context) + if environ.get("DEBUG", "") : + log("POST", self.url, headers, body) + requests.post(self.url, headers=headers, data=body) except Exception as e: log("Actor.handle_url:", e)