{"id":1374,"date":"2022-06-11T21:23:00","date_gmt":"2022-06-11T13:23:00","guid":{"rendered":"http:\/\/hower.forwebs.net\/robot\/?p=1374"},"modified":"2022-06-13T10:30:41","modified_gmt":"2022-06-13T02:30:41","slug":"%e4%b8%8b%e6%9c%9f%e7%ac%ac14%e5%a0%82%e9%9b%b2%e7%ab%af%e6%9c%8d%e5%8b%99%e6%a9%9f%e5%99%a8%e4%ba%ba-line%e6%a9%9f%e5%99%a8%e4%ba%ba-%e8%b3%87%e6%96%99%e8%92%90%e9%9b%86","status":"publish","type":"post","link":"https:\/\/hower.forwebs.net\/robot\/archives\/1374","title":{"rendered":"\u4e0b\u671f\u7b2c15\u5802[\u96f2\u7aef\u670d\u52d9\u6a5f\u5668\u4eba] Line\u6a5f\u5668\u4eba-\u5beb\u5165\u8cc7\u6599"},"content":{"rendered":"\n<hr class=\"wp-block-separator\"\/>\n\n\n\n<p>\u4eca\u5929\u4ecb\u7d39 \u5c07Line\u6a5f\u5668\u4eba\u63a5\u6536\u5230\u7684\u8a0a\u606f\uff0c\u63d2\u5165\u8cc7\u6599\u8868\u4e2d\u3002<\/p>\n\n\n\n<p> \u4eca\u5929\u4f7f\u7528\u7684\u5de5\u5177\u662fGoogle sheets\uff0c \u6bd4\u8d77\u6b63\u898f\u8cc7\u6599\u5eab\uff0c\u5efa\u7f6e\u8d77\u4f86\u5feb\u901f\u65b9\u4fbf\uff0c<\/p>\n\n\n\n<p> \u7576\u7136\u9019\u9069\u5408\u5c0f\u578b\u7684\u8cc7\u6599\uff0c\u5927\u6982\u5e7e\u5343\u7b46\u4e4b\u5167\u8f03\u9069\u5408\u3002<\/p>\n\n\n\n<figure class=\"wp-block-embed is-type-video is-provider-youtube wp-block-embed-youtube wp-embed-aspect-16-9 wp-has-aspect-ratio\"><div class=\"wp-block-embed__wrapper\">\n<div class=\"video-container\"><iframe loading=\"lazy\" title=\"Line\u6a5f\u5668\u4eba\u63d2\u5165 google sheets \u8cc7\u6599\u5eab\" width=\"500\" height=\"281\" src=\"https:\/\/www.youtube.com\/embed\/logHk3U4LYQ?feature=oembed&#038;wmode=opaque\" frameborder=\"0\" allow=\"accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture\" allowfullscreen><\/iframe><\/div>\n<\/div><\/figure>\n\n\n\n<hr class=\"wp-block-separator\"\/>\n\n\n\n<p>\u7a0b\u5f0f\u78bc<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>function doPost(e) {\n    \/\/ LINE Messenging API Token\nvar CHANNEL_ACCESS_TOKEN = '......................';\n    \/\/ \u4ee5 JSON \u683c\u5f0f\u89e3\u6790 User \u7aef\u50b3\u4f86\u7684 e \u8cc7\u6599\n    var msg = JSON.parse(e.postData.contents);\n\nconst replyToken = msg.events&#91;0].replyToken;\nconst userMessage = msg.events&#91;0].message.text; \/\/ \u4f7f\u7528\u8005\u50b3\u7684\u8a0a\u606f\u5167\u5bb9\nconst user_id = msg.events&#91;0].source.userId;    \/\/ \u6293\u53d6\u4f7f\u7528\u8005\u7684 ID\nconst event_type = msg.events&#91;0].source.type;   \/\/ \u5206\u8fa8\u662f\u500b\u4eba\u804a\u5929\u5ba4\u9084\u662f\u7fa4\u7d44\n\nconst sheet_url = '......................';   \/\/ \u7db2\u5740\nconst sheet_name = '....................................'; \/\/ \u5de5\u4f5c\u8868\u540d\u7a31\nconst SpreadSheet = SpreadsheetApp.openByUrl(sheet_url);\nconst reserve_list = SpreadSheet.getSheetByName(sheet_name); \n\nvar current_list_row = reserve_list.getLastRow(); \/\/ \u53d6\u5f97\u5de5\u4f5c\u8868\u6700\u5f8c\u4e00\u6b04\nvar reply_message = &#91;]; \/\/ \u7a7a\u767d\u56de\u8986\u8a0a\u606f\u9663\u5217\uff0c\u5f8c\u671f\u6703\u52a0\u5165 JSON\n\n    \/\/ \u67e5\u8a62\u50b3\u8a0a\u8005\u7684 LINE \u5e33\u865f\u540d\u7a31\n    function get_user_name() {\n        \/\/ \u5224\u65b7\u70ba\u7fa4\u7d44\u6210\u54e1\u9084\u662f\u55ae\u4e00\u4f7f\u7528\u8005\n        switch (event_type) {\n            case \"user\":\n                var nameurl = \"https:\/\/api.line.me\/v2\/bot\/profile\/\" + user_id;\n                break;\n            case \"group\":\n                var groupid = msg.events&#91;0].source.groupId;\n                var nameurl = \"https:\/\/api.line.me\/v2\/bot\/group\/\" + groupid + \"\/member\/\" + user_id;\n                break;\n        }\n\n        try {\n            \/\/  \u547c\u53eb LINE User Info API\uff0c\u4ee5 user ID \u53d6\u5f97\u8a72\u5e33\u865f\u7684\u4f7f\u7528\u8005\u540d\u7a31\n            var response = UrlFetchApp.fetch(nameurl, {\n                \"method\": \"GET\",\n                \"headers\": {\n                    \"Authorization\": \"Bearer \" + CHANNEL_ACCESS_TOKEN,\n                    \"Content-Type\": \"application\/json\"\n                },\n            });\n            var namedata = JSON.parse(response);\n            var reserve_name = namedata.displayName;\n        }\n        catch {\n            reserve_name = \"not avaliable\";\n        }\n        return String(reserve_name)\n    }\n\n    \/\/\u5b9a\u7fa9 \u56de\u50b3\u8a0a\u606f\u51fd\u6578\n    function send_to_line() {\n        var url = 'https:\/\/api.line.me\/v2\/bot\/message\/reply';\n        UrlFetchApp.fetch(url, {\n            'headers': {\n                'Content-Type': 'application\/json; charset=UTF-8',\n                'Authorization': 'Bearer ' + CHANNEL_ACCESS_TOKEN,\n            },\n            'method': 'post',\n            'payload': JSON.stringify({\n                'replyToken': replyToken,\n                'messages': reply_message,\n            }),\n        });\n    }\n\n    \/\/ \u5c07\u8f38\u5165\u503c word \u8f49\u70ba LINE \u6587\u5b57\u8a0a\u606f\u683c\u5f0f\u4e4b JSON\n    function format_text_message(word) {\n        let text_json = &#91;{\n            \"type\": \"text\",\n            \"text\": word\n        }]\n\n        return text_json;\n    }\n\n    \nvar reserve_name = get_user_name();\n\nif (typeof replyToken === 'undefined') {\n    return;\n};\n\n\nif (userMessage == \"\u986f\u793a\" | userMessage == \"\u6e05\u55ae\") {\n    var list=\"\u5168\u90e8\u8cc7\u6599\";\n    for (var x = 1; x &lt;= current_list_row; x++) {\n      list = list + \"\\n\" + reserve_list.getRange(x, 1).getValue();\n    }\n    reply_message = &#91;{\n        \"type\": \"text\",\n        \"text\": \"\u5171\u6709 \" + current_list_row + \"\u7b46\u6e05\u55ae\"\n      },{\n        \"type\": \"text\",\n        \"text\": list\n      }]\n    send_to_line();\n\n}else{\n\u3000var Today=new Date();\n  reserve_list.getRange(current_list_row + 1, 1).setValue(reserve_name);\n  reserve_list.getRange(current_list_row + 1, 2).setValue(userMessage);\n  current_list_row = reserve_list.getLastRow();\n        \n  \/\/ \u56de\u50b3\u6210\u529f\u8a0a\u606f\n  reply_message = &#91;{\n    \"type\": \"text\",\n    \"text\": reserve_name + \"\u63d2\u5165\u8cc7\u6599\" \n        }]\n  send_to_line();\n}\n\n\n\n\n\n\n}\n<\/code><\/pre>\n\n\n\n<hr class=\"wp-block-separator\"\/>\n\n\n\n<p class=\"has-pale-cyan-blue-background-color has-background\">\u4eca\u65e5\u6311\u6230<\/p>\n\n\n\n<p>\u4e0a\u7db2\u641c\u5c0b java script\u8a9e\u6cd5\uff0c\u5728\u7b2c\u4e09\u6b04\u52a0\u4e0a\u7576\u6642\u6642\u9593<\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><img decoding=\"async\" loading=\"lazy\" width=\"961\" height=\"553\" src=\"http:\/\/hower.forwebs.net\/robot\/wp-content\/uploads\/sites\/2\/2022\/06\/image.png\" alt=\"\" class=\"wp-image-1382\" srcset=\"https:\/\/hower.forwebs.net\/robot\/wp-content\/uploads\/sites\/2\/2022\/06\/image.png 961w, https:\/\/hower.forwebs.net\/robot\/wp-content\/uploads\/sites\/2\/2022\/06\/image-300x173.png 300w, https:\/\/hower.forwebs.net\/robot\/wp-content\/uploads\/sites\/2\/2022\/06\/image-768x442.png 768w\" sizes=\"(max-width: 961px) 100vw, 961px\" \/><figcaption>\u5728\u7bad\u982d\u7684\u5730\u65b9\u63d2\u5165\u65b0\u4e00\u884c<\/figcaption><\/figure>\n\n\n\n<figure class=\"wp-duotone-000000-00a5ff-1 wp-block-image size-large\"><img decoding=\"async\" loading=\"lazy\" width=\"1024\" height=\"522\" src=\"http:\/\/hower.forwebs.net\/robot\/wp-content\/uploads\/sites\/2\/2022\/06\/\u622a\u5716-2022-06-13-\u4e0a\u53489.25.17-1024x522.png\" alt=\"\" class=\"wp-image-1390\" srcset=\"https:\/\/hower.forwebs.net\/robot\/wp-content\/uploads\/sites\/2\/2022\/06\/\u622a\u5716-2022-06-13-\u4e0a\u53489.25.17-1024x522.png 1024w, https:\/\/hower.forwebs.net\/robot\/wp-content\/uploads\/sites\/2\/2022\/06\/\u622a\u5716-2022-06-13-\u4e0a\u53489.25.17-300x153.png 300w, https:\/\/hower.forwebs.net\/robot\/wp-content\/uploads\/sites\/2\/2022\/06\/\u622a\u5716-2022-06-13-\u4e0a\u53489.25.17-768x392.png 768w, https:\/\/hower.forwebs.net\/robot\/wp-content\/uploads\/sites\/2\/2022\/06\/\u622a\u5716-2022-06-13-\u4e0a\u53489.25.17.png 1506w\" sizes=\"(max-width: 1024px) 100vw, 1024px\" \/><\/figure>\n\n\n\n<p>\u5c0f\u6311\u6230\u53c3\u8003\u7b54\u6848<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>reserve_list.getRange(current_list_row + 1, 3).setValue((Today.getMonth()+1)+\"\u6708\"+Today.getDate()+\"\u65e5\");\n<\/code><\/pre>\n\n\n\n<hr class=\"wp-block-separator\"\/>\n\n\n\n<p class=\"has-light-green-cyan-background-color has-background\"> \u601d\u8003\u8207\u767c\u5c55<\/p>\n\n\n\n<p> \u4eca\u5929\u7684\u7a0b\u5f0f\u53ea\u662f\u4e00\u500b\u793a\u7bc4\uff0c\u4ed6\u6703\u628a\u6c92\u6709\u95dc\u9375\u5b57\u7684\u5c0d\u8a71\u5168\u90e8\u6284\u9304\u8d77\u4f86\u3002<\/p>\n\n\n\n<p>\u540c\u5b78\u7576\u7136\u53ef\u4ee5\u6539\u6210\u6709\u95dc\u9375\u5b57\u624d\u7d00\u9304\uff0c\u4f8b\u5982\u53e5\u5b50\u88e1\u9762\u6709\u201c\u8acb\u8a18\u9304\u201d\uff0c<\/p>\n\n\n\n<p>\u624d\u628a\u9019\u4e00\u500b\u5c0d\u8a71\u63d2\u5230\u8cc7\u6599\u5eab\u88e1\u9762<\/p>\n\n\n\n<hr class=\"wp-block-separator\"\/>\n\n\n\n<p class=\"has-pale-pink-background-color has-background\"> \u5c0f\u53ee\u5680<\/p>\n\n\n\n<p>\u5b78\u671f\u5df2\u7d93\u63a5\u8fd1\u5c3e\u8072\uff0c\u540c\u5b78\u53ef\u4ee5\u958b\u59cb\u88fd\u4f5c\u671f\u672b\u6210\u679c\u4e86\u3002<\/p>\n\n\n\n<p><\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u4eca\u5929\u4ecb\u7d39 \u5c07Line\u6a5f\u5668\u4eba\u63a5\u6536\u5230\u7684\u8a0a\u606f\uff0c\u63d2\u5165\u8cc7\u6599\u8868\u4e2d\u3002 \u4eca\u5929\u4f7f\u7528\u7684\u5de5&#46;&#46;&#46;<\/p>\n","protected":false},"author":1,"featured_media":1384,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[2],"tags":[],"_links":{"self":[{"href":"https:\/\/hower.forwebs.net\/robot\/wp-json\/wp\/v2\/posts\/1374"}],"collection":[{"href":"https:\/\/hower.forwebs.net\/robot\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/hower.forwebs.net\/robot\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/hower.forwebs.net\/robot\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/hower.forwebs.net\/robot\/wp-json\/wp\/v2\/comments?post=1374"}],"version-history":[{"count":14,"href":"https:\/\/hower.forwebs.net\/robot\/wp-json\/wp\/v2\/posts\/1374\/revisions"}],"predecessor-version":[{"id":1398,"href":"https:\/\/hower.forwebs.net\/robot\/wp-json\/wp\/v2\/posts\/1374\/revisions\/1398"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/hower.forwebs.net\/robot\/wp-json\/wp\/v2\/media\/1384"}],"wp:attachment":[{"href":"https:\/\/hower.forwebs.net\/robot\/wp-json\/wp\/v2\/media?parent=1374"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/hower.forwebs.net\/robot\/wp-json\/wp\/v2\/categories?post=1374"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/hower.forwebs.net\/robot\/wp-json\/wp\/v2\/tags?post=1374"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}