{"id":3948,"date":"2016-03-10T10:26:46","date_gmt":"2016-03-10T01:26:46","guid":{"rendered":"http:\/\/blog.bitmeister.jp\/?p=3948"},"modified":"2016-03-10T10:26:46","modified_gmt":"2016-03-10T01:26:46","slug":"python%e3%81%a7slackbot%e3%82%92%e4%bd%9c%e3%82%8b3","status":"publish","type":"post","link":"https:\/\/blog.bitmeister.jp\/?p=3948","title":{"rendered":"Python\u3067Slackbot\u3092\u4f5c\u308b(3)"},"content":{"rendered":"<p>\u73fe\u5728\u3001\u5f0a\u793e\u3067\u3082Slack\u3092\u8a66\u9a13\u7684\u306b\u5229\u7528\u3057\u3066\u3044\u308b\u306e\u3067\u3059\u304c\u3001RTM API\u3092\u4f7f\u3048\u3070\u30ed\u30fc\u30ab\u30eb\u3067\u3082bot\u304c\u4f5c\u6210\u3067\u304d\u308b\u3053\u3068\u3092\u77e5\u3063\u305f\u306e\u3067Python\u3067\u4f5c\u3063\u3066\u307f\u3088\u3046\u3068\u3044\u3046\u8a18\u4e8b\u3067\u3059\u3002<br \/>\n\u4eca\u56de\u306f\u7b2c3\u56de\u76ee\u3067\u3059\u3002<\/p>\n<p><!--more--><\/p>\n<p>\u524d\u56de\u306fSlackbot\u306e\u30d7\u30e9\u30b0\u30a4\u30f3\u3068\u3057\u3066\u3001DM\u3084Bot\u304c\u53c2\u52a0\u3057\u3066\u3044\u308b\u30c1\u30e3\u30f3\u30cd\u30eb\uff08\u30b0\u30eb\u30fc\u30d7\u542b\u3080\uff09\u5185\u3067\u306e\u30e1\u30f3\u30b7\u30e7\u30f3\u3084\u6295\u7a3f\u5185\u306e\u7279\u5b9a\u306e\u8a00\u8449\u306b\u53cd\u5fdc\u3059\u308b\u6a5f\u80fd\u3092\u5b9f\u88c5\u3057\u307e\u3057\u305f\u304c\u3001Bot\u3068\u3057\u3066\u306f\u3001\u4efb\u610f\u306e\u5951\u6a5f\u3067\u6295\u7a3f\u3057\u3066\u304f\u308c\u308b\u6a5f\u80fd\u3082\u6b32\u3057\u3044\u3067\u3059\u3088\u306d\u3002\u30b1\u30fc\u30b9\u3068\u3057\u3066\u306f\u6642\u5831\u3067\u3042\u3063\u305f\u308a\u3001\u30ea\u30de\u30a4\u30f3\u30c0\u3060\u3063\u305f\u308aGit\u30ea\u30dd\u30b8\u30c8\u30ea\u3078\u306epush\u306e\u6642\u3060\u3063\u305f\u308a\u3068\u8272\u3005\u3068\u4f7f\u3048\u305d\u3046\u3067\u3059\u3002<\/p>\n<p>\u6b8b\u5ff5\u306a\u304c\u3089\u3001\u4eca\u56de\u5229\u7528\u3057\u3066\u3044\u308bSlackbot\u30e9\u30a4\u30d6\u30e9\u30ea\u306b\u81ea\u4f53\u306f\u305d\u306e\u3088\u3046\u306a\u6a5f\u80fd\u3092\u6301\u3063\u3066\u3044\u306a\u3044\u306e\u3067\u3059\u304c\u3001Slackbot\u30e9\u30a4\u30d6\u30e9\u30ea\u304c\u5185\u90e8\u3067\u5229\u7528\u3057\u3066\u3044\u308bSlacker\u30e9\u30a4\u30d6\u30e9\u30ea\u3092\u7528\u3044\u3066Slack API\u3092\u4f7f\u3048\u3070\u3084\u308a\u305f\u3044\u3053\u3068\u306f\u5b9f\u73fe\u3067\u304d\u307e\u3059\u3002<\/p>\n<p><a href=\"https:\/\/github.com\/os\/slacker\" target=\"_blank\">os\/slacker: Full-featured Python interface for the Slack API<\/a><br \/>\n<a href=\"https:\/\/api.slack.com\/\" target=\"_blank\">Slack API<\/a><\/p>\n<h3>Slacker\u3067\u6295\u7a3f(\u305d\u306e1)<\/h3>\n<p>Slacker\u30e9\u30a4\u30d6\u30e9\u30ea\u3092\u5229\u7528\u3059\u308b\u306e\u306f\u3069\u306e\u30c7\u30a3\u30ec\u30af\u30c8\u30ea\u3067\u3082\u554f\u984c\u306f\u306a\u3044\u306e\u3067\u3059\u304c\u3001Bot\u7528\u306bAPI\u30c8\u30fc\u30af\u30f3\u3092\u8a18\u8ff0\u3057\u305f\u30d5\u30a1\u30a4\u30eb\u3092\u305d\u306e\u307e\u307e\u53c2\u7167\u3057\u305f\u3044\u306e\u3067bot\u7528\u306e\u30c7\u30a3\u30ec\u30af\u30c8\u30ea\u306b\u79fb\u52d5\u3057\u307e\u3059\u3002<\/p>\n<pre class=\"brush: bash; gutter: false; title: ; notranslate\" title=\"\">\r\n$ cd bossan\/\r\n$ vi bossan_post1.py\r\n<\/pre>\n<p>\u30d7\u30e9\u30a4\u30d9\u30fc\u30c8\u30b0\u30eb\u30fc\u30d7\u306b\u6295\u7a3f\u3057\u3066\u307f\u307e\u3059\u3002<\/p>\n<pre class=\"brush: python; gutter: false; title: ; notranslate\" title=\"\">\r\n# -*- coding: utf-8 -*-\r\n\r\nfrom slacker import Slacker\r\nimport slackbot_settings\r\n\r\nif __name__ == '__main__':\r\n    slack = Slacker(slackbot_settings.API_TOKEN)\r\n    slack.chat.post_message('bossan_test','\u3053\u3093\u306b\u3061\u308f\u30fc')\r\n<\/pre>\n<pre class=\"brush: bash; gutter: false; title: ; notranslate\" title=\"\">\r\n$ python3 bossan_post1.py\r\n<\/pre>\n<p><a href=\"https:\/\/blog.bitmeister.jp\/wp-content\/uploads\/2016\/03\/01_post.png\" rel=\"attachment wp-att-3955\" data-rel=\"lightbox-image-0\" data-rl_title=\"\" data-rl_caption=\"\" title=\"\"><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-3955\" src=\"https:\/\/blog.bitmeister.jp\/wp-content\/uploads\/2016\/03\/01_post.png\" alt=\"01_post\" width=\"249\" height=\"56\" \/><\/a><\/p>\n<p>\u3042\u308c\uff1f\u30a2\u30a4\u30b3\u30f3\u3068\u540d\u524d\u304c\u9055\u3044\u307e\u3059\u306d\u3002\u5f15\u6570\u3092\u8ffd\u52a0\u3057\u3066\u307f\u307e\u3057\u3087\u3046\u3002<\/p>\n<pre class=\"brush: bash; gutter: false; title: ; notranslate\" title=\"\">\r\n$ vi bossan_post2.py\r\n<\/pre>\n<pre class=\"brush: python; gutter: false; title: ; notranslate\" title=\"\">\r\n# -*- coding: utf-8 -*-\r\n\r\nfrom slacker import Slacker\r\nimport slackbot_settings\r\n\r\nif __name__ == '__main__':\r\n    slack = Slacker(slackbot_settings.API_TOKEN)\r\n    slack.chat.post_message(\r\n        'bossan_test',\r\n        '\u3053\u3093\u306b\u3061\u308f\u30fc',\r\n        as_user=True\r\n        )\r\n<\/pre>\n<p>\u4eca\u5ea6\u306f\u5f15\u6570\u306b\u300cas_user\u300d\u3092True\u3067\u6307\u5b9a\u3057\u307e\u3059\u3002<\/p>\n<pre class=\"brush: bash; gutter: false; title: ; notranslate\" title=\"\">\r\n$ python3 bossan_post2.py\r\n<\/pre>\n<p><a href=\"https:\/\/blog.bitmeister.jp\/wp-content\/uploads\/2016\/03\/02_post.png\" rel=\"attachment wp-att-3956\" data-rel=\"lightbox-image-1\" data-rl_title=\"\" data-rl_caption=\"\" title=\"\"><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-3956\" src=\"https:\/\/blog.bitmeister.jp\/wp-content\/uploads\/2016\/03\/02_post.png\" alt=\"02_post\" width=\"215\" height=\"45\" \/><\/a><\/p>\n<p>\u304a\u304a\u3001\u3061\u3083\u3093\u3068\u540d\u524d\u3068\u30a2\u30a4\u30b3\u30f3\u304c\u8868\u793a\u3055\u308c\u307e\u3057\u305f\u3002\u3067\u3082\u3001\u6642\u306b\u306f\u30c7\u30d5\u30a9\u30eb\u30c8\u306e\u540d\u524d\u3068\u30a2\u30a4\u30b3\u30f3\u4ee5\u5916\u3092\u4f7f\u3044\u305f\u3044\u6642\u3082\u3042\u308a\u307e\u3059\u3088\u306d\uff1f\u305d\u3093\u306a\u6642\u306f\u2026<\/p>\n<pre class=\"brush: bash; gutter: false; title: ; notranslate\" title=\"\">\r\n$ vi bossan_post3.py\r\n<\/pre>\n<pre class=\"brush: python; gutter: false; title: ; notranslate\" title=\"\">\r\n# -*- coding: utf-8 -*-\r\n\r\nfrom slacker import Slacker\r\nimport slackbot_settings\r\n\r\nif __name__ == '__main__':\r\n    slack = Slacker(slackbot_settings.API_TOKEN)\r\n    slack.chat.post_message(\r\n        'bossan_test',\r\n        '\u3053\u3093\u306b\u3061\u308f\u30fc',\r\n        username='\u30dc\u30c3\u30b5\u30f3',\r\n        icon_emoji=':simple_smile:',\r\n        )\r\n<\/pre>\n<p>\u5f15\u6570\u306b\u300cusername\u300d\u3068\u300cicon_emoji\u300d\u3092\u6307\u5b9a\u3057\u307e\u3059\u3002<\/p>\n<pre class=\"brush: bash; gutter: false; title: ; notranslate\" title=\"\">\r\n$ python3 bossan_post3.py\r\n<\/pre>\n<p><a href=\"https:\/\/blog.bitmeister.jp\/wp-content\/uploads\/2016\/03\/03_post.png\" rel=\"attachment wp-att-3957\" data-rel=\"lightbox-image-2\" data-rl_title=\"\" data-rl_caption=\"\" title=\"\"><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-3957\" src=\"https:\/\/blog.bitmeister.jp\/wp-content\/uploads\/2016\/03\/03_post.png\" alt=\"03_post\" width=\"226\" height=\"52\" \/><\/a><\/p>\n<p>\u3068\u3001\u30c7\u30d5\u30a9\u30eb\u30c8\u3068\u306f\u5225\u306e\u3082\u306e\u3067\u3082\u4f7f\u3048\u307e\u3059\u3002<\/p>\n<p>\u6295\u7a3f\u5148\u306f\u7b2c\u4e00\u5f15\u6570\u3067\u6307\u5b9a\u3057\u3066\u3044\u308b\u306e\u3067\u3059\u304c\u3001\u5f53\u7136\u666e\u901a\u306b\u30c1\u30e3\u30f3\u30cd\u30eb\u3084DM\u3082\u9001\u308b\u3053\u3068\u304c\u3067\u304d\u307e\u3059\u3002<\/p>\n<p><a href=\"https:\/\/api.slack.com\/methods\/chat.postMessage#channels\" target=\"_blank\">chat.postMessage method | Slack<\/a><\/p>\n<p>\u6295\u7a3f\u5148\u306e\u6307\u5b9a\u306f\u540d\u524d\u3067\u3082ID\u3067\u3082\u3088\u3044\u306e\u3067\u3059\u304c\u3001\u4eca\u56de\u306f\u540d\u524d\u3067\u6307\u5b9a\u3057\u3066\u307f\u307e\u3057\u305f\u3002\u306a\u304a\u3001\u6295\u7a3f\u5148\u3092\u30c1\u30e3\u30f3\u30cd\u30eb\u3084\u30b0\u30eb\u30fc\u30d7\u3067\u306f\u306a\u304f\u7279\u5b9a\u306e\u30e6\u30fc\u30b6\u306b\u5bfe\u3059\u308bDM\u3068\u3059\u308b\u5834\u5408\u306f\u3001as_user=True\u306b\u3057\u306a\u3044\u3068\u9001\u4fe1\u5143\u304cAPI\u30c8\u30fc\u30af\u30f3\u3092\u6307\u5b9a\u3057\u305fBot\u3067\u306f\u306a\u304f\u3001\u6a19\u6e96\u306eslackbot\u306b\u306a\u308b\u306e\u3067\u6ce8\u610f\u3057\u307e\u3057\u3087\u3046\u3002<\/p>\n<h3>Slacker\u3067\u6295\u7a3f(\u305d\u306e2)<\/h3>\n<p>\u3055\u3066\u3001\u3053\u308c\u3067\u6295\u7a3f\u306f\u3067\u304d\u307e\u3057\u305f\u304c\u306a\u3093\u3060\u304b\u30b7\u30f3\u30d7\u30eb\u3067\u3055\u307f\u3057\u3044\u3067\u3059\u306d\u3002\u5b9f\u306fSlack\u3067\u306fAttachements\u3068\u3044\u3046\u4ed5\u7d44\u307f\u3092\u4f7f\u3046\u3068\u3082\u3046\u5c11\u3057\u30ea\u30c3\u30c1\u306a\u5f62\u5f0f\u3092\u6307\u5b9a\u3057\u305f\u6295\u7a3f\u304c\u3067\u304d\u307e\u3059\u3002<\/p>\n<p><a href=\"https:\/\/api.slack.com\/docs\/attachments\" target=\"_blank\">Message Attachments | Slack<\/a><\/p>\n<pre class=\"brush: bash; gutter: false; title: ; notranslate\" title=\"\">\r\n$ vi bossan_post4.py\r\n<\/pre>\n<pre class=\"brush: python; gutter: false; title: ; notranslate\" title=\"\">\r\n# -*- coding: utf-8 -*-\r\n\r\nfrom slacker import Slacker\r\nimport slackbot_settings\r\n\r\nif __name__ == '__main__':\r\n\r\n    slack = Slacker(slackbot_settings.API_TOKEN)\r\n    attachment = {\r\n        'author_name': '\u30d3\u30c3\u30c8\u30ed\u30b0',\r\n        'author_icon': 'https:\/\/XXXXXXXXXXXX\/blog\/bitlogo.png',\r\n        'author_link': 'https:\/\/blog.bitmeister.jp\/?p=3892',\r\n        'title': 'Python\u3067Slackbot\u3092\u4f5c\u308b(1)',\r\n        'text': '\u73fe\u5728\u3001\u5f0a\u793e\u3067\u3082Slack\u3092\u8a66\u9a13\u7684\u306b\u5229\u7528\u3057\u3066\u3044\u308b\u306e\u3067\u3059\u304c\u3001RTM API\u3092\u4f7f\u3048\u3070\u30ed\u30fc\u30ab\u30eb\u3067\u3082bot\u304c\u4f5c\u6210\u3067\u304d\u308b\u3053\u3068\u3092\u77e5\u3063\u305f\u306e\u3067Python\u3067\u4f5c\u3063\u3066\u307f\u3088\u3046\u3068\u3044\u3046\u8a18\u4e8b\u3067\u3059\u3002\\n\u4eca\u56de\u306f\u7b2c1\u56de\u76ee\u3067\u3059\u3002',\r\n        'image_url': 'https:\/\/XXXXXXXXXXXX\/blog\/07_slack.png',\r\n        'color': '#1e2c5b'\r\n    }\r\n\r\n    slack.chat.post_message(\r\n        'bossan_test',\r\n        '\u30d6\u30ed\u30b0\u304c\u66f4\u65b0\u3055\u308c\u307e\u3057\u305f',\r\n        as_user=True,\r\n        attachments=&#x5B;attachment]\r\n    )\r\n<\/pre>\n<p>\u5f15\u6570\u306b\u300cattachments\u300d\u306bdict\u306e\u914d\u5217\u3092\u6307\u5b9a\u3057\u307e\u3059\u3002dict\u306b\u8a2d\u5b9a\u3059\u308b\u30ad\u30fc\u9805\u76ee\u306f\u300cMessage Attachments\u300d\u3092\u53c2\u7167\u3057\u3066\u304f\u3060\u3055\u3044\u3002\u306a\u304a\u3001\u914d\u5217\u3092\u6307\u5b9a\u3057\u3066\u3044\u308b\u306e\u3067\u304a\u308f\u304b\u308a\u304b\u3068\u601d\u3044\u307e\u3059\u304c\u3001\u8907\u6570\u306eAttachment(dict)\u3092\u8a2d\u5b9a\u3059\u308b\u3053\u3068\u304c\u3067\u304d\u307e\u3059\u3002<\/p>\n<pre class=\"brush: bash; gutter: false; title: ; notranslate\" title=\"\">\r\n$ python3 bossan_post4.py\r\n<\/pre>\n<p><a href=\"https:\/\/blog.bitmeister.jp\/wp-content\/uploads\/2016\/03\/10_slack.png\" rel=\"attachment wp-att-3976\" data-rel=\"lightbox-image-3\" data-rl_title=\"\" data-rl_caption=\"\" title=\"\"><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-medium wp-image-3976\" src=\"https:\/\/blog.bitmeister.jp\/wp-content\/uploads\/2016\/03\/10_slack-295x300.png\" alt=\"10_slack\" width=\"295\" height=\"300\" srcset=\"https:\/\/blog.bitmeister.jp\/wp-content\/uploads\/2016\/03\/10_slack-295x300.png 295w, https:\/\/blog.bitmeister.jp\/wp-content\/uploads\/2016\/03\/10_slack.png 661w\" sizes=\"auto, (max-width: 295px) 100vw, 295px\" \/><\/a><\/p>\n<p>\u3053\u306e\u3088\u3046\u306b\u3001\u30bf\u30a4\u30c8\u30eb\u3084\u753b\u50cf\u3092\u6dfb\u4ed8\u3057\u305f\u6295\u7a3f\u3092\u884c\u3046\u3053\u3068\u304c\u53ef\u80fd\u3067\u3059\u3002<\/p>\n<p>\u203b\u4e0a\u8a18\u30b5\u30f3\u30d7\u30eb\u3067\u306f\u300cauthor_icon\u300d\u3068\u300cimage_url\u300d\u306eURL\u306f\u64ec\u4f3c\u306a\u306e\u3067\u74b0\u5883\u306b\u5fdc\u3058\u3067\u5909\u66f4\u3057\u3066\u304f\u3060\u3055\u3044\u3002\u306a\u304a\u3001\u53c2\u7167\u5148\u306eURL\u306b\u3088\u3063\u3066\u306fSlack\u5074\u304b\u3089\u306e\u753b\u50cf\u53d6\u5f97\u306b\u6642\u9593\u304c\u304b\u304b\u308a\u9001\u4fe1\u30a8\u30e9\u30fc\u3068\u306a\u308b\u30b1\u30fc\u30b9\u304c\u898b\u53d7\u3051\u3089\u308c\u305f\u306e\u3067\u3001\u540c\u3058\u75c7\u72b6\u304c\u767a\u751f\u3057\u305f\u5834\u5408\u306fdropbox\u7b49\u306e\u30af\u30e9\u30a6\u30c9\u30b9\u30c8\u30ec\u30fc\u30b8\u3067\u5171\u6709\u3057\u3066\u8a66\u3057\u3066\u307f\u308b\u3068\u6539\u5584\u3055\u308c\u308b\u304b\u3082\u3057\u308c\u307e\u305b\u3093\u3002<\/p>\n<p>\u3068\u3044\u3046\u3053\u3068\u3067\u3001Slacker\u30e9\u30a4\u30d6\u30e9\u30ea\u3092\u4f7f\u3048\u3070\u3001\u7c21\u5358\u306b\u6295\u7a3f\u3067\u304d\u308b\u3053\u3068\u304c\u3067\u304d\u307e\u3057\u305f\u3002\u6b21\u56de\u306f\u3044\u3088\u3044\u3088\u5fdc\u7528\u7de8\u306b\u7a81\u5165\u3057\u307e\u3059\u3002<\/p>\n<p>&nbsp;<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u73fe\u5728\u3001\u5f0a\u793e\u3067\u3082Slack\u3092\u8a66\u9a13\u7684\u306b\u5229\u7528\u3057\u3066\u3044\u308b\u306e\u3067\u3059\u304c\u3001RTM API\u3092\u4f7f\u3048\u3070\u30ed\u30fc\u30ab\u30eb\u3067\u3082bot\u304c\u4f5c\u6210\u3067\u304d\u308b\u3053\u3068\u3092\u77e5\u3063\u305f\u306e\u3067Python\u3067\u4f5c\u3063\u3066\u307f\u3088\u3046\u3068\u3044\u3046\u8a18\u4e8b\u3067\u3059\u3002 \u4eca\u56de\u306f\u7b2c3\u56de\u76ee\u3067\u3059\u3002<\/p>\n","protected":false},"author":5,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[17],"tags":[80,137],"class_list":["post-3948","post","type-post","status-publish","format-standard","hentry","category-tech","tag-python","tag-slack"],"_links":{"self":[{"href":"https:\/\/blog.bitmeister.jp\/index.php?rest_route=\/wp\/v2\/posts\/3948","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/blog.bitmeister.jp\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/blog.bitmeister.jp\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/blog.bitmeister.jp\/index.php?rest_route=\/wp\/v2\/users\/5"}],"replies":[{"embeddable":true,"href":"https:\/\/blog.bitmeister.jp\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=3948"}],"version-history":[{"count":9,"href":"https:\/\/blog.bitmeister.jp\/index.php?rest_route=\/wp\/v2\/posts\/3948\/revisions"}],"predecessor-version":[{"id":3980,"href":"https:\/\/blog.bitmeister.jp\/index.php?rest_route=\/wp\/v2\/posts\/3948\/revisions\/3980"}],"wp:attachment":[{"href":"https:\/\/blog.bitmeister.jp\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=3948"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blog.bitmeister.jp\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=3948"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blog.bitmeister.jp\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=3948"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}