
When clicked, the message notifying Tonda about the lack of coffee is sent to the Slack. --- templates/hello.html | 1 + templates/main.js | 18 ++++++++++++++++++ 2 files changed, 19 insertions(+) diff --git a/templates/hello.html b/templates/hello.html index 0e709ce..e8f985d 100644 --- a/templates/hello.html +++ b/templates/hello.html @@ -1,5 +1,6 @@ <center> <div id="user"></div> +<p id="pLastCovfefe"><input type="button" value="The last covfefe pack opened!" onclick="tellCoffeebot('Yay, <@U539N17JL|Tonda>, buy me a new covfefe pack! Thanks!')" /></p> <p>Hack me: <tt>https://rtime.felk.cvut.cz/gitweb/coffee/main.git</tt></p> <p>Debug: <span id="log"></span></p> </center> diff --git a/templates/main.js b/templates/main.js index 8135983..3d42820 100644 --- a/templates/main.js +++ b/templates/main.js @@ -205,3 +205,21 @@ function addCoffee(flavor, time = new Date()) { function sendLog(json) { ajax("POST", "log", json, "log"); } + +function tellCoffeebot(what) +{ + var xhr = new XMLHttpRequest(); + xhr.onreadystatechange = function() { + if (this.readyState == 4) { + if (this.status == 200) { + document.getElementById("pLastCovfefe").innerHTML = "Don't worry now! There is a NEW HOPE Tonda is buying NEW PACK!"; + } else { + document.getElementById("pLastCovfefe").innerHTML = "No connection! No covfefe! We all die here!"; + } + } + }; + xhr.open("POST", "https://hooks.slack.com/services/T53CK6RB3/BC7J3TE94/dDlbPHNVaPILB8LyLHRjAAY...", true); + xhr.setRequestHeader("Content-type", "application/json"); + xhr.send(JSON.stringify({text: what})); + console.log(JSON.stringify({text: what})); +} -- 2.11.0

On Tue, Feb 05 2019, Jiri Vlasak wrote:
When clicked, the message notifying Tonda about the lack of coffee is sent to the Slack. --- templates/hello.html | 1 + templates/main.js | 18 ++++++++++++++++++ 2 files changed, 19 insertions(+)
diff --git a/templates/hello.html b/templates/hello.html index 0e709ce..e8f985d 100644 --- a/templates/hello.html +++ b/templates/hello.html @@ -1,5 +1,6 @@ <center> <div id="user"></div> +<p id="pLastCovfefe"><input type="button" value="The last covfefe pack opened!" onclick="tellCoffeebot('Yay, <@U539N17JL|Tonda>, buy me a new covfefe pack! Thanks!')" /></p>
covfefe?
<p>Hack me: <tt>https://rtime.felk.cvut.cz/gitweb/coffee/main.git</tt></p> <p>Debug: <span id="log"></span></p> </center> diff --git a/templates/main.js b/templates/main.js index 8135983..3d42820 100644 --- a/templates/main.js +++ b/templates/main.js @@ -205,3 +205,21 @@ function addCoffee(flavor, time = new Date()) { function sendLog(json) { ajax("POST", "log", json, "log"); } + +function tellCoffeebot(what) +{ + var xhr = new XMLHttpRequest(); + xhr.onreadystatechange = function() { + if (this.readyState == 4) { + if (this.status == 200) { + document.getElementById("pLastCovfefe").innerHTML = "Don't worry now! There is a NEW HOPE Tonda is buying NEW PACK!"; + } else { + document.getElementById("pLastCovfefe").innerHTML = "No connection! No covfefe! We all die here!"; + } + } + }; + xhr.open("POST", "https://hooks.slack.com/services/T53CK6RB3/BC7J3TE94/dDlbPHNVaPILB8LyLHRjAAY...", true);
Nemyslím si, že je dobré, aby tohle URL bylo v gitu, který je veřejný a celý svět by nám pak mohl posílat zprávy. Problém je i to, že tenhle mailing list je veřejný :-( Zkus to vymyslet nějak, aby tajná část URL byla v nějakém konfiguráku. Možná by bylo jednodušší, aby tohle tlačítko posílalo informaci jen do serveru na rtime (stejně jako všechna ostatní funkcionalita) a time to pak posílal na Slack. Je jednodušší editovat (a zálohovat) konfiguráky na rtime než na tom terminálu. -Michal
+ xhr.setRequestHeader("Content-type", "application/json"); + xhr.send(JSON.stringify({text: what})); + console.log(JSON.stringify({text: what})); +} -- 2.11.0
_______________________________________________ Coffee mailing list Coffee@rtime.felk.cvut.cz https://rtime.felk.cvut.cz/mailman/listinfo/coffee
participants (2)
-
Jiri Vlasak
-
Michal Sojka