Time by time in ideato, like in other IT and not-IT companies, someone needs a hug.
We have to manage on daily basis complex tasks, sometimes also quite frustrating, to talk with customers with lot of confuses ideas and deal with the bleeding edge technologies with no documentation.
Since we chose to adopt a remote office approach, do a proper hug is quite difficult. That’s why we created a proper channel (#abbracciatone, aka big hugs) on slack.
We also are lazy and looking every time for a hug image on google is a pain. To clear this pain I wrote a very little script for slack using a web service (this the Json endpoint url) created with kimono lab and the slack API to send a random hug image on the channel triggered by the command /hugs.
If you want to create your own hugs-bot this is the code you can start from:
<?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]); | |
?> |