Last active
April 19, 2017 22:57
-
-
Save shokai/6879cb8852888598763a9c5370170c15 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Description: | |
# hubot scrapbox notification | |
# | |
# Author: | |
# @shokai <[email protected]> | |
config = | |
room: "news" | |
header: ":sake:" | |
module.exports = (robot) -> | |
robot.router.post '/scrapbox-update', (req, res) -> | |
{text, attachments, mrkdwn, username} = req.body | |
unless text && attachments && attachments.length > 0 && mrkdwn && username | |
return res.status(400).send 'bad request' | |
room = req.query.room or config.room | |
res.end 'ok' | |
for att in attachments | |
if att.title_link | |
link = decodeURI(att.title_link).replace(/ /g, '%20') | |
text = "#{config.header} #{link}\n" | |
text += replace_slackMarkup(att.text.trim()) if att.text | |
robot.send {room}, text | |
if att.image_url | |
robot.send {room}, att.image_url | |
replace_slackMarkup = (str) -> | |
str.replace /<([^<>\|]+)\|([^<>\|]+)>/g, (_, url, title) -> | |
return url if url is title | |
return "【#{title}】 "if /https?:\/\/scrapbox.io/.test(url) | |
url = url.replace(/ /g, '%20') if /https?:\/\/.+/.test(url) | |
return url + ' ' + title |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
project settingsのnotificationsから、
http://your-hubot-url/scrapbox-update
を追加するhttp://your-hubot-url/scrapbox-update?room=gyazz
のようにすると、送信するroomを指定可能※先にslackにroomを作っておくのを忘れずに