From 2254f10b9877e4dfc845091c578f8d13ee888825 Mon Sep 17 00:00:00 2001 From: yukimura1227 Date: Fri, 6 Sep 2019 01:35:37 +0900 Subject: [PATCH 1/4] =?UTF-8?q?feat:=20timeline=E3=81=A8=E6=97=A5=E5=A0=B1?= =?UTF-8?q?=E3=81=AE=E6=A9=9F=E8=83=BD=E3=82=92=E5=AE=9F=E8=A3=85?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- index.js | 36 ++++++++++++++++++++++++++++++------ 1 file changed, 30 insertions(+), 6 deletions(-) diff --git a/index.js b/index.js index 8da4fa0..cf6b963 100644 --- a/index.js +++ b/index.js @@ -1,4 +1,5 @@ const Botkit = require('botkit'); +const request = require('request') if (!process.env.TOKEN) { console.log('Error: Specify TOKEN in environment'); @@ -34,7 +35,6 @@ controller.hears('hi', hearing_event_mention, function(bot,message) { controller.hears('', hearing_event_all, function(bot,message) { // console.log(bot); - console.log(message); var id = message.client_msg_id; var slack_team = process.env.SLACK_TEAM; var channel_id = message.channel; @@ -42,14 +42,38 @@ controller.hears('', hearing_event_all, function(bot,message) { event_ts = event_ts.replace('.','') var url_parameter = `?thread_ts=${message.thread_ts}&cid=${channel_id}` var post_link = `https://${slack_team}.slack.com/archives/${channel_id}/p${event_ts}` - var channel_from_id + var URL = `https://slack.com/api/channels.info?token=${process.env.TOKEN}&channel=${channel_id}` + request(URL, (error, response, body) => { + if (!error && response.statusCode == 200) { + let channel_info = JSON.parse(body); + // console.log(channel_info); + var channel_name = channel_info.channel.name; + + if(channel_name.match('^times_.+')) { + repost_to('#timeline', bot, post_link, message); + } + + if (channel_name.match('^日報_(.*)$') && channel_name.match('_').length === 1/* && username !== 'slackbot'*/) { + repost_to('#日報_all', bot, post_link, message); + } + + if (channel_name.match('^日報_(.*)_.+')) { + matcher = channel_name.match('^日報_(.*)_.+'); + repost_to(`#日報_${matcher[1]}`, bot, post_link, message); + repost_to('#日報_all', bot, post_link, message); + } + } + }); +}); + +function repost_to(channel, bot, post_link, message) { + console.log(message); bot.api.chat.postMessage({ text: `${post_link}`, - channel: '#random', - as_user: false, - username: bot.identity.name, + channel: channel, + as_user: true, unfurl_links: true }, function(err, message){ if(err) { console.log("err: ", err); return; } }); -}); +} From 2786a9f79e39c61c2d8eb47dc238093373964fe6 Mon Sep 17 00:00:00 2001 From: shoichinishiguchi Date: Thu, 19 Sep 2019 09:46:52 +0900 Subject: [PATCH 2/4] =?UTF-8?q?feat:trello=E3=81=AEui=5Fnote=E3=81=AB?= =?UTF-8?q?=E6=8A=95=E7=A8=BF=E3=81=99=E3=82=8Bbot=E4=BD=9C=E6=88=90?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- index.js | 59 +++++++++++++++++++++++++++++++++++++++++++++----------- 1 file changed, 48 insertions(+), 11 deletions(-) diff --git a/index.js b/index.js index cf6b963..926c4b9 100644 --- a/index.js +++ b/index.js @@ -35,6 +35,7 @@ controller.hears('hi', hearing_event_mention, function(bot,message) { controller.hears('', hearing_event_all, function(bot,message) { // console.log(bot); + console.log(message); var id = message.client_msg_id; var slack_team = process.env.SLACK_TEAM; var channel_id = message.channel; @@ -49,23 +50,59 @@ controller.hears('', hearing_event_all, function(bot,message) { // console.log(channel_info); var channel_name = channel_info.channel.name; - if(channel_name.match('^times_.+')) { - repost_to('#timeline', bot, post_link, message); - } + // if(channel_name.match('^times_.+')) { + // repost_to('#timeline', bot, post_link, message); + // } + + // if (channel_name.match('^日報_(.*)$') && channel_name.match('_').length === 1/* && username !== 'slackbot'*/) { + // repost_to('#日報_all', bot, post_link, message); + // } + + // if (channel_name.match('^日報_(.*)_.+')) { + // matcher = channel_name.match('^日報_(.*)_.+'); + // repost_to(`#日報_${matcher[1]}`, bot, post_link, message); + // repost_to('#日報_all', bot, post_link, message); + // } + + - if (channel_name.match('^日報_(.*)$') && channel_name.match('_').length === 1/* && username !== 'slackbot'*/) { - repost_to('#日報_all', bot, post_link, message); - } + const key = "7baa756dc6314bb4a1b7e3019602d0dc"; + const token="e4528b014c42038225b7324a5af99f508b1f4f5cdb1972462dcc2651323032a7"; + const ui_note="5d6e1bd5bf1ddb7a6ac7814c"; + const list_new_id="5d6e3b0cbdc0466c9eb05c85"; + const bot_room = '西口bot実験室' + const key_word_matcher = '^title:.*' + const title_matcher = '^title:([^\n]*)' + var msg = message["text"]; - if (channel_name.match('^日報_(.*)_.+')) { - matcher = channel_name.match('^日報_(.*)_.+'); - repost_to(`#日報_${matcher[1]}`, bot, post_link, message); - repost_to('#日報_all', bot, post_link, message); - } + + if (channel_name.match(bot_room)){ + if(msg.match(key_word_matcher)){ + if(message["files"]==null){ + var img_url = "" + }else{ + var img_url = message["files"][0]["url_private"]; + }; + var title = encodeURIComponent(msg.match(title_matcher)[1]); + var desc = encodeURIComponent(msg+'\n'+img_url); + var url = `https://trello.com/1/cards?key=${key}&token=${token}&idList=${list_new_id}&name=${title}&desc=${desc}`; + var webclient = require("request"); + webclient.post({ + url: url, + headers: { + "content-type": "application/json" + } + }, function (error, response, body){}); + + bot.reply(message,"uiチームのタスクに登録されました。随時取り掛かります。") + + }; + }; } }); }); + function repost_to(channel, bot, post_link, message) { console.log(message); bot.api.chat.postMessage({ From 86d9e9d0d755436576e556be4bd5a9377abb8d4e Mon Sep 17 00:00:00 2001 From: shoichinishiguchi Date: Thu, 19 Sep 2019 13:36:28 +0900 Subject: [PATCH 3/4] =?UTF-8?q?feat:slack=E3=81=AEui=5Fnote=E3=81=A8trello?= =?UTF-8?q?=E3=81=AEui=5Fnote=E3=81=AE=E9=80=A3=E6=90=BA?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- index.js | 40 +++++++++++++++++++--------------------- 1 file changed, 19 insertions(+), 21 deletions(-) diff --git a/index.js b/index.js index 926c4b9..580d93d 100644 --- a/index.js +++ b/index.js @@ -50,27 +50,25 @@ controller.hears('', hearing_event_all, function(bot,message) { // console.log(channel_info); var channel_name = channel_info.channel.name; - // if(channel_name.match('^times_.+')) { - // repost_to('#timeline', bot, post_link, message); - // } - - // if (channel_name.match('^日報_(.*)$') && channel_name.match('_').length === 1/* && username !== 'slackbot'*/) { - // repost_to('#日報_all', bot, post_link, message); - // } - - // if (channel_name.match('^日報_(.*)_.+')) { - // matcher = channel_name.match('^日報_(.*)_.+'); - // repost_to(`#日報_${matcher[1]}`, bot, post_link, message); - // repost_to('#日報_all', bot, post_link, message); - // } - - - - const key = "7baa756dc6314bb4a1b7e3019602d0dc"; - const token="e4528b014c42038225b7324a5af99f508b1f4f5cdb1972462dcc2651323032a7"; - const ui_note="5d6e1bd5bf1ddb7a6ac7814c"; - const list_new_id="5d6e3b0cbdc0466c9eb05c85"; - const bot_room = '西口bot実験室' + if(channel_name.match('^times_.+')) { + repost_to('#timeline', bot, post_link, message); + } + + if (channel_name.match('^日報_(.*)$') && channel_name.match('_').length === 1/* && username !== 'slackbot'*/) { + repost_to('#日報_all', bot, post_link, message); + } + + if (channel_name.match('^日報_(.*)_.+')) { + matcher = channel_name.match('^日報_(.*)_.+'); + repost_to(`#日報_${matcher[1]}`, bot, post_link, message); + repost_to('#日報_all', bot, post_link, message); + } + + const key = process.env.TRELLO_KEY; + const token=process.env.TRELLO_TOKEN; + const ui_note=process.env.TRELLO_UI_NOTE; + const list_new_id=process.env.TRELLO_LIST_NEW_ID; + const bot_room = 'ui_notes' const key_word_matcher = '^title:.*' const title_matcher = '^title:([^\n]*)' var msg = message["text"]; From 8e4defc5a31eabcd9c15beaa8afe4db629ad7d67 Mon Sep 17 00:00:00 2001 From: shoichinishiguchi Date: Thu, 19 Sep 2019 14:52:36 +0900 Subject: [PATCH 4/4] doc: README_update --- README.md | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/README.md b/README.md index ed80534..3a5d78f 100644 --- a/README.md +++ b/README.md @@ -28,6 +28,10 @@ heroku login heroku create servant-botkit heroku config:set SLACK_TEAM=[your team name] heroku config:set TOKEN=[your token] +heroku config:set TRELLO_KEY=[your token] +heroku config:set TRELLO_TOKEN=[your token] +heroku config:set TRELLO_UI_NOTE=[your token] +heroku config:set TRELLO_LIST_NEW_ID=[your token] ``` ### heroku config