def process_request(self, path, query_string, content):
payload = json.loads(content)
path = path.split("/")
conversation_id = path[1]
if not conversation_id:
raise ValueError("conversation id must be provided in path")
text = None
if "echo" in payload:
text = payload["echo"]
image_data = None
image_filename = None
if "image" in payload:
if "base64encoded" in payload["image"]:
image_raw = base64.b64decode(payload["image"]["base64encoded"])
image_data = io.BytesIO(image_raw)
if "filename" in payload["image"]:
image_filename = payload["image"]["filename"]
else:
image_type = imghdr.what('ignore', image_raw)
image_filename = str(int(time.time())) + "." + image_type
logger.info("automatic image filename: {}".format(image_filename))
if not text and not image_data:
raise ValueError("nothing to send")
results = await self.send_data(conversation_id, text, image_data=image_data, image_filename=image_filename)
return results
评论列表
文章目录