-
-
Save fullo/1a366b6dc08691fa2925 to your computer and use it in GitHub Desktop.
free hugs dispenser
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
class slack { | |
/** | |
* $message is the text (plus image link) you want to send to slack room | |
* $room is the room where the message has to be sent | |
* $icon is the icon | |
* $username is the name of the bot | |
*/ | |
public static function send($message, $room = "abbracciatone", $icon = ":hugme:", $username = "love dispenser") | |
{ | |
$room = ($room) ? $room : "abbracciatone"; | |
$data = "payload=" . json_encode(array( | |
"channel" => "#{$room}", | |
"text" => $message, | |
"icon_emoji" => $icon, | |
"unfurl_links" => true, | |
"username" => $username | |
)); | |
$ch = curl_init( YOUR_SLACK_URI ); | |
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "POST"); | |
curl_setopt($ch, CURLOPT_POSTFIELDS, $data); | |
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); | |
$result = curl_exec($ch); | |
curl_close($ch); | |
return $result; | |
} | |
} | |
$kimono_key = "PUT HERE YOUR KIMONO PRIVATE KEY" | |
// the webservice written with kimonolabs retrieve all the images from google with the query "animal hug" | |
$data = file_get_contents('https://www.kimonolabs.com/api/aj7qd51y?apikey='.$kimono_key); | |
$response = json_decode($data); | |
$images = $response->results->images; | |
shuffle($images); | |
// since the href attribute of google image search is pretty messy | |
// i need to clean all the not needed information to retrieve only the image url | |
$url = parse_url($images[0]->info->href); | |
$query = explode('&', $url['query']); | |
$image = explode('=', $query[0]); | |
echo slack::send("Showing some love ". $image[1]); | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment