forked from looker/lookerbot
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Schedule Looks to a Slack Channel (looker#53)
* working scheduler * show look title when receiving scheduled look * verify token and docs * Scheduled messages don't have a loading indicator, why distract everything? * fix linkText * allow posting to dms and groups * making expanding urls optional * update readme for new slack urls * don't expand urls by default * enable loading messages by default * just one look query runner
- Loading branch information
Showing
6 changed files
with
107 additions
and
25 deletions.
There are no files selected for viewing
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
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
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
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
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
ReplyContext = require('./reply_context') | ||
LookQueryRunner = require('./repliers/look_query_runner') | ||
|
||
module.exports = | ||
|
||
listen: (server, bot, lookers) -> | ||
server.post("/slack/post/:post_type/:channel_name", (req, res) => | ||
|
||
reply = (json) -> | ||
res.setHeader 'Content-Type', 'application/json' | ||
res.send JSON.stringify(json) | ||
console.log("Replied to scheduled plan webhook.", json) | ||
|
||
if req.body.scheduled_plan | ||
if req.body.scheduled_plan.type == "Look" | ||
if matches = req.body.scheduled_plan.url.match(/\/looks\/([0-9]+)$/) | ||
lookId = matches[1] | ||
|
||
channelName = req.params.channel_name | ||
channelType = req.params.post_type | ||
if channelType == "dm" | ||
channelName = "@#{channelName}" | ||
else if channelType == "channel" | ||
channelName = "##{channelName}" | ||
|
||
for looker in lookers | ||
if req.body.scheduled_plan.url.lastIndexOf(looker.url, 0) == 0 | ||
if req.headers['x-looker-webhook-token'] == looker.webhookToken | ||
context = new ReplyContext(bot, bot, { | ||
channel: channelName | ||
}) | ||
context.looker = looker | ||
context.scheduled = true | ||
runner = new LookQueryRunner(context, lookId) | ||
runner.start() | ||
reply {success: true, reason: "Sending Look #{lookId} to channel #{channelName}."} | ||
else | ||
reply {success: false, reason: "Invalid webhook token."} | ||
|
||
else | ||
reply {success: false, reason: "Unknown scheduled plan URL."} | ||
else | ||
reply {success: false, reason: "Scheduled plan type #{req.body.scheduled_plan.type} not supported."} | ||
else | ||
reply {success: false, reason: "No scheduled plan in payload."} | ||
) |