Skip to content

Instantly share code, notes, and snippets.

@lajlev
Created May 25, 2016 12:07
Show Gist options
  • Save lajlev/4e0bb7d7edbeaa757353f7311ecb5bda to your computer and use it in GitHub Desktop.
Save lajlev/4e0bb7d7edbeaa757353f7311ecb5bda to your computer and use it in GitHub Desktop.
A Slack - slash command for frokost.dk
<?php
// Create a new slack slash command https://my.slack.com/services/new/slash-commands
header('Content-Type: application/json; charset=utf-8');
# Grab token from the slash command.
$token = $_POST['token'];
# Check the token and make sure the request is from our team
if($token != '[insert-your-slash-token]'){ #replace this with the token from your slash command configuration page
$msg = "The token for the slash command doesn't match. Check your script.";
die($msg);
echo $msg;
}
$url = "http://e.frokost.dk/Menuplan/RssMenu.aspx?l=aN57ULa4f_";
$xml = simplexml_load_file($url);
$title = "Dagens menu fra " . $xml->channel->item[0]->title;
$link = $xml->channel->item[0]->link;
$description = $xml->channel->item[0]->description;
$description = html_entity_decode($description);
$description = str_replace(array('<b>', '</b>', '<br/><br/>', '<br/>'), array("*", ":* ", "\n", ""), $description);
$menu = array("text" => "");
$menu[attachments] = array(array("color" => "c0392b", "title" => $title, "title_link" => $url, "text" => $description, "mrkdwn_in" => ["text","fields"]));
echo json_encode($menu);
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment