Skip to content

Instantly share code, notes, and snippets.

@jumpingdeeps
Last active August 29, 2015 14:22
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 jumpingdeeps/a4cd639ea8453b09d422 to your computer and use it in GitHub Desktop.
Save jumpingdeeps/a4cd639ea8453b09d422 to your computer and use it in GitHub Desktop.
Wootric-Slack.js
  • Log into your Slack channel
  • Click in configure integrations
  • Click on Incoming Webhooks and Add a new one
  • Copy the Webhook URL e.g. https://hooks.slack.com/services/
  • Set the response_callback in wootricSettings to window.woolib.notifySlack as well as the slack_hook_url

    Example:

window.wootricSettings = {
  email:'nps@example.com',
  created_at: 1234567890,
  product_name: 'Wootric',
  account_token: 'NPS-xxxxxxx',
  slack_hook_url: 'https://hooks.slack.com/services/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',
  response_callback: window.woolib.notifySlack,
};
window.woolib = {
post: function (url, data, success, error) {
var request = new XMLHttpRequest();
request.onreadystatechange = function() {
if (request.readyState == 4) {
if (request.status == 200 && success) {
success(request.responseText);
}
else if (error) {
error(request.responseText);
}
}
};
request.open("POST", url, true);
request.send(JSON.stringify(data));
},
notifySlack: function(score, comment) {
// TODO: response_callback is getting called upon page load
// (thus we are checking comment as well as a hack)
if (comment && +score > 8 ) {
slackPayload = {
username: "wootbot",
channel: "#bot",
attachments: [
{
pretext: "*You got a new promoter!*",
text: comment,
mrkdwn_in: ["text", "pretext"],
color: "good",
}
]
}
window.woolib.post(this.slack_hook_url, slackPayload, function (response) {});
}
}
}
// wootric_survey_immediately = true; //Use for testing
window.wootricSettings = {
email:'nps@example.com',
created_at: 1234567890,
product_name: 'Wootric',
account_token: 'NPS-xxxxxxxx',
slack_hook_url: 'https://hooks.slack.com/services/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',
response_callback: window.woolib.notifySlack,
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment