LoginSignup
3
2

More than 5 years have passed since last update.

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

Last updated at Posted at 2016-12-01

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
3
2
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
3
2