#!/bin/bash

GOOGLE_CHAT_WEBHOOK_URL="https://chat.googleapis.com/v1/spaces/AAAA7hXAOCM/messages?key=AIzaSyDdI0hCZtE6vySjMm-WEfRq3CPzqKqqsHI&token=YupvEeDhNq2aF9ldCAf8TeJw8kmafVAXpj3xJWIzRGw%3D"


#echo "Generate the Thread Title ..."
#response=$(curl -s -X POST -H "Content-Type: application/json" \
#  -d '{"text":"這是主題訊息"}' \
#  "$GOOGLE_CHAT_WEBHOOK_URL")
#
## 取得 thread.name
#thread_name=$(echo "$response" | jq -r '.thread.name')
#if [[ "$thread_name" == "null" || -z "$thread_name" ]]; then
#  echo "Error: Can not get the thread.name"
#  echo "Response: $response"
#  exit 1
#fi
#echo "Get the thread.name successfully: $thread_name ..."

thread_name="spaces/AAAA7hXAOCM/threads/UvkuttTelDM"

echo "Send Messages to the same thread ..."
curl -s -X POST -H "Content-Type: application/json" \
  -d '{
        "text": "這是 thread 中的回覆 from bash",
        "thread": { "name": "'"$thread_name"'" }
      }' \
  "$GOOGLE_CHAT_WEBHOOK_URL"

echo "Finished."
