slackに書き込まれたものをhubotでLINE Notifyで送る


TL;DR

  • slackの特定のchannelに書き込まれたテキストをLINE NotifyでLINEにおくる
  • LINE Notifyのaccess_tokenは適宜取得する

script

line_notify.coffee

# Description:
#   Line Notify bot
#
# Commands:
#  target channel hear
#
# Author:
#   tknzk

module.exports = (robot) ->

  robot.hear /.*/, (res) ->
    room = res.envelope.room
    text = res.message.text
    console.log room
    console.log text

    if room == 'TARGET CHANNEL'

      request = res.http("https://notify-api.line.me/api/notify")
        .headers("Authorization": "Bearer " + process.env.HUBOT_LINE_NOTIFY_API_TOKEN)
        .headers("Content-Type": 'application/x-www-form-urlencoded')
        .post("message=" + text)
      request (err, resp, body) ->
        if err
          res.send err
        else
          if body.length == 0
            res.send "Failed "
          else
            res.send body