Skip to content
Open
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 15 additions & 7 deletions scripts/wail.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,22 @@
# csoni111

module.exports = (robot) ->
robot.respond /who.*lab/i, (msg) ->
waliUrl = process.env.WAIL_PIC_URL + '?t=' + new Date().getTime()
msg.send(
"attachments": [
robot.respond /who.*lab/i, (msg) ->
waliUrl = process.env.WAIL_PIC_URL + '?t=' + new Date().getTime()
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please correct the typo, wali wail .

wailTextUrl = process.env.WAIL_NAME_URL + '?t=' + new Date().getTime()
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Add WAIL_NAME_URL to the configuration on the top of this script.


request = require 'request'
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There's no request package defined in dependencies in package.json. Instead you could use robot.http() to make a http call. Check here.


resp = ""
request.get {uri:'#{wailTextUrl}'}, (err, r, body) ->
resp = body

msg.send(
"attachments": [
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

please test the script locally once, I sense there's some indentation error.

"fallback": "Here's a pic: #{waliUrl}"
"color": "#36a64f"
"pretext": "Here's a pic:"
"pretext": "#{resp} \n Here's a pic:"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

msg.send will be sent before the resp is fetched, since request.get makes an asynchronous call.
So it will send empty message to slack.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Add the complete message to fallback too. In case the attachment message fails, slack displays the fallback text.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

when it fails, will the response be null?

"image_url": waliUrl
"ts": new Date().getTime() / 1000
]
)
]
)