Last active
September 23, 2015 08:59
-
-
Save kakajika/18ac731176b90c8e7eed to your computer and use it in GitHub Desktop.
Hubot script for bridging channel over two teams in Slack.
This file contains 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
# bridgebot.coffee | |
# | |
# Description: | |
# Bot for bridging channel with another Slack team. | |
qs = require 'querystring' | |
bridgeMessage = (robot, userid, username, text) -> | |
return unless text.length > 0 | |
their_channel = process.env.SLACK_BRIDGE_CHANNEL_THEIR ? 'bridge' | |
params = | |
token: process.env.SLACK_API_TOKEN_THEIR | |
text: text | |
channel: "##{their_channel}" | |
username: username | |
icon_url: robot.adapter.client.users[userid].profile.image_48 | |
unfurl_links: true | |
req = robot.http("https://slack.com/api/chat.postMessage?#{qs.stringify(params)}").get() | |
req (err, res, body) -> | |
module.exports = (robot) -> | |
client = robot.adapter.client | |
client.on 'messageSent', (msg) => | |
myself = client.getUserByName robot.name | |
channel = client.getChannelByID msg.channel | |
if channel.name is process.env.SLACK_BRIDGE_CHANNEL_OUR | |
bridgeMessage robot, myself.id, myself.name, msg.text | |
robot.hear /.*?/i, (msg) => | |
channel = msg.envelope.room | |
user = msg.message.user | |
if channel is process.env.SLACK_BRIDGE_CHANNEL_OUR | |
bridgeMessage robot, user.id, user.name, msg.message.text | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment