{"id":3869,"date":"2016-09-16T10:15:35","date_gmt":"2016-09-16T01:15:35","guid":{"rendered":"http:\/\/sitest.jp\/blog\/?p=3869"},"modified":"2016-09-16T10:14:51","modified_gmt":"2016-09-16T01:14:51","slug":"google-apps-script%e3%82%92%e4%bd%bf%e3%81%a3%e3%81%a6gmail%e3%81%ae%e6%96%b0%e7%9d%80%e3%83%a1%e3%83%bc%e3%83%ab%e3%82%92chatwork%e3%81%ab%e9%80%9a%e7%9f%a5%e3%81%97%e3%81%a6%e3%81%bf%e3%81%9f","status":"publish","type":"post","link":"https:\/\/sitest.jp\/blog\/?p=3869","title":{"rendered":"Google Apps Script\u3092\u4f7f\u3063\u3066Gmail\u306e\u65b0\u7740\u30e1\u30fc\u30eb\u3092ChatWork\u306b\u901a\u77e5\u3057\u3066\u307f\u305f"},"content":{"rendered":"<p>\u7686\u3055\u3093\u3001\u30b3\u30df\u30e5\u30cb\u30b1\u30fc\u30b7\u30e7\u30f3\u30c4\u30fc\u30eb\u306f\u3069\u306e\u3088\u3046\u306a\u30c4\u30fc\u30eb\u3092\u4f7f\u3063\u3066\u3044\u308b\u3067\u3057\u3087\u3046\u304b\u3002<br \/>\n\u5f0a\u793e\u3067\u306f\u30c1\u30e3\u30c3\u30c8\u30c4\u30fc\u30eb\u3068\u3057\u3066<a rel=\"nofollow\" href=\"http:\/\/www.chatwork.com\/ja\/\" target=\"_blank\">ChatWork<\/a>\u3092\u5229\u7528\u3057\u3066\u3044\u307e\u3059\u3002<br \/>\nChatWork\u306b\u306f\u5b09\u3057\u3044\u3053\u3068\u306bREST-API\u304c\u5b9f\u88c5\u3055\u308c\u3066\u3044\u307e\u3059\u306e\u3067\u3001<br \/>\nGoogle Apps Script\u3092\u4f7f\u7528\u3057\u3066Gmail\u306b\u5c4a\u3044\u305f\u304a\u554f\u3044\u5408\u308f\u305b\u30e1\u30fc\u30eb\u3092ChatWork\u306b\u901a\u77e5\u3059\u308b\u30b9\u30af\u30ea\u30d7\u30c8\u3092\u4f5c\u6210\u3057\u3066\u307f\u307e\u3057\u305f\u3002<\/p>\n<p><!--more--><\/p>\n<div class=\"frame_headding\">\n<h3 style=\"text-align: left;\">Chatwork API\u30c8\u30fc\u30af\u30f3\u306e\u53d6\u5f97<\/h3>\n<\/div>\n<p>\u307e\u305a\u306fChatwork API\u30c8\u30fc\u30af\u30f3\u3092\u53d6\u5f97\u3057\u307e\u3057\u3087\u3046\u3002<br \/>\nChatWork API\u306f\u73fe\u5728\uff082016\u5e749\u67086\u65e5\u6642\u70b9\uff09\u3067\u306f\u30d7\u30ec\u30d3\u30e5\u30fc\u7248\u3068\u3057\u3066\u63d0\u4f9b\u3055\u308c\u3066\u304a\u308a\u3001<br \/>\n\u5229\u7528\u3059\u308b\u306b\u306f\u7533\u8acb\u3092\u884c\u3046\u5fc5\u8981\u304c\u3042\u308a\u307e\u3059\u3002<br \/>\n<a href=\"http:\/\/developer.chatwork.com\/ja\/index.html\" target=\"_blank\" rel=\"nofollow\">\u30c1\u30e3\u30c3\u30c8\u30ef\u30fc\u30afAPI\u30c9\u30ad\u30e5\u30e1\u30f3\u30c8<\/a>\u304b\u3089\u7533\u8acb\u3092\u884c\u3046\u3053\u3068\u304c\u51fa\u6765\u307e\u3059\u3002<br \/>\n\u305f\u3060\u3057\u3001\u30d3\u30b8\u30cd\u30b9\u30d7\u30e9\u30f3\u3067\u306f\u7ba1\u7406\u8005\u6a29\u9650\u304c\u3042\u308b\u30e6\u30fc\u30b6\u304b\u3089\u3057\u304b\u7533\u8acb\u304c\u884c\u3048\u306a\u3044\u306e\u3067\u6ce8\u610f\u3057\u307e\u3057\u3087\u3046\u3002<br \/>\n\u307e\u305f\u3001\u7533\u8acb\u3057\u3066\u304b\u3089API\u304c\u5229\u7528\u53ef\u80fd\u306b\u306a\u308b\u307e\u3067\u5c11\u3057\u6642\u9593\u304c\u304b\u304b\u308a\u307e\u3059\u306e\u3067\u3001\u4e88\u3081\u7533\u8acb\u3057\u3066\u304a\u304d\u307e\u3057\u3087\u3046\u3002<\/p>\n<p>API\u304c\u5229\u7528\u53ef\u80fd\u306b\u306a\u308b\u3068ChatWork\u30de\u30a4\u30da\u30fc\u30b8\u306e\u52d5\u4f5c\u8a2d\u5b9a\u304b\u3089API\u30c8\u30fc\u30af\u30f3\u3092\u767a\u884c\u3059\u308b\u3053\u3068\u304c\u51fa\u6765\u307e\u3059\u3002<br \/>\n<a href=\"https:\/\/storage.googleapis.com\/sitest-wp\/blog\/wp-content\/uploads\/2016\/09\/8b768d5e90f02a94f02d4384e5328ae5.png\" target=\"_blank\"><img loading=\"lazy\" class=\"alignnone size-full wp-image-4013\" src=\"https:\/\/storage.googleapis.com\/sitest-wp\/blog\/wp-content\/uploads\/2016\/09\/8b768d5e90f02a94f02d4384e5328ae5.png\" alt=\"_4_\u30c1\u30e3\u30c3\u30c8\u30ef\u30fc\u30af_-_\u30de\u30a4\u30c1\u30e3\u30c3\u30c8_\" width=\"694\" height=\"392\" \/><\/a><\/p>\n<div class=\"frame_headding\">\n<h3 style=\"text-align: left;\">Apps Script\u306e\u4f5c\u6210<\/h3>\n<\/div>\n<p>\u4e0b\u8a18\u753b\u50cf\u306e\u3088\u3046\u306bGoogle Drive\u304b\u3089Apps Script\u30d7\u30ed\u30b8\u30a7\u30af\u30c8\u3092\u4f5c\u6210\u3059\u308b\u3053\u3068\u304c\u51fa\u6765\u307e\u3059\u3002<br \/>\n<a target=\"_blank\" href=\"https:\/\/storage.googleapis.com\/sitest-wp\/blog\/wp-content\/uploads\/2016\/09\/bdd6057af0e3653ac3e8e3aebe3b3d6c1.png\"><img loading=\"lazy\" src=\"https:\/\/storage.googleapis.com\/sitest-wp\/blog\/wp-content\/uploads\/2016\/09\/bdd6057af0e3653ac3e8e3aebe3b3d6c1.png\" alt=\"\u30b4\u30df\u7bb1_-_Google_\u30c9\u30e9\u30a4\u30d6\" width=\"610\" height=\"654\" class=\"alignnone size-full wp-image-4017\" \/><\/a><\/p>\n<p>\u30b9\u30af\u30ea\u30d7\u30c8\u306e\u30b5\u30f3\u30d7\u30eb\u306f\u4e0b\u8a18\u306b\u306a\u308a\u307e\u3059\u3002<br \/>\nAPI_TOKEN\u306f\u5148\u7a0b\u53d6\u5f97\u3057\u305f\u30c8\u30fc\u30af\u30f3\u3001ROOM_ID\u306fChatWork\u306eURL\u3067rid000000\u3068\u306a\u3063\u3066\u3044\u308brid\u4ee5\u964d\u306e\u6570\u5217\u3067\u3059\u3002<br \/>\n\u901a\u77e5\u3057\u305f\u3044ChatWork\u30b0\u30eb\u30fc\u30d7\u306eROOM_ID\u3092\u53d6\u5f97\u3057\u3066\u4e0b\u3055\u3044\u3002<br \/>\n\u5185\u5bb9\u3068\u3057\u3066\u306f\u3068\u3066\u3082\u7c21\u5358\u3067\u3001Gmail\u304b\u3089\u304a\u554f\u3044\u5408\u308f\u305b\u30e1\u30fc\u30eb\u306b\u30de\u30c3\u30c1\u3059\u308b\u30bf\u30a4\u30c8\u30eb\u306e\u65b0\u7740\u30e1\u30fc\u30eb\u3092\u53d6\u5f97\u3057\u3001<br \/>\n\u30e1\u30fc\u30eb\u306e\u5185\u5bb9\u3092ChatWork\u306b\u901a\u77e5\u3057\u3066\u3044\u307e\u3059\u3002<br \/>\n\u30e1\u30fc\u30eb\u306e\u691c\u7d22\u306b\u306f<a href=\"https:\/\/support.google.com\/mail\/answer\/7190\" rel=\"nofollow\" target=\"_blank\">Gmail\u3067\u4f7f\u7528\u3067\u304d\u308b\u691c\u7d22\u6f14\u7b97\u5b50<\/a>\u3092\u4f7f\u7528\u3059\u308b\u3053\u3068\u304c\u51fa\u6765\u307e\u3059\u3002<br \/>\n\u3053\u306e\u691c\u7d22\u6f14\u7b97\u5b50\u3092\u4e0a\u624b\u304f\u4f7f\u3063\u3066\u901a\u77e5\u3057\u305f\u3044\u30e1\u30fc\u30eb\u306e\u691c\u7d22\u3092\u3057\u307e\u3057\u3087\u3046\u3002<br \/>\n\u307e\u305f\u3001HTTP\u901a\u4fe1\u306b\u306f\u6a19\u6e96\u3067Apps Script\u306b\u63d0\u4f9b\u3055\u308c\u3066\u3044\u308b<a rel=\"nofollow\" href=\"https:\/\/developers.google.com\/apps-script\/reference\/url-fetch\/url-fetch-app\" target=\"_blank\">UrlFetchApp<\/a>\u30af\u30e9\u30b9\u3092\u4f7f\u7528\u3057\u3066\u3044\u307e\u3059\u3002<\/p>\n<pre><code>function notifyMail() {\n  var token = API_TOKEN;\n  var roomId = ROOM_ID;\n\n  try {\n    \/\/ \u672a\u8aad\u30e1\u30fc\u30eb\u3092\u53d6\u5f97\u3059\u308b \u691c\u7d22\u30af\u30a8\u30ea\u3092\u5909\u66f4\u3059\u308c\u3070\u8ee2\u9001\u3059\u308b\u30e1\u30fc\u30eb\u3092\u7d5e\u308b\u3053\u3068\u3082\u53ef\u80fd\n    var threads = GmailApp.search(\"is:unread subject:(\u304a\u554f\u3044\u5408\u308f\u305b\u304c\u3042\u308a\u307e\u3057\u305f OR \u304a\u7533\u8fbc\u304c\u3042\u308a\u307e\u3057\u305f)\");\n    Logger.log(\"Found \" + threads.length + \" threads.\");\n    if (threads == null || threads.length === 0) return;\n\n    for (var i = 0, tlen = threads.length; i &lt; tlen; i++) {\n      var msgs = threads[i].getMessages();\n      for (var j = 0, mlen = msgs.length; j &lt; mlen; j++) {\n        var msg = msgs[j];\n        if (!msg.isUnread()) continue;\n\n        var from = msg.getFrom();\n        var subject = msg.getSubject();\n        var body = msg.getBody();\n        \/\/ http:\/\/developer.chatwork.com\/ja\/endpoint_rooms.html#POST-rooms-room_id-messages\n        UrlFetchApp.fetch('https:\/\/api.chatwork.com\/v1\/rooms\/' + roomId + '\/messages', {\n          headers: {'X-ChatWorkToken': token},\n          method: 'post',\n          payload: 'body=' + encodeURIComponent(\n            \"\u203b\u3053\u3061\u3089\u306e\u30c1\u30e3\u30c3\u30c8\u306fAPI\u3092\u4f7f\u7528\u3057\u3066\u81ea\u52d5\u9001\u4fe1\u3057\u3066\u304a\u308a\u307e\u3059\u3002\" + \"\\n\"\n            + '[info][title]' + subject + '\\n'\n            + 'from: ' + from + '[\/title]'\n            + body + '[\/info]'\n          )\n        });\n        msg.markRead();\n      }\n    }\n  } catch(error) {\n    Logger.log(\"message:\" + error.message + \"\\nfileName:\" + error.fileName + \"\\nlineNumber:\" + error.lineNumber + \"\\nstack:\" + error.stack);\n  }\n}\n<\/code><\/pre>\n<div class=\"frame_headding\">\n<h3 style=\"text-align: left;\">Apps Script\u306e\u8d77\u52d5\u30c8\u30ea\u30ac\u30fc\u3092\u8a2d\u5b9a<\/h3>\n<\/div>\n<p>\u6700\u5f8c\u306bApp\uff53 Script\u306e\u8d77\u52d5\u30c8\u30ea\u30ac\u30fc\u3092\u8a2d\u5b9a\u3057\u307e\u3057\u3087\u3046\u3002<br \/>\n\u4e0a\u90e8\u30ca\u30d3\u30b2\u30fc\u30b7\u30e7\u30f3\u5185\u306e\u300c\u30ea\u30bd\u30fc\u30b9\u300d\u304b\u3089\u300c\u73fe\u5728\u306e\u30d7\u30ed\u30b8\u30a7\u30af\u30c8\u306e\u30c8\u30ea\u30ac\u30fc\u300d\u3092\u30af\u30ea\u30c3\u30af\u3057\u3066\u4e0b\u3055\u3044\u3002<br \/>\nGmail\u3092\u5229\u7528\u3059\u308b\u30b9\u30af\u30ea\u30d7\u30c8\u3067\u306f\u3001\u6642\u9593\u4e3b\u5c0e\u578b\u306e\u30c8\u30ea\u30ac\u30fc\u3092\u5229\u7528\u3067\u304d\u307e\u3059\u3002<br \/>\n\u6700\u77ed1\u5206\u6bce\u306b\u8d77\u52d5\u3059\u308b\u3088\u3046\u306b\u8a2d\u5b9a\u3059\u308b\u3053\u3068\u304c\u51fa\u6765\u307e\u3059\u306e\u3067\u3001\u304a\u597d\u307f\u306e\u30bf\u30a4\u30df\u30f3\u30b0\u3092\u8a2d\u5b9a\u3057\u3066\u4e0b\u3055\u3044\u3002<br \/>\n<a target=\"_blank\" href=\"https:\/\/storage.googleapis.com\/sitest-wp\/blog\/wp-content\/uploads\/2016\/09\/Notify_ChatWork_from_Gmail.png\"><img loading=\"lazy\" src=\"https:\/\/storage.googleapis.com\/sitest-wp\/blog\/wp-content\/uploads\/2016\/09\/Notify_ChatWork_from_Gmail.png\" alt=\"Notify_ChatWork_from_Gmail\" width=\"932\" height=\"305\" class=\"alignnone size-full wp-image-4028\" \/><\/a><\/p>\n<p>\u4fdd\u5b58\u30dc\u30bf\u30f3\u3092\u30af\u30ea\u30c3\u30af\u3057\u3066\u8a2d\u5b9a\u3057\u305f\u30c8\u30ea\u30ac\u30fc\u3092\u4fdd\u5b58\u3059\u308c\u3070\u8a2d\u5b9a\u306f\u5b8c\u4e86\u3067\u3059\u3002<\/p>\n<div class=\"frame_headding\">\n<h3 style=\"text-align: left;\">\u307e\u3068\u3081<\/h3>\n<\/div>\n<p>\u305f\u3063\u305f\u3053\u308c\u3060\u3051\u3067\u3001\u308f\u3056\u308f\u3056Gmail\u3092\u958b\u304f\u3053\u3068\u306a\u304fChatWork\u3092\u958b\u3044\u3066\u3044\u308b\u3060\u3051\u3067\u65b0\u7740\u30e1\u30fc\u30eb\u304c\u5206\u304b\u308b\u3088\u3046\u306b\u306a\u308a\u307e\u3057\u305f\u3002<br \/>\nGoogle Apps Script\u3084ChatWork API\u306b\u306f\u307e\u3060\u307e\u3060\u6ca2\u5c71\u4fbf\u5229\u306a\u4f7f\u3044\u65b9\u304c\u3042\u308a\u307e\u3059\u3002<br \/>\n\u4eca\u5f8c\u3082\u4fbf\u5229\u306a\u4f7f\u3044\u65b9\u3092\u7d39\u4ecb\u3057\u3066\u3044\u304d\u305f\u3044\u3068\u601d\u3044\u307e\u3059\u306e\u3067\u3001\u697d\u3057\u307f\u306b\u304a\u5f85\u3061\u4e0b\u3055\u3044\uff01<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u7686\u3055\u3093\u3001\u30b3\u30df\u30e5\u30cb\u30b1\u30fc\u30b7\u30e7\u30f3\u30c4\u30fc\u30eb\u306f\u3069\u306e\u3088\u3046\u306a\u30c4\u30fc\u30eb\u3092\u4f7f\u3063\u3066\u3044\u308b\u3067\u3057\u3087\u3046\u304b\u3002 \u5f0a\u793e\u3067\u306f\u30c1\u30e3\u30c3\u30c8\u30c4\u30fc\u30eb\u3068\u3057\u3066ChatWork\u3092\u5229\u7528\u3057\u3066\u3044\u307e\u3059\u3002 ChatWork\u306b\u306f\u5b09\u3057\u3044\u3053\u3068\u306bREST-API\u304c\u5b9f\u88c5\u3055\u308c\u3066\u3044\u307e\u3059\u306e\u3067\u3001 Google Apps Script\u3092\u4f7f\u7528\u3057\u3066Gmail\u306b\u5c4a\u3044\u305f\u304a\u554f\u3044\u5408\u308f\u305b\u30e1\u30fc\u30eb\u3092ChatWork\u306b\u901a\u77e5\u3059\u308b\u30b9\u30af\u30ea\u30d7\u30c8\u3092\u4f5c\u6210\u3057\u3066\u307f\u307e\u3057\u305f\u3002<\/p>\n","protected":false},"author":1,"featured_media":4050,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[27],"tags":[],"acf":false,"_links":{"self":[{"href":"https:\/\/sitest.jp\/blog\/wp-json\/wp\/v2\/posts\/3869"}],"collection":[{"href":"https:\/\/sitest.jp\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/sitest.jp\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/sitest.jp\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/sitest.jp\/blog\/wp-json\/wp\/v2\/comments?post=3869"}],"version-history":[{"count":13,"href":"https:\/\/sitest.jp\/blog\/wp-json\/wp\/v2\/posts\/3869\/revisions"}],"predecessor-version":[{"id":4049,"href":"https:\/\/sitest.jp\/blog\/wp-json\/wp\/v2\/posts\/3869\/revisions\/4049"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/sitest.jp\/blog\/wp-json\/wp\/v2\/media\/4050"}],"wp:attachment":[{"href":"https:\/\/sitest.jp\/blog\/wp-json\/wp\/v2\/media?parent=3869"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/sitest.jp\/blog\/wp-json\/wp\/v2\/categories?post=3869"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/sitest.jp\/blog\/wp-json\/wp\/v2\/tags?post=3869"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}