in chat-client/main.py [0:0]
def handle_pubsub_message(req: flask.Request):
try:
envelope = req.get_json()
if not envelope:
raise Exception("No Pub/Sub message received")
pubsub_message = json.loads(
base64.b64decode(envelope["message"]["data"]).decode("utf-8").strip()
)
print(f"Processing Pub/Sub message: {pubsub_message}")
space_id = pubsub_message.get("space_id")
card_message = create_card_message(pubsub_message)
print(f"Sending the following card to space {space_id}:\n\n{card_message}")
client_utils.send_chat_message(space_id, card_message)
return ("Done", 200)
except Exception as e:
# Return a 200 to acknowledge receipt of the message
# otherwise Pub/Sub will continue to trigger this function
print(f"Error handling Pub/Sub message: {e}")
return ("Done", 200)