Created
November 16, 2016 14:25
-
-
Save akiray03/65d7821303ee235550eb452054d61bca 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: | |
| # Listen for a specific title from Qiita:Team | |
| # | |
| # Dependencies: | |
| # None | |
| # | |
| # Configuration: | |
| # HUBOT_QIITA_TEAM | |
| # HUBOT_QIITA_TOKEN | |
| # | |
| # Commands: | |
| # paste a qiita:team link in the presence of hubot | |
| # | |
| # Author: | |
| # akiray03 | |
| module.exports = (robot) -> | |
| team_name = process.env.HUBOT_QIITA_TEAM | |
| if team_name | |
| robot.hear ///#{team_name}\.qiita\.com\/.*\/items///i, (msg) -> | |
| token = process.env.HUBOT_QIITA_TOKEN | |
| pattern = /items\/([0-9a-f]*)/ | |
| robot.logger.info msg.message.text.match(pattern) | |
| item_id = msg.message.text.match(pattern)[1] | |
| url = "https://#{team_name}.qiita.com/api/v2/items/#{item_id}" | |
| msg.http(url).headers("Authorization": "Bearer #{token}").get() (err, res, body) -> | |
| return msg.send "Qiita says: #{err}" if err | |
| try | |
| item = JSON.parse(body) | |
| catch e | |
| return msg.send "Error parsing qiita items body: #{e}" | |
| if process.env.HUBOT_SLACK_TOKEN | |
| robot.emit 'slack-attachment', | |
| channel: msg.message.room, | |
| text: "<#{item.url}|#{item.title}>", | |
| username: 'Qiita', | |
| icon_emoji: ':kobito:' | |
| else | |
| msg.send "#{item.title}: #{item.url}" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment