Skip to content

Instantly share code, notes, and snippets.

@shokai
Last active April 19, 2017 22:57
Show Gist options
  • Save shokai/6879cb8852888598763a9c5370170c15 to your computer and use it in GitHub Desktop.
Save shokai/6879cb8852888598763a9c5370170c15 to your computer and use it in GitHub Desktop.
# 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
@shokai
Copy link
Author

shokai commented Jul 8, 2016

project settingsのnotificationsから、 http://your-hubot-url/scrapbox-update を追加する

http://your-hubot-url/scrapbox-update?room=gyazz のようにすると、送信するroomを指定可能

※先にslackにroomを作っておくのを忘れずに

@shokai
Copy link
Author

shokai commented Jul 8, 2016

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment