Skip to content

Instantly share code, notes, and snippets.

@chentingjuan
Last active September 29, 2022 18:34
Show Gist options
  • Save chentingjuan/8cb3a2adf74bb02f3c1a5fabe9f29785 to your computer and use it in GitHub Desktop.
Save chentingjuan/8cb3a2adf74bb02f3c1a5fabe9f29785 to your computer and use it in GitHub Desktop.
line messages
// 檢查是否為有內容的字串
const hasContent = (value) => {
let string = toString(value||'')
return string.trim()
}
// 最大字數限制,超過則在最後一個字數顯示 '⋯'
const trim = (str, maxLength) => {
let string = str||''
if(string.length > maxLength) {
return `${string.substring(0, maxLength - 1)}⋯`
}
return string
}
// information mapping
const locationName = {
'arts-center': '臺北表演藝術中心',
'night-market': '士林夜市',
'official-residence': '士林官邸公園',
'art-park': '臺北科學藝術園區',
}
const typeName = {
'visual': '視覺作品',
'show': '表演節目',
'event': '活動'
}
// generate text
// 使用 dayjs 做時間格式轉換
const text = ''
text += `${dayjs(data.startTime).format('HH:mm')}-${dayjs(data.endTime).format('HH:mm')}-${locationName[data.location_type]}/${typeName[data.type]}`
if(hasContent(data.tag)) text += `-${data.tag}`
if(hasContent(data.media)) text += `:${data.media}`
const message = {
"type": "template",
"altText": data.label,
"template": {
"type": "buttons",
"thumbnailImageUrl": data.cover_photo,
"imageAspectRatio": "rectangle",
"imageSize": "cover",
"imageBackgroundColor": "#000000",
"title": trim(data.title_zh, 40),
"text": trim(text, 60),
"defaultAction": {
"type": "uri",
"label": "⌖ 觀看作品介紹 ⌖",
"uri": `https://liff.line.me/${process.env.LIFF_ID}/artworks/${data.original_id}`
},
"actions": [
{
"type": "uri",
"label": "⌖ 觀看作品介紹 ⌖",
"uri": `https://liff.line.me/${process.env.LIFF_ID}/artworks/${data.original_id}`
},
{
"type": "uri",
"label": "⌖ 分享現場實況 ⌖",
"uri": `https://liff.line.me/${process.env.LIFF_ID}/artworks/${data.original_id}/?action=upload`
},
{
"type": "uri",
"label": "⌖ 解開RGB任務 ⌖",
"uri": `https://liff.line.me/${process.env.LIFF_ID}/artworks/${data.original_id}/?action=mission`
}
]
}
}
// liff.sendMessages([message])
// 10/01 00:00 後的歡迎訊息
[{
"type": "text",
"text": '📢 您好 這裡是晝夜站長廣播\n離慶典又更近一步了!\n\n不管身在何方,就是10/1晚上\n我們即將在士林相會。\n\n而我,將以最優雅的姿態\n親自迎接。'
}, {
"type": "text",
"text": '那一夜的行動代言了\n士林自古以來的RGB精神。\n\n日出時將浮現眾人的成果\n(自然少不了你的加入!)\n\n通往不眠之夜的車次已停靠,\n千萬不要錯過了🚈\n\n(若您在旅程中覺得受到太多干擾,提醒您可以隨時關閉提醒🔕)\n\n-\n\n2022 Nuit Blanche Taipei ☽\n10.1 SAT 6PM - 10.2 SUN 6AM\n@士林 SHILIN'
}]
// 10/01 17:00 後的歡迎訊息
[{
"type": "text",
"text": "您好,我是晝夜站長,\n將擔任您最親近的活動導覽員,\n每整點提供參考指引與迷航提醒。\n透過我的引導,您將在旅程中享有更多樂趣與知識。\n\n溫馨提醒:若您在旅程中覺得受到太多干擾,可以隨時關閉提醒🔕"
}, {
"type": "image",
"originalContentUrl": "https://s3.nuitblanche.taipei/app/uploads/2022/09/30012824/line_msg_ask_silent.png",
"previewImageUrl": "https://s3.nuitblanche.taipei/app/uploads/2022/09/30012824/line_msg_ask_silent.png"
}, {
"type": "text",
"text": "除了晝夜站長整點報時,如果您,即將前往白晝之夜實體活動現場,\n那麼,我也要告訴你,\n在這個神奇的夜晚,RGB化成67個任務,藏身在白晝之夜的藝術作品中。\n\n🔴🟢🔵\n\n若你願意,請現在打開手機,動動手指打開任務設定,\n(你離任務挑戰又更進一步了!)\n\n◕ 起初,你將收到任務推播,或可在藝術作品周遭,掃描任務QR code加入解謎。\n◕ 每完成一道題,參與者將可閱讀到對應的答案訊息和作品介紹。*切記,這將有助於之後的任務挑戰\n◕ 接續,你會得到此題的榮耀貼紙和積分。 *而這是屬於你個人的名譽軌跡\n◕ 請帶著它,繼續遊晃在白晝之夜現場。遇到RGB,也請不要猶豫,為我們破解每道任務。\n\n您將擁有到今年白晝之夜獨特體驗,\n跟著任務一起探險、遊玩、感受,\n跟著任務一起累積遊戲積分,積分將成為一件數位作品,\n在清晨6點,你能看見,\n集結所有人投注、所生成的眾願太陽緩緩升起。\n\n它流動、匯聚、它忍不住慶賀的光粒,正是士林RGB的能量具體。\n\n-\n2022 Nuit Blanche Taipei ☽\n10.1 SAT 6PM - 10.2 SUN 6AM\n@士林 SHILIN"
}, {
"type": "image",
"originalContentUrl": "https://s3.nuitblanche.taipei/app/uploads/2022/09/24224702/line_msg_beacon_hint.jpeg",
"previewImageUrl": "https://s3.nuitblanche.taipei/app/uploads/2022/09/24224702/line_msg_beacon_hint.jpeg"
}]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment