ããã«ã¡ã¯ãã»ãããã§ãã
çããããåãè¨èãã¡ããç¥ã£ã¦ãã¾ããï¼æè¿æµè¡ã£ã¦ãã¾ãããã
ãã®æå³ããã¨ããã¯ãã¾ãã¡ãããã¾ããããããã ãåºãèªç¥ããã¦ããã¨ãããã¨ã§ããã¼ã±ãã£ã³ã°çã«ã¯æåãªã®ã§ãããããæ£ç´ãããããã¾ããã
ãã¤ã§ãå³ããããï¼
ãããããã®ãã¼ã¸ãè¦ã¦ããã¨
ã»ããããªãã»ã©ï¼
ã¨æã£ãã
ã»ããããªãã»ã©...
ã¨æã£ãããä¸æä¸æãå³ããæ·±ãããã§ãã
ãããªè¨èããåãã¦ããã¨ãã«ãã¤ã§ãå³ããããï¼ ããæããåãè¨èãã¡ãè¿ãã¦ãããbotãä½ã£ã¦ã社å ã®slackã«ã¶ã¡è¾¼ãã§ããã¾ããã Good bye 令åãCome backæåã
ä¼ç¤¾ã®devãã¼ã ã®ã¹ã©ãã¯ã§ã¯ãhelloã¨æ¨æ¶ãããã¨æ¨æ¶ä»£ããã«åãè¨èãè¿ãã¦ããã¾ãã
ãåãè¨èãã¡ããå³ããããã¨ãã«å³ãããbotã社å ã¹ã©ãã¯ã«ã¶ã¡è¾¼ãã§ããã¾ãããåãæ¹æ¹é©ã§ãð pic.twitter.com/m5ArfcScfj
— ã»ããã (@hokekiyoo) June 14, 2019
社å¡ã®ã¿ããªãããã¡ãã«ä½¿ã£ã¦ããã¦ããã¤ã³ããé¸æããã¦ãã¾ããã¨ã¦ãwin-winã§ãã^^
ã¤ãããã
åºæ¬çãªslack botã®ä½ãæ¹ã«æ²¿ã£ãã ããªã®ã§ãããå°å
¥ãããï¼ã¨ããæ¹ãããã£ãããã¨æãã®ã§ãã¡ãã£ã¨ã ãæè¡çãªèª¬æãã
ä»åã¯ãpythonã®slackbot
ã¨ããã©ã¤ãã©ãªã使ã£ã¦ãã¾ãã
ç¨æãããã®
- ãµã¼ãã¼(slackbotãåããã³ã³ãã¥ã¼ã¿ãã¤ãã«botãåããã¦ãããªã24h稼åãæã¾ããããpython使ããã°ä½ã§ãè¯ãã)
- Pythonç°å¢ : ç¨æãã¦ãã ãããä»åã¯3.7ã§ä½ã£ã¦ãã¾ããä¸è¨ã©ã¤ãã©ãªã使ããããã«ãã¦ããã¾ããã
- bs4 (ã¹ã¯ã¬ã¤ãã³ã°ç¨ã®ã©ã¤ãã©ãª)
- slackbot (slackbotãåããã¨ãã®ã©ã¤ãã©ãª)
- git: ããã°ä¾¿å©ãç§ã®ã³ã¼ããã®ã¾ã¾ä½¿ãã¾ãã
slack bot
ã¾ãã¯ãæ¢åslackã«botã追å ãã¦ããã¾ããä¸è¨ãã¼ã¸ãã追å ãã§ããããã«ãªã£ã¦ãã¾ããä½ãããã¯ã¼ã¯ã¹ãã¼ã¹ã«ã¢ã¯ã»ã¹ããâã«é£ã³ã¾ãããã
https://my.slack.com/services/new/bot
botã®ååã決ããããTOKENã¨ããã®ãåºã¦ãã¾ãããããã³ãã¼ãããªããã¦ä¿åãã¦ããã¦ãã ããã
slackbotã®è¨å®
ã³ã¼ãã¯githubãªãã¸ããªã«ä¸ãã¦ãã¾ã
ãªããä½ãæ¹ã¯ãã¡ãã®è¨äºãåèã«ãã¾ãã
ãã©ã«ããã¨cloneãã¦ä½¿ã£ã¦ãã ãããå¤ããã®ã¯ãslackbot_settings
ã®API_TOKENã®ã¨ããã§ãã
ããã«ãå
ç¨ä¿ç®¡ãã¦ãããAPIãæ¸ãè¾¼ã¿ã¾ãã
# coding: utf-8 # botã¢ã«ã¦ã³ãã®ãã¼ã¯ã³ãæå®ããããå¤ããï¼ API_TOKEN = "XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX" # botå®ã¡ãã»ã¼ã¸ã®ä¾å¤å¯¾å¿ DEFAULT_REPLY = "HELLO, SOMETHING WRONG" # ãã©ã°ã¤ã³ããã®ä¸ã«å¼ã³ãããå¾ã®åå¿ãªã©ãæ¸ã PLUGINS = ['plugins']
python run.py
ããã©ã¤ãã©ãªãç¨æããç°å¢ä¸ã§åããã¨OKã§ãã
å¼ã³ãããå¾ã®åå¿ãæ¸ã
ã©ããã£ã¦åã£ã¦ãã¦ããã®ãã¯é常ã«ç°¡åã§ãå½è©²ãã¼ã¸ããã¹ã¯ã¬ã¤ãã³ã°ããã¦ãããã¹ããè¿ãã¦ããã ãã§ãã
my_mentions
ã®ä¸èº«ã«æ¸ããã¦ãã¾ãã
# coding: utf-8 from slackbot.bot import respond_to # @botname: ã§åå¿ãããã³ã¼ã from slackbot.bot import listen_to # ãã£ãã«å çºè¨ã§åå¿ãããã³ã¼ã from slackbot.bot import default_reply # 該å½ããå¿çããªãå ´åã«åå¿ãããã³ã¼ã from bs4 import BeautifulSoup try: from urllib2 import urlopen except: from urllib.request import urlopen def FetchWorkingWord(): #url url = "https://www.hatakoto.jp/" #get html html = urlopen(url) soup = BeautifulSoup(html, "html.parser") text = "\n" text += soup.find(attrs=["class_","chinContent vertical"]).text text += "\n\n"+soup.find(attrs=["class_","chinMsg vertical"]).text return text @respond_to('hello') def reply_hello(message): text = FetchWorkingWord() message.reply(text)
ããã§ã話ãããããã³ã«ãåãè¨èãã¡ããããã¯ã¢ãããã¦ãè¿ãã¦ããã¾ãã
ã¾ã¨ã
ã¿ãªããããé©å½ãªãµã¼ãã¼ãç«ã¦ã¦ç¤¾å slackã«ã¶ã¡ããã§ã¿ã¦ã¯ãããã§ãããï¼ ãªããªãå³ããæ·±ãæç« ãåºåãã¦ããã¾ãããããæå³å æ°ãåºã¾ã
å®æçã«åãæµãã¦ããåãè¨èãã¡ãã«ã¤ãããªã¢ã¯ã·ã§ã³æ°ãã«ã¦ã³ããã¦ããã®ä¼ç¤¾ã®"""社風"""ãåæããããªãã¦ãã£ã¦ããã人ããªãã§ããï¼æã社ã¯ã¾ã 社å¡ãå¤ããªãã®ã§ãµã³ãã«ãéã¾ããªãããã§ãã
ä»åã¯åºæ¥å¿ã§ä½ãã¾ããããslackbotã¯ã¨ã¦ãèªç±åº¦ãé«ãå¼·åãªãã¼ã«ã§ãã使ãæ¹ã§ç¤¾å ã³ãã¥ãã±ã¼ã·ã§ã³ã®æ´»çºåã«ãç¹ããã¾ããã¿ãªãããæ¯é使ã£ã¦ã¿ã¦ãã ãããã§ã¯ã§ã¯ã£