Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
2254f10
feat: timelineと日報の機能を実装
yukimura1227 Sep 5, 2019
2786a9f
feat:trelloのui_noteに投稿するbot作成
Sep 19, 2019
86d9e9d
feat:slackのui_noteとtrelloのui_noteの連携
Sep 19, 2019
8e4defc
doc: README_update
Sep 19, 2019
dbcd782
Merge pull request #1 from gi-no/feat/add_trello_function
shoichinishiguchi Sep 19, 2019
65b76d9
feat:add_link
Sep 30, 2019
3b86619
Merge branch 'master' of github.com:gi-no/servant_botkit
Oct 1, 2019
8bbb026
feat:add_link
Oct 1, 2019
badb600
feat: post_message_for_remote_work
yukimura1227 Oct 7, 2019
fefefc4
Merge pull request #2 from gi-no/feat/post_message_for_remote_work
yukimura1227 Oct 7, 2019
c5ef0a3
feat:lint
Oct 7, 2019
1840106
Merge branch 'master' of github.com:gi-no/servant_botkit
Oct 7, 2019
7c73bb4
feat: exceptionをざっくりとしわける機能を追加してみた
yukimura1227 Jul 20, 2020
fec555e
fix: メッサージの文言でマッチングかけるべきところが誤っていて、落ちてしまっていたのを是正
yukimura1227 Jul 20, 2020
b4b5b30
feat: yarn add date-utils
puriso Aug 3, 2020
a211e48
feat: trelloの登録するカードの概要にsalck urlや投稿日を追加。テンプレもアップデートした。
puriso Aug 3, 2020
2361d73
refact: refact
puriso Aug 3, 2020
8d2ebc1
Merge pull request #3 from gi-no/feat/PAIZA-5246_update_ui_notes_temp…
puriso Aug 4, 2020
4a79f80
fix: fix
puriso Aug 4, 2020
b281b65
Merge branch 'master' of github.com:gi-no/servant_botkit
puriso Aug 4, 2020
ffe2301
feat: 報告月をhashtagとして追加する
puriso Sep 24, 2020
34756ce
Merge pull request #4 from gi-no/feat/add_month_hashtag_to_trello
puriso Sep 25, 2020
e93fd6f
fix: メソッドが新しくなり、古いものが使用できなくなったので変更
shoichinishiguchi Feb 25, 2021
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file added .DS_Store
Binary file not shown.
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
105 changes: 99 additions & 6 deletions index.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
const Botkit = require('botkit');
const Botkit = require('botkit');
const request = require('request');
require('date-utils');

if (!process.env.TOKEN) {
console.log('Error: Specify TOKEN in environment');
Expand Down Expand Up @@ -32,6 +34,10 @@ controller.hears('hi', hearing_event_mention, function(bot,message) {
bot.reply(message,'hi');
});

controller.hears('remote', ['direct_mention'], function(bot, message) {
bot.reply(message, "<!channel> 本日リモートありなので、*今日やろうと思っていること*と、*実際にやったこと*を、このメッセージのスレッドに返信する形で共有しませう");
});

controller.hears('', hearing_event_all, function(bot,message) {
// console.log(bot);
console.log(message);
Expand All @@ -42,14 +48,101 @@ 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/conversations.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('^exceptions$')) {
sort_exception_into_appropriate_channel(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]*)'
const dt = new Date();
const posted_at = '### 投稿日\n'+dt.toFormat("YYYY/MM/DD/ HH24:MI")+'\n';
const msg_url = '### Slack URL\nhttps://paiza.slack.com/archives/C8RRSA2CS/p'+message['event_ts']+'\n'
const msg = message["text"]
const trello_body = '###概要\n'+message["text"].replace( /^title:/g, '')+'\n';
var img_url = ''

var desc = encodeURIComponent(msg+msg_url+posted_at+img_url);
if (channel_name.match(bot_room)){
if(msg.match(key_word_matcher)){
if(message["files"]){
img_url = '### 画像URL\n' + message["files"][0]["url_private"]+'\n'
}
var hashtag = '#' + dt.toFormat("YYYY年MM月") + '報告分';
var title = encodeURIComponent(msg.match(title_matcher)[1] + hashtag);
var desc = encodeURIComponent(trello_body+msg_url+posted_at+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チームのタスクに登録されました。随時取り掛かります。" +'\n' + "https://trello.com/b/jrmkblAB/uinotes")
};
};
}
});
});


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; }
});
});
}

function sort_exception_into_appropriate_channel(bot, post_link, message) {
repost_to_target_channel_postfix = 'others'
if ( message.text.match(/\/manage\//)) {
repost_to_target_channel_postfix = 'manage'
} else if ( message.text.match(/\/business\//)) {
repost_to_target_channel_postfix = 'business'
} else if ( message.text.match(/\/for_team_manage\//)) {
repost_to_target_channel_postfix = 'for_team_manage'
} else if ( message.text.match(/\/works\//)) {
repost_to_target_channel_postfix = 'works'
} else if ( message.text.match(/\/cgc\//)) {
repost_to_target_channel_postfix = 'games'
} else if ( message.text.match(/\/poh\//)) {
repost_to_target_channel_postfix = 'games'
} else if ( message.text.match(/\/codechronicle\//)) {
repost_to_target_channel_postfix = 'games'
}
repost_to(`#exceptions_${repost_to_target_channel_postfix}`, bot, post_link, message);
}

3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
"author": "yukimura1227 <takamura1227@gmail.com>",
"license": "MIT",
"dependencies": {
"botkit": "0.7.4"
"botkit": "0.7.4",
"date-utils": "^1.2.21"
}
}
5 changes: 5 additions & 0 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -1027,6 +1027,11 @@ dashdash@^1.12.0:
dependencies:
assert-plus "^1.0.0"

date-utils@^1.2.21:
version "1.2.21"
resolved "https://registry.yarnpkg.com/date-utils/-/date-utils-1.2.21.tgz#61fb16cdc1274b3c9acaaffe9fc69df8720a2b64"
integrity sha1-YfsWzcEnSzyayq/+n8ad+HIKK2Q=

debug@2.6.9, debug@^2.2, debug@^2.2.0:
version "2.6.9"
resolved "https://registry.yarnpkg.com/debug/-/debug-2.6.9.tgz#5d128515df134ff327e90a4c93f4e077a536341f"
Expand Down