星期五, 11月 20, 2026

[Line] Flex Message - 輪播卡

多張 Flex Message 卡片 (bubble) 可以設定為輪播卡 (carousel),使用者在手機 Line 上左右滑動瀏覽每張卡片,非常適合做「商品目錄」、「功能選單」或「教學章節導覽」,該筆記是「教學章節導覽」為主,把之前三篇文章摘要並整理為輪播卡

輪播卡限制
  • 最多只能包含 12 張卡片
  • 整個輪播訊息的資料大小不能超過 50KB
  • 每張卡片寬度都會是一樣的
  • 每張高度會自動保持一致,系統會以最高的卡片為基準,將所有卡片的 body 都對齊到相同高度,該卡片沒有 body 的話則不受影響
官方卡片高度說明
The body of each bubble will stretch to match the tallest bubble in the carousel. However, bubbles with no body will not change height.

code.gs
function getCarouselCard() {
  return {
    type: 'carousel',
    contents: [
      // 第 1 張卡片:對應 [Line] Flex Message - Hello World
      {
        type: 'bubble',
        size: 'kilo',
        header: {
          type: 'box',
          layout: 'vertical',
          contents: [
            {
              type: 'text',
              text: 'STEP 01|2026/11/03',
              color: '#DCFCE7',
              size: 'xs',
              weight: 'bold'
            },
            {
              type: 'text',
              text: 'Hello World 基礎卡片',
              color: '#FFFFFF',
              size: 'lg',
              weight: 'bold',
              wrap: true
            }
          ]
        },
        body: {
          type: 'box',
          layout: 'vertical',
          spacing: 'sm',
          contents: [
            {
              type: 'text',
              text: '文章重點:',
              weight: 'bold',
              size: 'sm',
              color: '#1E293B'
            },
            {
              type: 'text',
              text: '• 透過 GAS 串接 Push API 主動推播\n• payload 指定 type: flex 與 altText\n• 認識 bubble 單卡與 body 基礎區塊\n• vertical 垂直容器與文字 wrap 設定',
              size: 'xs',
              color: '#475569',
              wrap: true,
              lineSpacing: '4px'
            }
          ]
        },
        footer: {
          type: 'box',
          layout: 'vertical',
          contents: [
            {
              type: 'button',
              style: 'primary',
              height: 'sm',
              color: '#16A34A',
              action: {
                type: 'uri',
                label: '閱讀文章',
                uri: 'https://jengting.blogspot.com/2026/11/Hello-Flex-Message.html'
              }
            }
          ]
        },
        styles: {
          header: {
            backgroundColor: '#16A34A'
          }
        }
      },
      // 第 2 張卡片:對應 [Line] Flex Message - 排版容器應用
      {
        type: 'bubble',
        size: 'kilo',
        header: {
          type: 'box',
          layout: 'vertical',
          contents: [
            {
              type: 'text',
              text: 'STEP 02|2026/11/07',
              color: '#DBEAFE',
              size: 'xs',
              weight: 'bold'
            },
            {
              type: 'text',
              text: '排版容器應用(雙欄)',
              color: '#FFFFFF',
              size: 'lg',
              weight: 'bold',
              wrap: true
            }
          ]
        },
        body: {
          type: 'box',
          layout: 'vertical',
          spacing: 'sm',
          contents: [
            {
              type: 'text',
              text: '文章重點:',
              weight: 'bold',
              size: 'sm',
              color: '#1E293B'
            },
            {
              type: 'text',
              text: '• 垂直與水平巢狀容器製作雙欄明細\n• flex 屬性控制左右欄位空間比例\n• header 標題列與 separator 分隔線\n• align 對齊技巧製作活動入場憑證',
              size: 'xs',
              color: '#475569',
              wrap: true,
              lineSpacing: '4px'
            }
          ]
        },
        footer: {
          type: 'box',
          layout: 'vertical',
          contents: [
            {
              type: 'button',
              style: 'primary',
              height: 'sm',
              color: '#2563EB',
              action: {
                type: 'uri',
                label: '閱讀文章',
                uri: 'https://jengting.blogspot.com/2026/11/Flex-Message-Layout.html'
              }
            }
          ]
        },
        styles: {
          header: {
            backgroundColor: '#2563EB'
          }
        }
      },
      // 第 3 張卡片:對應 [Line] Flex Message - 圖文與按鈕
      {
        type: 'bubble',
        size: 'kilo',
        header: {
          type: 'box',
          layout: 'vertical',
          contents: [
            {
              type: 'text',
              text: 'STEP 03|2026/11/14',
              color: '#FEF3C7',
              size: 'xs',
              weight: 'bold'
            },
            {
              type: 'text',
              text: '圖文與按鈕互動',
              color: '#FFFFFF',
              size: 'lg',
              weight: 'bold',
              wrap: true
            }
          ]
        },
        body: {
          type: 'box',
          layout: 'vertical',
          spacing: 'sm',
          contents: [
            {
              type: 'text',
              text: '文章重點:',
              weight: 'bold',
              size: 'sm',
              color: '#1E293B'
            },
            {
              type: 'text',
              text: '• hero 滿版主視覺與 aspectRatio 設定\n• baseline 基準線對齊星星評分圖示\n• footer 按鈕樣式(primary/secondary)\n• uri 開啟網頁與 message 關鍵字觸發',
              size: 'xs',
              color: '#475569',
              wrap: true,
              lineSpacing: '4px'
            }
          ]
        },
        footer: {
          type: 'box',
          layout: 'vertical',
          contents: [
            {
              type: 'button',
              style: 'primary',
              height: 'sm',
              color: '#D97706',
              action: {
                type: 'uri',
                label: '閱讀文章',
                uri: 'https://jengting.blogspot.com/2026/11/Flex-Message-Image.html'
              }
            }
          ]
        },
        styles: {
          header: {
            backgroundColor: '#D97706'
          }
        }
      }
    ]
  };
}

星期三, 11月 18, 2026

[Zoom] 音訊增強

透過 Zoom 分享聲音時發現,平常播的音樂透過 Zoom 分享後,整個音質下降很多且聽起來就是有種糊糊的感覺還伴隨著隨機破音,後來發現 Lenovo ThinkPad 筆電內 Windows 11 有 [音訊增強] 設定,把它關閉後過 Zoom 分享聲音就正常了

星期六, 11月 14, 2026

[Line] Flex Message - 圖文與按鈕

該筆記重點
  • hero 區塊:放置滿版主視覺圖片
  • layout-baseline:專門用來把小圖示 (icon) 與文字 (text) 沿著文字底部基準線對齊,該範例內容是應用在星級評分
  • footer 區塊 + button 控件
    • action.type-uri:點擊後直接開啟外部網頁
Flex Message json 和發出效果
function getCafeCard() {
  return {
    "type": "bubble",
    "size": "mega",
    "hero": {
      "type": "image",
      "url": "https://images.unsplash.com/photo-1501339847302-ac426a4a7cbb?auto=format&fit=crop&w=1000&q=80",
      "size": "full",
      "aspectRatio": "20:13",
      "aspectMode": "cover"
    },
    "body": {
      "type": "box",
      "layout": "vertical",
      "spacing": "sm",
      "contents": [
        {
          "type": "text",
          "text": " 圖文與按鈕",
          "weight": "bold",
          "color": "#D97706",
          "size": "xs"
        },
        {
          "type": "text",
          "text": "楓花雪岳 Kaffe",
          "weight": "bold",
          "size": "xl",
          "color": "#1E293B",
          "wrap": true
        },
        {
          "type": "box",
          "layout": "baseline",
          "margin": "md",
          "contents": [
            {
              "type": "icon",
              "size": "sm",
              "url": "https://scdn.line-apps.com/n/channel_devcenter/img/fx/review_gold_star_28.png"
            },
            {
              "type": "icon",
              "size": "sm",
              "url": "https://scdn.line-apps.com/n/channel_devcenter/img/fx/review_gold_star_28.png"
            },
            {
              "type": "icon",
              "size": "sm",
              "url": "https://scdn.line-apps.com/n/channel_devcenter/img/fx/review_gold_star_28.png"
            },
            {
              "type": "icon",
              "size": "sm",
              "url": "https://scdn.line-apps.com/n/channel_devcenter/img/fx/review_gold_star_28.png"
            },
            {
              "type": "icon",
              "size": "sm",
              "url": "https://scdn.line-apps.com/n/channel_devcenter/img/fx/review_gold_star_28.png"
            },
            {
              "type": "text",
              "text": "4.9 (128 則評論)",
              "size": "sm",
              "color": "#64748B",
              "margin": "md",
              "flex": 0
            }
          ]
        },
        {
          "type": "box",
          "layout": "vertical",
          "margin": "lg",
          "spacing": "sm",
          "contents": [
            {
              "type": "box",
              "layout": "horizontal",
              "spacing": "sm",
              "contents": [
                {
                  "type": "text",
                  "text": "招牌推薦",
                  "color": "#94A3B8",
                  "size": "sm",
                  "flex": 2
                },
                {
                  "type": "text",
                  "text": "衣索比亞 紫風鈴 ($200)",
                  "wrap": true,
                  "color": "#334155",
                  "size": "sm",
                  "flex": 5
                }
              ]
            },
            {
              "type": "box",
              "layout": "horizontal",
              "spacing": "sm",
              "contents": [
                {
                  "type": "text",
                  "text": "營業時間",
                  "color": "#94A3B8",
                  "size": "sm",
                  "flex": 2
                },
                {
                  "type": "text",
                  "text": "每日10:00 營業(週一公休)",
                  "wrap": true,
                  "color": "#334155",
                  "size": "sm",
                  "flex": 5
                }
              ]
            }
          ]
        }
      ]
    },
    "footer": {
      "type": "box",
      "layout": "vertical",
      "spacing": "sm",
      "flex": 0,
      "contents": [
        {
          "type": "button",
          "style": "primary",
          "height": "sm",
          "color": "#D97706",
          "action": {
            "type": "uri",
            "label": "楓花雪岳官網",
            "uri": "https://jengting.blogspot.com/"
          }
        }
      ]
    }
  };
}
Image
  • Size:有三種設定方式,分別為尺寸關鍵字、像素、百分比,預設值為尺寸 md
  • aspectRatio:設定圖片顯示區域的寬高比,寬與高的數值範圍為 1-100,000,且高不能超過寬的 3 倍,未設定預設為 1:1
  • aspectMode:設定圖片如何填入顯示區域,當原始圖片比例與 aspectRatio 不一致時,就由這個屬性決定顯示方式
    • cover:照片放大到填滿寬度,上下部分會被裁掉
    • fit:整張照片完整顯示,左右會留下空間
layout-baseline

官方文件 示意圖,直接看圖理解囉
Button

style
  • primary:適合深色底的主要按鈕
  • secondary:適合淺色底的次要按鈕
  • link:文字連結樣式,也是預設值
action 屬性
  •  uri:開啟指定網址
  • message:點擊後讓使用者在聊天室送出指定文字,可以應用在觸發關鍵字回覆 (可觸發 Webhook 回應)

星期六, 11月 07, 2026

[Line] Flex Message - 排版容器應用

該筆記練習使用垂直、水平排版容器,來製作雙欄明細資訊

Flex Message json 和發出效果
function getMultiColumnJson() {
  return {
    "type": "bubble",
    "size": "mega",
    "header": {
      "type": "box",
      "layout": "vertical",
      "contents": [
        {
          "type": "text",
          "text": "雙欄明細資訊",
          "color": "#BFDBFE",
          "size": "xs",
          "weight": "bold"
        },
        {
          "type": "text",
          "text": "實戰工作坊入場憑證",
          "color": "#FFFFFF",
          "size": "lg",
          "weight": "bold",
          "margin": "xs"
        }
      ]
    },
    "body": {
      "type": "box",
      "layout": "vertical",
      "spacing": "md",
      "contents": [
        {
          "type": "text",
          "text": "LineBot × GAS 自動化實戰班",
          "weight": "bold",
          "size": "md",
          "color": "#0F172A",
          "wrap": true
        },
        {
          "type": "separator",
          "margin": "md",
          "color": "#E2E8F0"
        },
        {
          "type": "box",
          "layout": "vertical",
          "margin": "md",
          "spacing": "sm",
          "contents": [
            {
              "type": "box",
              "layout": "horizontal",
              "contents": [
                {
                  "type": "text",
                  "text": "活動日期",
                  "size": "sm",
                  "color": "#64748B",
                  "flex": 1
                },
                {
                  "type": "text",
                  "text": "2026/11/15 (日) 14:00",
                  "size": "sm",
                  "color": "#1E293B",
                  "weight": "bold",
                  "flex": 2,
                  "align": "end"
                }
              ]
            },
            {
              "type": "box",
              "layout": "horizontal",
              "contents": [
                {
                  "type": "text",
                  "text": "上課地點",
                  "size": "sm",
                  "color": "#64748B",
                  "flex": 1
                },
                {
                  "type": "text",
                  "text": "台北市 OO 區 XX 路 ZZ 號",
                  "size": "sm",
                  "color": "#1E293B",
                  "flex": 2,
                  "align": "end",
                  "wrap": true
                }
              ]
            },
            {
              "type": "box",
              "layout": "horizontal",
              "contents": [
                {
                  "type": "text",
                  "text": "報到序號",
                  "size": "sm",
                  "color": "#64748B",
                  "flex": 1
                },
                {
                  "type": "text",
                  "text": "#GAS-888",
                  "size": "sm",
                  "color": "#2563EB",
                  "weight": "bold",
                  "flex": 2,
                  "align": "end"
                }
              ]
            }
          ]
        },
        {
          "type": "separator",
          "margin": "md",
          "color": "#E2E8F0"
        },
        {
          "type": "text",
          "text": "排版技巧:利用垂直排版容器搭配水平排版容器,即可做出對齊資訊欄位",
          "size": "xs",
          "color": "#94A3B8",
          "wrap": true,
          "margin": "md"
        }
      ]
    },
    "styles": {
      "header": {
        "backgroundColor": "#7C3AED"
      }
    }
  }
}

巢狀容器

在垂直排版容器 (下圖綠色框) 內放入多個水平排版容器 (下圖黃色框),水平排版容器內放置文字標籤,藉此來顯示雙欄位文字資訊

屬性 flex

flex 則是決定水平排版容器內的文字標籤佔整個水平空間比例,以該例子來說,左側文字標籤設定 flex: 1 、右側文字標籤設定 flex: 2,所以水平空間總比例為 3 ,左側文字標籤代表佔 1/3、右側文字標籤代表佔 2/3

星期二, 11月 03, 2026

[Line] Flex Message - Hello World

在 [Line] Flex Message - 模擬器 取得 Flex Message json 內容搭配 [GAS] LineBot 傳送訊息,使用 push API 主動發出 Flex Message 發給使用者
function testSendFlexMessageFromGAS() {
  const userId = getUserID();
  const card = SendFlexMessageFromGAS();
  pushFlexMessage(userId, 'altText:Hello Flex Message From GAS', card);
}

function SendFlexMessageFromGAS() {
  return {
    "type": "bubble",
    "body": {
      "type": "box",
      "layout": "vertical",
      "contents": [
        {
          "type": "text",
          "text": "Flex Message Sample",
          "weight": "bold",
          "color": "#1DB446",
          "size": "xs"
        },
        {
          "type": "text",
          "text": "Hello Flex Message",
          "weight": "bold",
          "size": "xl",
          "color": "#1E293B"
        },
        {
          "type": "text",
          "text": "從 Google Apps Script 發出的第一張 Flex Message,這張卡片只用了最基礎的 body 區塊與 vertical 垂直排列容器",
          "size": "sm",
          "color": "#64748B",
          "wrap": true,
          "lineSpacing": "4px"
        }
      ]
    }
  }
}

function pushFlexMessage(to, altText, flexContents) {

  const channelAccessToken = getchannelAccessToken();

  const payload = {
    to,
    messages: [
      {
        type: 'flex',
        altText,
        contents: flexContents
      }
    ]
  };

  const options = {
    method: 'post',
    contentType: 'application/json',
    headers: {
      Authorization: `Bearer ${channelAccessToken}`
    },
    payload: JSON.stringify(payload),
    muteHttpExceptions: true
  };

  const lineUrl = "https://api.line.me/v2/bot/message/push";
  const response = UrlFetchApp.fetch(lineUrl, options);
  const statusCode = response.getResponseCode();
  const responseText = response.getContentText();

  if (statusCode === 200) {
    Logger.log(`Flex Message 推播成功!"${altText}"`);
    return JSON.parse(responseText || '{}');
  }

  throw new Error(`LINE Push API 發送失敗 (HTTP ${statusCode}):${responseText}`);
}

function getchannelAccessToken() {
  const scriptProperties = PropertiesService.getScriptProperties();
  const rawToken = scriptProperties.getProperty('CHANNEL_ACCESS_TOKEN') || '';

  // 自動去除前後空白、換行或誤加的雙引號/單引號
  const channelAccessToken = rawToken.trim().replace(/^["']+|["']+$/g, '');

  if (!channelAccessToken) {
    throw new Error(
      '尚未設定指令碼屬性 (Script Properties) 內的 CHANNEL_ACCESS_TOKEN'
    );
  }

  return channelAccessToken;
}

function getUserID() {
  const scriptProperties = PropertiesService.getScriptProperties();
  const rawUserId = scriptProperties.getProperty('USER_ID') || '';

  // 自動去除前後空白、換行或誤加的雙引號/單引號
  const userId = rawUserId.trim().replace(/^["']+|["']+$/g, '');

  if (!userId) {
    throw new Error(
      '尚未設定指令碼屬性 (Script Properties) 內的 USER_ID'
    );
  }

  return userId;
}
payload 內的 Message 有兩個重點
  • type 要指定為 flex
  • altText 即為通知訊息,故意在文字前面打個 altText 來辨識
Flex Message josn 有修改部分文字,方便辨識是從 GAS 發出