61 lines
No EOL
2 KiB
JavaScript
61 lines
No EOL
2 KiB
JavaScript
(function () {
|
|
var APP_NAME = "SL∀ƆK";
|
|
var APP_IMAGE = "https://hifi-content.s3.amazonaws.com/liv/dev/SlackMeApp/Slack_Mark_White_Web.png"
|
|
var APP_URL = "https://hifi-content.s3.amazonaws.com/liv/dev/SlackMeApp/SlackMe.html";
|
|
var SLACK_HOOK = Settings.getValue("slackHook"); // Set your slack hook URL for your desired integration
|
|
|
|
var tablet = Tablet.getTablet("com.highfidelity.interface.tablet.system");
|
|
|
|
var button = tablet.addButton({
|
|
text: APP_NAME,
|
|
icon: APP_IMAGE
|
|
});
|
|
|
|
function onClicked() {
|
|
tablet.gotoWebScreen(APP_URL);
|
|
}
|
|
button.clicked.connect(onClicked);
|
|
|
|
// Process event from tablet UI
|
|
function onWebEventReceived(event) {
|
|
if (typeof event === "string") {
|
|
event = JSON.parse(event);
|
|
};
|
|
|
|
if (event.type === "click") {
|
|
var data = formSlackRequestData(event);
|
|
print(JSON.stringify(data));
|
|
var xhr = new XMLHttpRequest();
|
|
xhr.open("POST", SLACK_HOOK, true);
|
|
xhr.onreadystatechange = function () {
|
|
if (xhr.readyState == 4) {
|
|
if (xhr.status == 200) {
|
|
print("200!");
|
|
} else {
|
|
print("A Problem Has Occurred: " + xhr.status + ": " + xhr.responseText);
|
|
}
|
|
}
|
|
}
|
|
xhr.setRequestHeader("Content-Type", "application/json");
|
|
xhr.send(JSON.stringify(data));
|
|
}
|
|
}
|
|
|
|
function formSlackRequestData(event) {
|
|
return {text : event.data + '\n' + formSignature(),
|
|
channel : "@" + event.sendTo};
|
|
}
|
|
|
|
function formSignature() {
|
|
return "Sent by " + Account.username + " in " + "<" + location.href + "|" + location.placename + ">";
|
|
}
|
|
|
|
tablet.webEventReceived.connect(onWebEventReceived);
|
|
|
|
// Clean Up when Unloaded
|
|
function cleanup() {
|
|
tablet.removeButton(button);
|
|
};
|
|
Script.scriptEnding.connect(cleanup);
|
|
|
|
})(); |