Created
April 26, 2020 06:02
-
-
Save ismaelc/8071f9f36d72dd63b545a530089ed9c6 to your computer and use it in GitHub Desktop.
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
var buildReply = async function (msg, token, thread, url) { | |
var channel = msg.event.channel | |
// Check if URL exists | |
if (url.length > 0) { | |
// Load the AWS SDK for Node.js | |
var AWS = require('aws-sdk'); | |
AWS.config.update({ | |
region: 'us-east-1' | |
}) | |
// Create an SQS service object | |
var sqs = new AWS.SQS({ | |
apiVersion: '2012-11-05' | |
}) | |
// Payload for SQS. | |
var params = { | |
MessageAttributes: { | |
"Thread": { | |
DataType: "String", | |
StringValue: thread | |
}, | |
"Channel": { | |
DataType: "String", | |
StringValue: channel | |
}, | |
"URL": { | |
DataType: "String", | |
StringValue: url | |
}, | |
"Token": { | |
DataType: "String", | |
StringValue: token | |
} | |
}, | |
MessageBody: `Message via SQS from Slack bot`, | |
QueueUrl: "https://sqs.us-east-1.amazonaws.com/<some number>/summarizer-slack-to-summarizer" | |
}; | |
// Send the payload to SQS | |
let sm = await sqs.sendMessage(params).promise(); | |
// Empty reply | |
reply = `` | |
} | |
// No URL, show a help message | |
else { | |
reply = 'Type `@tldr` alongside a URL, or as thread to a URL. Direct message works too.' | |
} | |
return reply | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment