AI LINE Bot練功坊-L8 Message Type (2) Template Message
Template Message
匯入函式庫
Action objects
匯入函式庫
Template Message、Flex Message都可以使用到messagingAPI裡的Action objects。
Action objects是當使用者點擊訊息中的按鈕或影像時機器人會執行的操作類型,共有以下幾種Type:
- Postback action : 回傳指定給伺服器的內容
- Message action : 讓使用者傳出指定訊息
- URI action連結 : 讓使用者連結指定網址
- Datetime picker action : 讓使用者選擇時間日期
- Camera action : 讓使用者開啟相機
- Camera roll action : 讓使用者開啟相簿
- Location action位置 : 讓使用者開啟地圖
使用範例_程式碼
Reference:https://developers.line.biz/en/reference/messaging-api/#action-objects
Template types
Template message 是一個事先模板化的訊息,我們只需要透過調整各項參數來製作客製化的訊息。
跟 Flex message 有類似的功能,但是Template message只能在手機上查看訊息,在電腦版只會看到一串文字。
總共有四種類型的樣式可以選擇,分別為 Buttons、Confirm、Carousel、ImageCarousel。
1. Buttons Template
2. Confirm Template
3. Carousel Template
4. ImageCarousel Template
1. Confirm Template
簡短提問的訊息模板,會提供最多兩個按鈕供使用者點選。
只能有兩個 action,通常用來用在使用者只有兩個選擇的時候。
Image Not Showing
Possible Reasons
- The image was uploaded to a note which you don't have access to
- The note which the image was originally uploaded to has been deleted
Learn More →
text 樣板說明文字。
actions 點擊按鈕觸發的行為,一個按鈕一種行為,最多支援兩個按鈕。
程式碼:
Reference:https://developers.line.biz/en/docs/messaging-api/message-types/#confirm-template
是一種包含按鈕的訊息,提供 最多4個 按鈕供使用者點選
Image Not Showing
Possible Reasons
- The image was uploaded to a note which you don't have access to
- The note which the image was originally uploaded to has been deleted
Learn More →
thumbnailImageUrl 縮圖連結,支援 jpg 和 png,最大寬度 1024px。
title 樣板標題。
text 樣板說明文字。
actions 點擊按鈕觸發的行為,一個按鈕一種行為,最多支援四個按鈕。
這裡使用三種action type 分別是 uri、postback、message,可以根據需要的功能去設定按鈕動作。
uri 是使用者按下後會導入 web連結。
postback 在使用者按下的時候可以用 event postback 接收這個資訊來做後續處理。
message 是使用者按下去會自動變成輸入文字模式,而 label 通常與 text 設定一樣就可以了。
程式碼:
Reference:https://developers.line.biz/en/docs/messaging-api/message-types/#buttons-template
3. Carousel Template
是一種多個 Buttons template 的集合,如果要做一個左右滑的 Buttons template 就可以用 Carousel template。
最多有五個區塊,每個區塊內最多三個 action,這些區塊會呈橫向排列,並可以滑動。
Image Not Showing
Possible Reasons
- The image was uploaded to a note which you don't have access to
- The note which the image was originally uploaded to has been deleted
Learn More →
columns 要出現的按鈕樣板,使用串列格式。
thumbnailImageUrl 縮圖連結,支援 jpg 和 png,最大寬度 1024px。
title 樣板標題。
text 樣板說明文字。
actions 點擊按鈕觸發的行為,一個按鈕一種行為,最多支援四個按鈕。
有三種action type 分別是 uri、postback、message,可以根據需要的功能去設定按鈕動作。
uri 是使用者按下後會導入 web連結。
postback 在使用者按下的時候可以用 event postback 接收這個資訊來做後續處理。
message 是使用者按下去會自動變成輸入文字模式,而 label 通常與 text 設定一樣就可以了。
程式碼:
Reference:https://developers.line.biz/en/docs/messaging-api/message-types/#carousel-template
4. ImageCarousel Template
會提供最多十張可以滑動選擇的圖片,作為按鈕供使用者點選。
和 Carousel template 相似,不同的地方是每個區中沒有選項,而是顯示一張大圖
Image Not Showing
Possible Reasons
- The image was uploaded to a note which you don't have access to
- The note which the image was originally uploaded to has been deleted
Learn More →
columns 要出現的圖片樣板,使用串列格式。
image_Url 圖片網址,支援 jpg 和 png,最大寬度 1024px。
actions 點擊圖片所觸發的行為,一張圖片一種行為,最多支援十張圖片。
uri 點擊會連結的網址
程式碼:
Reference:https://developers.line.biz/en/docs/messaging-api/message-types/#image-carousel-template
Youtube 課程影片
關於我們
國立臺北教育大學 教育大數據微學程
Image Not Showing
Possible Reasons
- The image was uploaded to a note which you don't have access to
- The note which the image was originally uploaded to has been deleted
Learn More →
Facebook
Image Not Showing
Possible Reasons
- The image was uploaded to a note which you don't have access to
- The note which the image was originally uploaded to has been deleted
Learn More →
Instagram
Image Not Showing
Possible Reasons
- The image was uploaded to a note which you don't have access to
- The note which the image was originally uploaded to has been deleted
Learn More →
Threads
Image Not Showing
Possible Reasons
- The image was uploaded to a note which you don't have access to
- The note which the image was originally uploaded to has been deleted
Learn More →
YouTube
Image Not Showing
Possible Reasons
- The image was uploaded to a note which you don't have access to
- The note which the image was originally uploaded to has been deleted
Learn More →
Line官方帳號
相關教材連結