Slackã®WebHookã¨NTTãã³ã¢ã®éè«å¯¾è©±APIã¨Apigeeã§éè«ããããã¤ãã #apijp
Web API Advent Calendar 2014ãæçµæ¥ã®ã¨ã³ããªã¯ãæè¿ä¸é¨ã§æµè¡ä¸ã®ãã¼ã ã³ãã¥ãã±ã¼ã·ã§ã³ãã¼ã«Slackã®ãã¿ã§ãã
ï¼å®æããããããSlackã§è©¦ãã¦ããã¨ããï¼
Slackãã¿ã¯id:i2keyããã®12/13ã®ç´ æµãªã¨ã³ããªï¼
ZapierでSlackを佐野ひなこちゃんで埋め尽くす #apijp - @i2key のBlog
ã§ãã§ã«ä½¿ããã¦ãã¾ãã¾ããããããã§ã¯Slackãæä¾ããå¥ã®ã¤ã³ãã°ã¬ã¼ã·ã§ã³æ¹æ³ã使ã£ã¦éè«ããããä½ã£ã¦ã¿ã¾ãã
Slackã«ã¯å¤é¨ããã°ã©ã ã¨ã®さまざまなインテグレーション方法ãç¨æããã¦ãã¾ãããã®ä¸ã®Outgoing WebHooksã®æ©è½ã¯ãSlackã«æ°ããã¡ãã»ã¼ã¸ãå ¥åããããã³ã«è¨å®ããå¤é¨URLãå¼ã³åºãã¦ãããã¨ãããã®ã§ããããã«ãå æ¥ã®API Meetup Tokyo #4ã§ドコモさんが紹介ãã¦ãã雑談対話APIãçµã¿åããã¾ãã
Slackã®WebHookå¼ã³åºãã¨éè«å¯¾è©±APIã®å¼ã³åºãå½¢å¼ã¯ç°ãªããããéã§ãã®èª¿æ´ãå¤æãè¡ãä½ããå¿ è¦ã«ãªãã¾ããé常ãªãä½ããã®ã¹ã¯ãªãããªã©ãæ¸ãã¨ããã§ãããããã§ã¯ããããªã(?)宣ä¼ãå ¼ãã¦Apigee Edgeã®API Proxyã®æ©è½ã使ã£ã¦ãã®æ¥ç¶ãå®ç¾ãã¦ã¿ã¾ããã
ããã¾ããªå¦çã®æµã
- æå®ãããæ¡ä»¶ã«åè´ããã¡ãã»ã¼ã¸ãå ¥åãããã¨ãè¨å®ãã¦ãããApigee Proxyã®URLã«Slackãã¡ãã»ã¼ã¸ããã¹ããªã©ãPOSTãã
- Apigeeããã©ã¼ã ãã¼ã¿ãåãåããã¡ãã»ã¼ã¸ããã¹ã(text)ãã¦ã¼ã¶å(user_name)ãªã©ãåãåºã
- ã¦ã¼ã¶åã"slackbot"ã®å ´åãçºè¨è ã¯ï¼èªåãå«ãï¼ããããªã®ã§ä½ããã200ã§ç©ºã®ã¬ã¹ãã³ã¹ãè¿ãã¦å¦çãçµããããããè¡ããªãã¨èªåã®çºè¨ã«å¯¾ãã¦ãWebHookå¼ã³åºããèµ·ããããç¡éã«ã¼ããçºçããï¼1åããããã¾ããï¼
- 以åã®ä¼è©±ã®ã³ã³ããã¹ãIDããã£ãã·ã¥ã«ããã°èªã¿åºã
- å¿ è¦ãªãã¼ã¿ãJSONå½¢å¼ã«ãã¦ãã³ã¢APIã«POSTãã
- ãã³ã¢APIãè¿ãJSONãã¼ã¿ãåãåãããããã®çºè¨(utt)ãã³ã³ããã¹ãID(context)ãåãåºã
- ã³ã³ããã¹ãIDã¯Slackã®channel_idããã¼ã¨ãã¦ãã£ãã·ã¥ã«ä¿åãã¦ãã
- ãããã®çºè¨ãWebHookã®è¿ä¿¡å½¢å¼ã®JSONã«ã¾ã¨ãç´ãã¦Slackã«è¿ã
Apigeeã§ã®å®è£
ãããã¯ã¯ã©ã¦ãåã®Apigeeç¡åçã§ãã¹ã¦å®ç¾ã§ãã¾ãã
ï¼ãããéçºä¸ã®Apigeeç»é¢ï¼
Apigeeã§ã®å®è£ ä¸ã®ãã¤ã³ãã¯ä»¥ä¸ã®éãï¼
- SlackããPOSTããããã©ã¼ã ãã¼ã¿ãããã³ã¢APIããè¿ãããJSONå ãã¼ã¿ããã®ãã©ã¡ã¿ã®åå¾ã«ã¯ExtractVariablesポリシーã使ã
- ãã³ã¢APIã¸ã®ãªã¯ã¨ã¹ãããSlackã¸ã®ã¬ã¹ãã³ã¹ã®ä½æã«ã¯AssignMessageポリシーã使ã
- contextã®ä¿åã»èªã¿åºãã«ã¯PopulateCacheポリシーã¨LookupCacheポリシーã使ã
- ãããçºè¨ã«ããç¡éã«ã¼ããé²ãããã«ã¯Conditional Flowã¨RaiseFaultポリシーã使ã
ï¼ãããªã·ã¼ãã¨ããã®ã¯Apigeeç¨èªã§ãããããç¨æãããå¦çé¨åã®ãã¨ï¼
ã¾ã¨ã
Slackã«éãããæè¿ã¯ãã¾ãã¾ãªãµã¼ãã¹ã§WebHookãæä¾ãããããã«ãªã£ã¦ãã¦ãã¾ããApigeeã®æã¤ã¤ã³ã¿ãã§ã¼ã¹å¤ææ©è½ã使ãã°ãèªåã§POSTãåãããµã¼ããã¹ã¯ãªãããç¨æãããã¨ãªãããã¾ãã¾ãªå¥ã®APIã«æ¥ç¶ãããã¨ãã§ãã¾ããï¼ããã§ã¯æ±ãã¾ããã§ãããè¤æ°APIã®ããã·ã¥ã¢ãããå¯è½ï¼
Apigeeã¯æ¬æ¥APIæä¾è ã«API管çã¬ã¤ã¤ãæä¾ãããã®ã§ãããã«æ¸ãããã¼ã«çãªç¨æ³ã¯æ¬è³ªçãªä½¿ãæ¹ã§ã¯ããã¾ããããããWebHookç¨ã®æ¥ç¶ãã¼ã«ã¨ãã¦ã¯ç¹ã«æç¨æ§ãé«ããããããªãã¨æãã¾ããã
ã¡ãªã¿ã«æ¸ãã¦ããéä¸ã§ãé常ã«ããä¼¼ãå
容ã®ããã°è¨äºãè¦ã¤ããã®ã§ãæ¬ã¨ã³ããªã®ã¿ã¤ãã«ã¯æ¬æã表ãã¦ãã¡ãã«ãããã¦ã¿ã¾ããã:-)
Safx: TypetalkのWebhookとNTTドコモの雑談対話APIとGoogle Apps Scriptで雑談ボットをつくる
Slackã§ã¯ãªãnulabããã®TypetalkãApigeeã§ã¯ãªãGoogle Apps Scriptã使ããã¦ãã¾ãããä»çµã¿çã«ã¯ã»ã¨ãã©åãã§ããä¸é¨åèã«ããã¦ããã ãã¾ãããæè¬ï¼