<?xml version="1.0" encoding="utf-8" standalone="yes"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:media="http://search.yahoo.com/mrss/">
  <channel>
    <title>Google App Script｜林鼎淵 Dean Lin</title>
    <link>https://deanlin.net/tags/google-app-script/</link>
    <image><url>https://deanlin.net/images/author_hu_aa256fc934e9a932.jpg</url><title>Google App Script｜林鼎淵 Dean Lin</title><link>https://deanlin.net/tags/google-app-script/</link><width>144</width><height>144</height></image>
    <description>林鼎淵（Dean Lin）的部落格：生成式 AI 企業內訓講師、外商資安公司軟體專家、7 本書作者。400 多篇文章用白話分享生成式 AI 實戰、Claude Code 與 Vibe Coding 教學、團隊合作與職場成長。</description>
    <generator>Hugo</generator>
    <language>zh-tw</language>
    <copyright>© 2020–2026 林鼎淵 Dean Lin</copyright>
    <lastBuildDate>Wed, 10 Jun 2020 12:13:46 +0800</lastBuildDate>
    <atom:link href="https://deanlin.net/tags/google-app-script/index.xml" rel="self" type="application/rss+xml" />
    <item>
      <title>讓Line機器人變成你的小秘書</title>
      <link>https://deanlin.net/blog/202006/line-bot-personal-assistant/</link>
      <pubDate>Wed, 10 Jun 2020 12:13:46 +0800</pubDate>
      <guid>https://deanlin.net/blog/202006/line-bot-personal-assistant/</guid>
      <dc:creator>林鼎淵</dc:creator>
      <category>技術教學</category>
      <description>機器人的秘書還不夠誘惑嗎ＸＤ</description>
      <media:content url="https://deanlin.net/blog/202006/line-bot-personal-assistant/images/line-bot-personal-assistant-og_hu_2dae16f1f3dfcd3f.jpg" medium="image" type="image/jpeg" width="1200" height="675" />
      <content:encoded><![CDATA[<blockquote>
<p>為什麼撰寫這篇文章</p>
</blockquote>
<p>在<a href="https://deanlin.net/blog/202006/line-bot-with-google-apps-script/">上一篇</a>文章已經介紹了Google App Script如何串接Line Message Api的應用，在這裡我將延續之前的議題，讓Line機器人變成你的小秘書</p>
<blockquote>
<p>文章目標</p>
</blockquote>
<ol>
<li>使用Google Sheet裡面Script的功能</li>
<li>使用簡單的SQL語法抓出Google Sheet中你需要的資訊</li>
</ol>
<blockquote>
<p>本文章使用到的技術：</p>
</blockquote>
<ol>
<li>Google App Script : 這次著重在執行SQL語法</li>
<li>Google Sheet : 會把它當成讀取/寫入的資料庫</li>
</ol>
<h2 id="step-1-結合google-sheet的衍生應用">STEP 1: 結合Google Sheet的衍生應用<a class="h-anchor" href="#step-1-%e7%b5%90%e5%90%88google-sheet%e7%9a%84%e8%a1%8d%e7%94%9f%e6%87%89%e7%94%a8" aria-label="這個段落的連結"></a></h2>
<blockquote>
<p>Google App Script功能很多，但能做到什麼地步就看個人的想像能力，接下來我提供的只是一條思路，如果大家想到有趣的應用歡迎下方留言</p>
</blockquote>
<p>如果大家平常有使用Google sheet當成工作記錄習慣的話，你可以嘗試看看這個應用</p>
<p>這裡我先創建一個Google Sheet，裡面建立一些清單(<a href="https://docs.google.com/spreadsheets/d/1ZdmsEkS27VWR6HF42_aka5rrtgu31saZoUupOD8Xx6s/edit?usp=sharing">你可以直接複製我的</a>)：</p>
<p><img src="https://deanlin.net/blog/202006/line-bot-personal-assistant/images/line-bot-personal-assistant-01.webp" width="1400" height="591" alt="STEP 1: 結合Google Sheet的衍生應用（圖 1）" fetchpriority="high" decoding="async"></p>
<p>接著建立Google Sheet的Script</p>
<p><img src="https://deanlin.net/blog/202006/line-bot-personal-assistant/images/line-bot-personal-assistant-02.webp" width="1400" height="811" alt="STEP 1: 結合Google Sheet的衍生應用（圖 2）" loading="lazy" decoding="async"></p>
<p>將以下程式複製貼上，如果您願意可以自由更改，記得將<a href="https://deanlin.net/blog/202006/line-bot-with-google-apps-script/">上一篇</a>取得的line token放上去喔</p>
<pre tabindex="0"><code>var ss = SpreadsheetApp.getActiveSpreadsheet()//抓取這張excel
function doPost (e) {
    var msg = JSON.parse(e.postData.contents);
    // 取出 replayToken 和發送的訊息文字
    var replyToken = msg.events[0].replyToken;
    var userMessage = msg.events[0].message.text;

    if (userMessage.indexOf(&#34;未完成&#34;) &gt; -1) {//分析傳遞字串確認是否有“未完成”
        // QUERY(目標文件及範圍,SQL語法)
        // 尋找sheet1範圍A2到C100裡面A跟B欄位的資料且C欄位為FALSE
        var formulaToUse = &#39;=QUERY(Sheet1!A2:C100,&#34;SELECT A,B WHERE C = FALSE&#34;)&#39;
        var result = query(formulaToUse)

        var userMessage = &#39;未完成文件如下：\n&#39;;//單純的文字組成
        result.forEach(row =&gt; {
            userMessage = userMessage + row[0] + &#39;:&#39; + row[1] + &#39;\n&#39;
        })
        return sendLineMsg(userMessage, replyToken);
    }
    if (userMessage.indexOf(&#34;已完成&#34;) &gt; -1) {//分析傳遞字串確認是否有“已完成”
        var formulaToUse = &#39;=QUERY(Sheet1!A2:C100,&#34;SELECT A,B WHERE C = TRUE&#34;)&#39;
        var result = query(formulaToUse)
        var userMessage = &#39;已完成文件如下：\n&#39;;
        result.forEach(row =&gt; {
            userMessage = userMessage + row[0] + &#39;:&#39; + row[1] + &#39;\n&#39;
        })
        return sendLineMsg(userMessage, replyToken);
    }
    if (userMessage.indexOf(&#34;功能&#34;) &gt; -1) {//這是列出你有提供功能的列表
        return sendLineMsg(&#39;朕不給的你不能搶ㄎㄎ\n• 未完成 ：列出excel未完成清單\n• 已完成 ：列出excel已完成清單&#39;, replyToken);
    }
}
function query (request) { //執行SQL語法的地方
    var sheet = ss.insertSheet(); //先插入一張新的sheet(也許有更好的做法，如果有請告訴我ＱＱ)
    sheet.getActiveRange().setFormula(request); //執行SQL
    var result = sheet.getDataRange().getValues(); //把整張表抓下來
    ss.deleteSheet(sheet); //把sheet刪除
    Logger.log(result);//可透過log來看輸出的資訊(上方的View Logs)
    return result; //回傳結果
}
function sendLineMsg (Message, replyToken) {
    var CHANNEL_ACCESS_TOKEN = &#39;你的 Channel access token&#39;;

    var url = &#39;https://api.line.me/v2/bot/message/reply&#39;;
    UrlFetchApp.fetch(url, {
        &#39;headers&#39;: {
            &#39;Content-Type&#39;: &#39;application/json; charset=UTF-8&#39;,
            &#39;Authorization&#39;: &#39;Bearer &#39; + CHANNEL_ACCESS_TOKEN,
        },
        &#39;method&#39;: &#39;post&#39;,
        &#39;payload&#39;: JSON.stringify({
            &#39;replyToken&#39;: replyToken,
            &#39;messages&#39;: [{
                &#39;type&#39;: &#39;text&#39;,
                &#39;text&#39;: Message,
            }],
        }),
    });
}
</code></pre><p class="code-source">原始碼：<a href="https://gist.github.com/dean9703111/8f6d1e06b079ae3061d450d459cedc2c" rel="noopener">line_secretary.gs</a>（GitHub Gist）</p>
<p>接下來要將這個程式發布（如果有授權相關問題必須都接受才會通過）</p>
<p><img src="https://deanlin.net/blog/202006/line-bot-personal-assistant/images/line-bot-personal-assistant-03.webp" width="998" height="408" alt="STEP 1: 結合Google Sheet的衍生應用（圖 3）" loading="lazy" decoding="async"></p>
<p>Project version記得每次都要選擇New(否則不會更新)，並且要允許任何人可以存取這隻app，不然你的程式無法被line機器人執行</p>
<p><img src="https://deanlin.net/blog/202006/line-bot-personal-assistant/images/line-bot-personal-assistant-04.webp" width="892" height="804" alt="STEP 1: 結合Google Sheet的衍生應用（圖 4）" loading="lazy" decoding="async"></p>
<p>接下來複製你這串web app URL給LINE Message Api使用</p>
<p><img src="https://deanlin.net/blog/202006/line-bot-personal-assistant/images/line-bot-personal-assistant-05.webp" width="892" height="534" alt="STEP 1: 結合Google Sheet的衍生應用（圖 5）" loading="lazy" decoding="async"></p>
<p>貼到webhook URL上面後按下Save</p>
<p><img src="https://deanlin.net/blog/202006/line-bot-personal-assistant/images/line-bot-personal-assistant-06.webp" width="1400" height="698" alt="STEP 1: 結合Google Sheet的衍生應用（圖 6）" loading="lazy" decoding="async"></p>
<h2 id="step-2--驗證串接成功">STEP 2 : 驗證串接成功<a class="h-anchor" href="#step-2--%e9%a9%97%e8%ad%89%e4%b8%b2%e6%8e%a5%e6%88%90%e5%8a%9f" aria-label="這個段落的連結"></a></h2>
<p>打開你的LINE就可以輸入下面三種文字，機器人就會做相對應的回覆喔！</p>
<ol>
<li>功能</li>
<li>未完成</li>
<li>已完成</li>
</ol>
<p><img src="https://deanlin.net/blog/202006/line-bot-personal-assistant/images/line-bot-personal-assistant-07.webp" width="748" height="1140" alt="STEP 2 : 驗證串接成功（圖 7）" loading="lazy" decoding="async"></p>
<p>希望大家喜歡這篇文章的應用～</p>
]]></content:encoded>
    </item>
    <item>
      <title>用Google App Script打造打造自己的lINE機器人</title>
      <link>https://deanlin.net/blog/202006/line-bot-with-google-apps-script/</link>
      <pubDate>Wed, 10 Jun 2020 12:12:04 +0800</pubDate>
      <guid>https://deanlin.net/blog/202006/line-bot-with-google-apps-script/</guid>
      <dc:creator>林鼎淵</dc:creator>
      <category>技術教學</category>
      <description>來打造一個回聲狗吧～</description>
      <media:content url="https://deanlin.net/blog/202006/line-bot-with-google-apps-script/images/line-bot-with-google-apps-script-og_hu_5aca1942c5c55728.jpg" medium="image" type="image/jpeg" width="1200" height="675" />
      <content:encoded><![CDATA[<blockquote>
<p>為什麼撰寫這篇文章</p>
</blockquote>
<p>Google App Script在以前我就非常的喜愛，也曾用他來當我專案後台登入的api來使用，搭配上Google Sheet，你簡直獲得了免費資料庫(不過他執行的速度就…反正就免費的速度XD)</p>
<p>但為了讓技術經過這段日子獲得更多提升，我想在原先資料庫的應用上加點料，比如說串接機器人，讓機器人對你定期提醒</p>
<p>本文章僅僅是示範最簡單的應用層面，實際上應該有非常多的應用等待大家去發掘</p>
<blockquote>
<p>文章目標</p>
</blockquote>
<ol>
<li>了解Google App Script，可撰寫簡單api並附帶參數</li>
<li>Google App Script串接Line機器人，讓你可以自由決定使用功能</li>
</ol>
<blockquote>
<p>本文章使用到的技術：</p>
</blockquote>
<ol>
<li>Google App Script : 撰寫你想要執行的邏輯</li>
<li>LINE developers : 打造自己的lINE機器人</li>
</ol>
<h2 id="setp-1-建立-line-messaging-api">SETP 1: 建立 LINE Messaging API<a class="h-anchor" href="#setp-1-%e5%bb%ba%e7%ab%8b-line-messaging-api" aria-label="這個段落的連結"></a></h2>
<p>我們要先在<a href="https://developers.line.biz/zh-hant/">這裡申請到line</a>發送訊息所需要的token</p>
<p>除了Channel type要寫Messaging API外其他就自由發揮，反正你填錯或是漏填LINE會逼著你填完</p>
<p><img src="https://deanlin.net/blog/202006/line-bot-with-google-apps-script/images/line-bot-with-google-apps-script-01.webp" width="1400" height="682" alt="SETP 1: 建立 LINE Messaging API（圖 1）" fetchpriority="high" decoding="async"></p>
<p>新增完成後在Messaging Api裡面的basic id就是這個機器人在line的id</p>
<p><img src="https://deanlin.net/blog/202006/line-bot-with-google-apps-script/images/line-bot-with-google-apps-script-02.webp" width="1400" height="905" alt="SETP 1: 建立 LINE Messaging API（圖 2）" loading="lazy" decoding="async"></p>
<p>你就能在line裡面透過id找到他惹</p>
<p><img src="https://deanlin.net/blog/202006/line-bot-with-google-apps-script/images/line-bot-with-google-apps-script-03.webp" width="624" height="810" alt="SETP 1: 建立 LINE Messaging API（圖 3）" loading="lazy" decoding="async"></p>
<p>除了id之外最重要的就是token，這個也是在Messaging Api裡面的Channel access token</p>
<p><img src="https://deanlin.net/blog/202006/line-bot-with-google-apps-script/images/line-bot-with-google-apps-script-04.webp" width="1400" height="668" alt="SETP 1: 建立 LINE Messaging API（圖 4）" loading="lazy" decoding="async"></p>
<p>另外我們不需要Greeting message、Auto response的功能</p>
<p><img src="https://deanlin.net/blog/202006/line-bot-with-google-apps-script/images/line-bot-with-google-apps-script-05.webp" width="1400" height="890" alt="SETP 1: 建立 LINE Messaging API（圖 5）" loading="lazy" decoding="async"></p>
<h2 id="step-2--建立-google-apps-script-接收-line-訊息">STEP 2 : 建立 Google Apps Script 接收 LINE 訊息<a class="h-anchor" href="#step-2--%e5%bb%ba%e7%ab%8b-google-apps-script-%e6%8e%a5%e6%94%b6-line-%e8%a8%8a%e6%81%af" aria-label="這個段落的連結"></a></h2>
<p>你可以在<a href="https://www.google.com/script/start/">這裡開始你的Google App Script</a>的故事 ，點擊Start Scripting，開啟一個Google App Script的專案吧</p>
<p><img src="https://deanlin.net/blog/202006/line-bot-with-google-apps-script/images/line-bot-with-google-apps-script-06.webp" width="1400" height="944" alt="STEP 2 : 建立 Google Apps Script 接收 LINE 訊息（圖 6）" loading="lazy" decoding="async"></p>
<p>將以下程式複製貼上，如果您願意可以自由更改，記得將剛剛取得的line token放上去喔</p>
<pre tabindex="0"><code>function doPost (e) { //凡事使用post method皆要通過這個function 

  var CHANNEL_ACCESS_TOKEN = &#39;你的 Channel access token&#39;;
  var msg = JSON.parse(e.postData.contents);

  // 取出 replayToken 和發送的訊息文字
  var replyToken = msg.events[0].replyToken;
  var userMessage = msg.events[0].message.text;

  if (typeof replyToken === &#39;undefined&#39;) {
    return;
  }

  var url = &#39;https://api.line.me/v2/bot/message/reply&#39;;
  UrlFetchApp.fetch(url, {
    &#39;headers&#39;: {
      &#39;Content-Type&#39;: &#39;application/json; charset=UTF-8&#39;,
      &#39;Authorization&#39;: &#39;Bearer &#39; + CHANNEL_ACCESS_TOKEN,
    },
    &#39;method&#39;: &#39;post&#39;,
    &#39;payload&#39;: JSON.stringify({
      &#39;replyToken&#39;: replyToken,
      &#39;messages&#39;: [{
        &#39;type&#39;: &#39;text&#39;, // 格式為文字，line可以傳送多種個格式(carousel、image)，有興趣的可以自己研究
        &#39;text&#39;: userMessage, //你目標傳遞的訊息
      }],
    }),
  });
}
</code></pre><p class="code-source">原始碼：<a href="https://gist.github.com/dean9703111/7b90f26418375ed32aec1370a9673059" rel="noopener">code.gs</a>（GitHub Gist）</p>
<p>接下來要將這個程式發布（如果有授權相關問題必須都接受才會通過）</p>
<p><img src="https://deanlin.net/blog/202006/line-bot-with-google-apps-script/images/line-bot-with-google-apps-script-07.webp" width="1014" height="396" alt="STEP 2 : 建立 Google Apps Script 接收 LINE 訊息（圖 7）" loading="lazy" decoding="async"></p>
<p>Project version記得每次都要選擇New(否則不會更新)，並且要允許任何人可以存取這隻app，不然你的程式無法被line機器人執行</p>
<p><img src="https://deanlin.net/blog/202006/line-bot-with-google-apps-script/images/line-bot-with-google-apps-script-08.webp" width="892" height="804" alt="STEP 2 : 建立 Google Apps Script 接收 LINE 訊息（圖 8）" loading="lazy" decoding="async"></p>
<p>接下來複製你這串web app URL給LINE Message Api使用</p>
<p><img src="https://deanlin.net/blog/202006/line-bot-with-google-apps-script/images/line-bot-with-google-apps-script-09.webp" width="892" height="534" alt="STEP 2 : 建立 Google Apps Script 接收 LINE 訊息（圖 9）" loading="lazy" decoding="async"></p>
<p>貼到webhook URL上面後按下Save</p>
<p><img src="https://deanlin.net/blog/202006/line-bot-with-google-apps-script/images/line-bot-with-google-apps-script-10.webp" width="1400" height="698" alt="STEP 2 : 建立 Google Apps Script 接收 LINE 訊息（圖 10）" loading="lazy" decoding="async"></p>
<h2 id="step-3-驗證串接成功">STEP 3: 驗證串接成功<a class="h-anchor" href="#step-3-%e9%a9%97%e8%ad%89%e4%b8%b2%e6%8e%a5%e6%88%90%e5%8a%9f" aria-label="這個段落的連結"></a></h2>
<p>打開你的LINE就可以測試功能是否正常嚕～如果你是按照我的程式碼複製貼上，那他現在應該是回聲狗的功能XD</p>
<p><img src="https://deanlin.net/blog/202006/line-bot-with-google-apps-script/images/line-bot-with-google-apps-script-11.webp" width="748" height="886" alt="STEP 3: 驗證串接成功（圖 11）" loading="lazy" decoding="async"></p>
<p><strong>今天的教學就到這裡了～串接Google Sheet的部分我會放到<a href="https://deanlin.net/blog/202006/line-bot-personal-assistant/">下一篇文章</a>，歡迎有興趣的人來觀看喔！</strong></p>
<p>參考資源：<a href="https://www.oxxostudio.tw/articles/201805/backend-apps-script.html">簡易後端實作 ( Google Apps Script )</a></p>
]]></content:encoded>
    </item>
    <item>
      <title>免費打造專屬於您的問卷程式</title>
      <link>https://deanlin.net/blog/202006/free-custom-survey-app/</link>
      <pubDate>Wed, 03 Jun 2020 17:30:53 +0800</pubDate>
      <guid>https://deanlin.net/blog/202006/free-custom-survey-app/</guid>
      <dc:creator>林鼎淵</dc:creator>
      <category>技術教學</category>
      <description>Google Form & Google App Script & LINE Notity</description>
      <media:content url="https://deanlin.net/blog/202006/free-custom-survey-app/images/free-custom-survey-app-og_hu_8b5316a35a643901.jpg" medium="image" type="image/jpeg" width="1200" height="675" />
      <content:encoded><![CDATA[<h2 id="免費打造結合即時通知店家推廣的問卷程式">免費打造結合即時通知&amp;店家推廣的問卷程式<a class="h-anchor" href="#%e5%85%8d%e8%b2%bb%e6%89%93%e9%80%a0%e7%b5%90%e5%90%88%e5%8d%b3%e6%99%82%e9%80%9a%e7%9f%a5%e5%ba%97%e5%ae%b6%e6%8e%a8%e5%bb%a3%e7%9a%84%e5%95%8f%e5%8d%b7%e7%a8%8b%e5%bc%8f" aria-label="這個段落的連結"></a></h2>
<blockquote>
<p><strong>也許您曾經有這樣的經驗：</strong></p>
</blockquote>
<ol>
<li>顧客填寫完問卷後留下負評但店家未即時處置</li>
<li>顧客用餐體驗極佳但您卻沒讓他更近一步地幫店裡宣傳</li>
</ol>
<blockquote>
<p>文章目標：</p>
</blockquote>
<ol>
<li>客戶留下負面評價時會即時向店長(老闆)的line發出通知，讓店長(老闆)可以馬上了解狀況並處理</li>
<li>客戶留下好的用餐評價會引導他幫店家粉絲團按讚留下好評</li>
</ol>
<blockquote>
<p><strong>本文章使用到的技術：</strong></p>
</blockquote>
<ol>
<li>Google Form表單</li>
<li>Google App Script</li>
<li>LINE Notify</li>
</ol>
<p>接下來將一步一步解說如何從零打造您的問卷程式</p>
<h2 id="step-1--4--建立google-form表單">STEP 1 / 4 : 建立Google Form表單<a class="h-anchor" href="#step-1--4--%e5%bb%ba%e7%ab%8bgoogle-form%e8%a1%a8%e5%96%ae" aria-label="這個段落的連結"></a></h2>
<p>先建立一個<a href="https://www.google.com.tw/intl/zh-TW/forms/about/">Google Form</a>，選取個人的即可：</p>
<p><img src="https://deanlin.net/blog/202006/free-custom-survey-app/images/free-custom-survey-app-01.webp" width="1400" height="743" alt="STEP 1 / 4 : 建立Google Form表單（圖 1）" fetchpriority="high" decoding="async"></p>
<p>我將表單拆成兩個section如下圖，您可以設定自己想要的問題，不過我會建議您先跟我做一樣的步驟：</p>
<blockquote>
<p>Section1是店家評分的設定，我們會根據評分不同給予不同的導向</p>
</blockquote>
<p><img src="https://deanlin.net/blog/202006/free-custom-survey-app/images/free-custom-survey-app-02.webp" width="1400" height="1321" alt="STEP 1 / 4 : 建立Google Form表單（圖 2）" loading="lazy" decoding="async"></p>
<blockquote>
<p>Section2是當客戶不滿意時可以讓他加註的部分</p>
</blockquote>
<p><img src="https://deanlin.net/blog/202006/free-custom-survey-app/images/free-custom-survey-app-03.webp" width="1400" height="544" alt="STEP 1 / 4 : 建立Google Form表單（圖 3）" loading="lazy" decoding="async"></p>
<h2 id="step-2--4-撰寫google-app-script">STEP 2 / 4: 撰寫Google App Script<a class="h-anchor" href="#step-2--4-%e6%92%b0%e5%af%abgoogle-app-script" aria-label="這個段落的連結"></a></h2>
<p>完成上面Form的設定後就可以幫他加上Google App Script</p>
<p><img src="https://deanlin.net/blog/202006/free-custom-survey-app/images/free-custom-survey-app-04.webp" width="1400" height="782" alt="STEP 2 / 4: 撰寫Google App Script（圖 4）" loading="lazy" decoding="async"></p>
<p>將以下程式複製貼上，如果您願意可以自由更改，如果看不懂可在下方詢問，LINE Notify 的token會在Step3講解，您取得後再補上去即可</p>
<pre tabindex="0"><code>function getFormResponse (event) { //event為觸發submit事件時帶入的資訊

  //表單名稱(請填寫對應的名稱，否則google會無法找出對應的form id)
  var FORMNAME = &#34;餐後回饋表單&#34;;

  //取得表單
  var formHandle = DriveApp.getFilesByName(FORMNAME).next();

  //由表單 Id 開啟表單
  var form = FormApp.openById(formHandle.getId());

  //取得表單名稱
  var formTitle = form.getTitle();

  //取得表單回覆內容
  var formResponse = event.response;

  //取得表單上的項目
  var itemResponses = formResponse.getItemResponses();

  //傳送訊息設定
  var itemContext = &#34;\n&#34; + formTitle + &#34;\n 電子郵件 : &#34; + Session.getEffectiveUser().getEmail() + &#34;\n&#34;;
  
  //紀錄回覆評分
  var scrore = 0

  //將表單每一項問答組成訊息
  for (var j = 0; j &lt; itemResponses.length; j++) {
    //取得問題標題
    itemContext += itemResponses[j].getItem().getTitle();

    //取得問題回覆內容
    itemContext += &#34; : &#34; + itemResponses[j].getResponse() + &#34;\n&#34;;

    //用這裡來取得評分
    if (itemResponses[j].getItem().getTitle() == &#39;店家評分(5分最高)&#39;) {
      scrore = itemResponses[j].getResponse()
    }
  }

  //取得填寫表單時間
  itemContext += &#34;\n填寫時間 : &#34; + formResponse.getTimestamp() + &#34;\n\n\n&#34;;
  
  if (Number(scrore) &lt;= 2) {//如果訂單評分低於2分則馬上送出表單到Line讓店家儘速回覆
    sendToLine(itemContext);
    form.setConfirmationMessage(&#39;非常抱歉造成您用餐的不愉快，我們店長將儘快與您取得聯繫並致上最誠懇的道歉&#39;);
  } 
  else if (Number(scrore) &gt;= 4){//如果訂單評分高於4分則馬上送出店家粉絲團爭取按讚機會
    form.setConfirmationMessage(&#39;如果本次的用餐讓您感到愉悅，請您給粉絲團一個讚:&#39; + &#34;\n&#34; + &#39;https://www.facebook.com/profile.php?id=100001123361906&#39;);
  }

}

function sendToLine (message) {

  var token = &#34;你自己的LINE Notify&#34;;

  var options =
  {
    method: &#34;post&#34;,
    payload: &#34;message=&#34; + message,
    headers: { &#34;Authorization&#34;: &#34;Bearer &#34; + token },
    muteHttpExceptions: true
  };

  UrlFetchApp.fetch(&#34;https://notify-api.line.me/api/notify&#34;, options);
}
</code></pre><p class="code-source">原始碼：<a href="https://gist.github.com/dean9703111/6cc1f1f7ac5526b27b5e2963fc3b125a" rel="noopener">google_reponse</a>（GitHub Gist）</p>
<p>接下來要將這個程式發布（如果有授權相關問題必須都接受才會通過）</p>
<p><img src="https://deanlin.net/blog/202006/free-custom-survey-app/images/free-custom-survey-app-05.webp" width="1014" height="396" alt="STEP 2 / 4: 撰寫Google App Script（圖 5）" loading="lazy" decoding="async"></p>
<p>Project version記得每次都要選擇New(否則不會更新)</p>
<p><img src="https://deanlin.net/blog/202006/free-custom-survey-app/images/free-custom-survey-app-06.webp" width="920" height="1036" alt="STEP 2 / 4: 撰寫Google App Script（圖 6）" loading="lazy" decoding="async"></p>
<p>因為我們要觸發script裡面的function所以需要設定觸發的時機點如下：</p>
<p><img src="https://deanlin.net/blog/202006/free-custom-survey-app/images/free-custom-survey-app-07.webp" width="932" height="746" alt="STEP 2 / 4: 撰寫Google App Script（圖 7）" loading="lazy" decoding="async"></p>
<p><img src="https://deanlin.net/blog/202006/free-custom-survey-app/images/free-custom-survey-app-08.webp" width="1400" height="1356" alt="STEP 2 / 4: 撰寫Google App Script（圖 8）" loading="lazy" decoding="async"></p>
<p>如果新增成功就會看到下圖</p>
<p><img src="https://deanlin.net/blog/202006/free-custom-survey-app/images/free-custom-survey-app-09.webp" width="1400" height="234" alt="STEP 2 / 4: 撰寫Google App Script（圖 9）" loading="lazy" decoding="async"></p>
<h2 id="step-3--4-申請line-notify-token">STEP 3 / 4: 申請LINE Notify token<a class="h-anchor" href="#step-3--4-%e7%94%b3%e8%ab%8bline-notify-token" aria-label="這個段落的連結"></a></h2>
<p>因為我們表單在判斷評價低分時要向老闆(主管)的LINE推播，所以需要<a href="https://notify-bot.line.me/zh_TW/">申請一組LINE Notify的token</a>，你可以把它想像成一個允許對你LINE發送訊息的鑰匙</p>
<p><img src="https://deanlin.net/blog/202006/free-custom-survey-app/images/free-custom-survey-app-10.webp" width="1400" height="371" alt="STEP 3 / 4: 申請LINE Notify token（圖 10）" loading="lazy" decoding="async"></p>
<figure class="figure"><img src="https://deanlin.net/blog/202006/free-custom-survey-app/images/free-custom-survey-app-11.webp" width="1400" height="1023" alt="如果有曾經申請過token的就會在上方顯示" loading="lazy" decoding="async">
  <figcaption>如果有曾經申請過token的就會在上方顯示</figcaption>
</figure>

<p>接下來只需要將您申請的這組token貼到Google App Script裡面token的位置就好嚕～記得要重新publish App script的版本喔</p>
<h2 id="step-4-4-展示成果">STEP 4/ 4: 展示成果<a class="h-anchor" href="#step-4-4-%e5%b1%95%e7%a4%ba%e6%88%90%e6%9e%9c" aria-label="這個段落的連結"></a></h2>
<p>只要您按造上面的教學文件，如果順理的話應該會得到下面的畫面喔</p>
<blockquote>
<p>如果評分低於2分：</p>
</blockquote>
<p><img src="https://deanlin.net/blog/202006/free-custom-survey-app/images/free-custom-survey-app-12.webp" width="1400" height="1079" alt="STEP 4/ 4: 展示成果（圖 12）" loading="lazy" decoding="async"></p>
<p><img src="https://deanlin.net/blog/202006/free-custom-survey-app/images/free-custom-survey-app-13.webp" width="1400" height="882" alt="STEP 4/ 4: 展示成果（圖 13）" loading="lazy" decoding="async"></p>
<p><img src="https://deanlin.net/blog/202006/free-custom-survey-app/images/free-custom-survey-app-14.webp" width="1400" height="410" alt="STEP 4/ 4: 展示成果（圖 14）" loading="lazy" decoding="async"></p>
<p><img src="https://deanlin.net/blog/202006/free-custom-survey-app/images/free-custom-survey-app-15.webp" width="764" height="934" alt="STEP 4/ 4: 展示成果（圖 15）" loading="lazy" decoding="async"></p>
<blockquote>
<p>如果評分高於4分</p>
</blockquote>
<p><img src="https://deanlin.net/blog/202006/free-custom-survey-app/images/free-custom-survey-app-16.webp" width="1400" height="1079" alt="STEP 4/ 4: 展示成果（圖 16）" loading="lazy" decoding="async"></p>
<p><img src="https://deanlin.net/blog/202006/free-custom-survey-app/images/free-custom-survey-app-17.webp" width="1400" height="390" alt="STEP 4/ 4: 展示成果（圖 17）" loading="lazy" decoding="async"></p>
<p><img src="https://deanlin.net/blog/202006/free-custom-survey-app/images/free-custom-survey-app-18.webp" width="1400" height="445" alt="STEP 4/ 4: 展示成果（圖 18）" loading="lazy" decoding="async"></p>
<h2 id="人生第一篇部落格教學到這裡結束啦希望大家都有透過這些工具的組合蹦出新的火花喔">人生第一篇部落格教學到這裡結束啦～希望大家都有透過這些工具的組合蹦出新的火花喔～<a class="h-anchor" href="#%e4%ba%ba%e7%94%9f%e7%ac%ac%e4%b8%80%e7%af%87%e9%83%a8%e8%90%bd%e6%a0%bc%e6%95%99%e5%ad%b8%e5%88%b0%e9%80%99%e8%a3%a1%e7%b5%90%e6%9d%9f%e5%95%a6%e5%b8%8c%e6%9c%9b%e5%a4%a7%e5%ae%b6%e9%83%bd%e6%9c%89%e9%80%8f%e9%81%8e%e9%80%99%e4%ba%9b%e5%b7%a5%e5%85%b7%e7%9a%84%e7%b5%84%e5%90%88%e8%b9%a6%e5%87%ba%e6%96%b0%e7%9a%84%e7%81%ab%e8%8a%b1%e5%96%94" aria-label="這個段落的連結"></a></h2>
<p>參考資源：<a href="https://developers.google.com/apps-script/reference/forms">Google App Script (From Service)</a> , <a href="http://white5168.blogspot.com/2018/04/google-apps-script-19-google-line-notify_24.html#.Xtcm-lMzbzI">Google 表單與 Line Notify 結合應用</a></p>
]]></content:encoded>
    </item>
  </channel>
</rss>
