Skip to content

Instantly share code, notes, and snippets.

@SeanPlusPlus
Created June 23, 2017 19:44
Show Gist options
  • Save SeanPlusPlus/4496a9f9f52f09ab7efec31773333953 to your computer and use it in GitHub Desktop.
Save SeanPlusPlus/4496a9f9f52f09ab7efec31773333953 to your computer and use it in GitHub Desktop.
const request = require('request')
const moment = require('moment-timezone')
exports.handler = function(event, context, callback) {
const SLACK_CHANNEL = process.env.SLACK_CHANNEL
const channel = SLACK_CHANNEL
const icon_emoji = ':robot_face:'
const username = 'stokebot'
const fallback = 'Required plain-text summary!'
const color = '#36a64f'
const pretext = 'Optional text that appears above the attachment block!!!'
const author_name = 'Bobby D. Tables'
const author_link = 'http://flickr.com/bobby/'
const title = 'Slack API Documentation'
const title_link = 'https://api.slack.com/'
const text = 'Optional text that appears within the attachment'
const image_url = 'http://my-website.com/path/to/image.jpg'
const thumb_url = 'http://example.com/path/to/thumb.png'
const footer = 'Slack API'
const footer_icon = 'https://platform.slack-edge.com/img/default_application_icon.png'
const ts = moment().unix()
const priority = {
title: 'Priority',
value: 'High',
short: true,
}
const status = {
title: 'Status',
value: 'Open',
short: true,
}
const fields = [
priority,
status,
]
const callback_id = 'foobar'
const attachments = [{
fallback,
color,
pretext,
author_name,
author_link,
title,
title_link,
text,
image_url,
thumb_url,
footer,
footer_icon,
ts,
fields,
}]
const json = {
attachments,
channel,
icon_emoji,
username,
}
// build the options
const SLACK_WEB_HOOK_URL = process.env.SLACK_WEB_HOOK_URL
const uri = SLACK_WEB_HOOK_URL
const method = 'POST'
const options = {
uri,
method,
json,
}
request.post(options, (err, response, body) => {
return callback(null, {
statusCode: '200',
body: 'foo bar',
headers: { 'Content-Type': 'application/json' },
})
})
}
// errs out with:
// {
// "errorMessage": "2017-06-23T19:43:26.155Z 33228baa-584c-11e7-90a6-4964d19fb68f Task timed out after 10.00 seconds"
// }
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment