# Google Apps Script

<details>

<summary>Send Email</summary>

```javascript
function doPost(e) {
  var param = e.parameter ;
  var title = '' ;
  var body = '' ;
  switch (param.Order_Status)  {
    case "新成立":
      title = "新訂單成立" ;
      body = "如有現貨，寄貨時間為1~3天內。" ;
      break;
    case "缺貨中":
      title = "品項缺貨中" ;
      body = "﹝目前訂單內品項尚有缺貨﹞" ;
      break;
    case "已完成":
      title = "訂單已完成" ;
      body = "感謝您本次購買<br>如使用商品符合您的期待<br>歡迎再次回購<br>購物網站：<br>https://jay.twl.ink/" ;
      break;
    case "取消單":
      title = "訂單已取消" ;
      body = "取消原因：" + param.Order_Remarks ;
      break;
    default:
      title = "";
      break;
  }
  try {
    MailApp.sendEmail({
      name: "Jay 管理系統",
      to: param.Client_Email,
      bcc: "jay@1oe0.com",
      replyTo: "jay@1oe0.com",
      subject: "小傑的賣場﹝" + title + "﹞",
      htmlBody: "<p>" + param.Client_Name + " 您好，訂單資訊如下</p>"+
                "<p>訂單編碼：" + param.Orders_ID +
                "<br>下單時間：" + param.Time_Create +
                "<br>目前狀態：" + param.Order_Status +
                "</p><p>" + body + "</p>" +
                "<a href=\"https://jay.1oe0.com/Data.php?SID=" + param.Orders_ID + "\" target=\"_blank\"> 點我查看訂單 </a>" +
                "<p>此為系統自動發送，請勿直接回覆。</p>"+
                "<p>若您對訂單有任何問題，歡迎透過客服信箱：<br>jay@1oe0.com<br>或者聯絡本人Instagram：<br>https://www.instagram.com/_____28.o7_prince/</p>",
    });
  } catch(ex) {
    console.error(ex);
  }
  return ContentService.createTextOutput("傳送成功");
}

function emailQuotaRemaining() {
  var emailQuotaRemaining = MailApp.getRemainingDailyQuota();
  Logger.log("Remaining email quota: " + emailQuotaRemaining);
}
```

</details>

<details>

<summary>Google Forms To Line Notify</summary>

## 表單收到新回應傳送LINE通知

創建一個表單 <https://forms.new>

點選『回覆』連結一個試算表

<img src="/files/wyww7qxBK83LemXgsekN" alt="" data-size="original">

點選『工具』選擇『指令碼編輯器』

<img src="/files/UQ5w1mnXuLEybRAkUeLE" alt="" data-size="original">

貼上程式碼

<img src="/files/tWsdUYcnxPNJ0KgZ2vmn" alt="" data-size="original">

圖片程式碼僅供參考，請以下方最新程式碼為準。

```javascript
function onSubmit(datas) {
  // 取得提交的值
  var Data = datas.namedValues;
  // 要傳送的訊息
  var Message = 'Google表單收到新提交\\n';
  // 整理訊息
  for(var Key in Data) {
    Message += Key + '：' + Data[Key] + '\\n';
  }
  // 發送訊息
  var List = JSON.parse(UrlFetchApp.fetch('<https://org.1oe0.com/Api/Notify?T=46963e88437560cbe463b1fdc2d9543a>'));
  for (var Key in List) {
    try {
      UrlFetchApp.fetch('<https://notify-api.line.me/api/notify>', {
        'headers': {
          'Authorization': 'Bearer ' + List[Key],
        },
        'method': 'post',
        'payload': {
          'message': Message
        }
      })
    } catch(ex) {
      console.error(List[Key] , ex);
    }
  }
}
```

切換至『觸發條件』

<img src="/files/jg5jCPa1mnSFV2KJ2NPd" alt="" data-size="original">

新增一個觸發條件『活動類型』選擇『提交表單時』

<img src="/files/y1TX1BYAqKJ8XUEuzY3d" alt="" data-size="original">

</details>


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://www.ggl.tw/document/google-apps-script.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
