Currently i'm trying to send a webhook request to discord, so i can send updates to my repository to a channel in my discord server.
If I load the page in my browser, it will run this code just fine, and the message will appear in my discord:
<script>
$(document).ready(function(){
setTimeout(send(), 300);
});
function send(){
var link = "discordwebhooklink";
var hookurl = link + "/slack";
var msgJson
msgJson = {
"username": "",
"icon_url": "",
"text": "Hey! I've got a new project [here](http://repo.mydomain.ca/<?php echo $link; ?>/)!",
"attachments":[{
"author_icon": "",
"author_name": "",
"color": "#ff9900",
"fields": [{
"title": "Repo Project Created!",
"value": "\n----------------------------------------------------------------------------\n```json\nProject Information\n\nTitle:\n \"<?php echo $title; ?>\"\nDescription:\n \"<?php echo $description; ?>\"\nVersion: <?php echo $version; ?>\n```",
}]
}]
};
post(hookurl, msgJson);
}
</script>
<script>
function post(url, jsonmsg){
xhr = new XMLHttpRequest();
xhr.open("POST", url, true);
xhr.setRequestHeader("Content-type", "application/json");
var data = JSON.stringify(jsonmsg);
console.log(jsonmsg);
console.log(data);
xhr.send(data);
xhr.onreadystatechange = function() {
if(this.status != 200){
alert(this.responseText);
}
}
}
</script>
But if i run the page from crontab with php /path/to/file.php
then it doesn't show up in the channel. I've figured out that the cause is that it won't execute javascript, so I'm here asking, how can I run the PHP code, and Javascript code, from bash. (Note: jQuery is included in the outputted html from the php script)
I also tried doing a pure PHP solution, but couldn't get the messages to appear in my channel either. I tried a few PHP solutions that used CURL, stream_context_create, and include, but I don't understand any of the solutions given, so it could be a fault on my part.
TL;DR: How do I use crontab to execute a .php file that outputs javascript, and have the outputted javascript be executed, not just printed.
Edit: Flagged as duplicate, but i said i couldn't figure out cURL solutions.