Skip to content

Instantly share code, notes, and snippets.

@jakemauer
Last active March 7, 2019 00:21
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jakemauer/578dc47811ed7feac5987bd6795a444a to your computer and use it in GitHub Desktop.
Save jakemauer/578dc47811ed7feac5987bd6795a444a to your computer and use it in GitHub Desktop.
// By default the script will have hubot listen for sentences starting with "feedback" and submit
// whatever follows to prodpad as a feedback item. You can adjust the listen word on line 28.
// If you want to scope the listener to a single channel (room),
// set the feedbackRoomId env var. It can be found by looking at
// the end of the URL when you visit a slack channel in the browser.
var prodpadKey = process.env.PRODPAD_API_KEY,
feedbackRoomId = process.env.FEEDBACK_ROOM_ID, // e.g. C0PFAF5QRS
errorMessage = process.env.PRODSLACK_ERROR_MESSAGE,
successMessage = process.env.PRODSLACK_SUCCESS_MESSAGE;
module.exports = function(robot) {
var sendFeedback = function(feedbackData, slackRes) {
var data = JSON.stringify(feedbackData);
robot.http("https://api.prodpad.com/v1/feedbacks")
.header('Content-Type', 'application/json')
.header('Authorization', `Bearer ${prodpadKey}`)
.post(data)(function(err, res, body) {
if (err) {
return slackRes.reply(errorMessage || `Well dang, there was an error sending your feedback:\n ${err}`)
}
return slackRes.reply(successMessage || "Your feedback was successfully added to ProdPad")
});
};
robot.hear(/^feedback (.*)/i, function(res) {
var feedbackData = {
name: res.message.user.real_name,
email: res.message.user.email_address,
feedback: res.match[1],
}
var messageRoomId = res.message.room;
if(!feedbackRoomId || feedbackRoomId === messageRoomId){
return sendFeedback(feedbackData, res);
}
})
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment