"", "password"=>"", "redir"=>"", "signin"=>1, "remenber"=>"on" ); $channel = "G0BS0ABBM"; //coffee $username = "sonia"; function file_get_content($url, $fields) { $fields_string = ""; foreach($fields as $key=>$value) { $fields_string .= $key.'='.$value.'&'; } rtrim($fields_string, '&'); $ch = curl_init(); curl_setopt($ch, CURLOPT_URL , $url); if ($fields){ curl_setopt($ch, CURLOPT_POST , count($fields)); curl_setopt($ch, CURLOPT_POSTFIELDS , $fields_string); } curl_setopt($ch, CURLOPT_SSL_VERIFYPEER , FALSE); curl_setopt($ch, CURLOPT_COOKIEFILE , "cookie.txt"); curl_setopt($ch, CURLOPT_COOKIEJAR , "cookie.txt"); curl_setopt($ch, CURLOPT_RETURNTRANSFER , 1); curl_setopt($ch, CURLOPT_FOLLOWLOCATION , true); $result = curl_exec($ch); $datas = curl_getinfo($ch); curl_close($ch); return $result; } /* * * Send a Message to Chan * */ function postMessage($msg, $channel){ global $auth, $username; if (!isset($auth) || empty($auth)) return 0; echo file_get_content("https://slack.com/api/chat.postMessage", array( "token"=>$auth, "channel"=>$channel, "icon_url"=>"http://cook.sndimg.com/content/dam/images/cook/unsized/2010/9/27/0/CC-Avatar_Nadia-G_s48x48.jpg", "text"=>$msg, "username"=> $username))."\n\n"; } /* * * * Read Message last from chan * */ function readMessage($channel){ global $auth; $msg = file_get_content("https://slack.com/api/groups.history", array("token"=>$auth,"channel"=>$channel,"count"=>1)); $msg = json_decode($msg, true); $msg = $msg["messages"][0]; $msg['username'] = UserName($msg['user']); return $msg; } /* * * * Get User Profile * */ function UserName($uid){ global $auth; $usr = file_get_content("https://slack.com/api/users.info", array( "token"=>$auth, "user"=>$uid )); $usr = json_decode($usr, true); return $usr['user']['name']; } /* * * Get Crumb ! */ $crumbs = file_get_content($slackUrl, $user); if (! preg_match('', $crumbs, $data)){ echo "Error Crumb\n"; exit(0);} $user['crumb']=$data[1]; /* * * Get Token * */ $connexion = file_get_content($slackUrl, $user)."_token: 'eeeeee "; if (! preg_match("/_token: '([a-zA-Z0-9^-]{0,50})',/i", $connexion, $data)){ echo "Error Token\n"; exit(0);} $auth = $data[1]; echo $auth; //Main postMessage("Bonjour tout le monde !!!", $channel); while (1){ $message = readMessage($channel); if (preg_match('/(salut|bonjour|helo|hello|hi|\'lut|hey) '.$username.'/i', strtolower($message['text']),$match )){ postMessage("Salut ". $message['username'], $channel); } else if (preg_match('/(ça va|salut ça va|ca va|salut ca va|bien ou bien|hey la forme) '.$username.'/i', strtolower($message['text']),$match )){ postMessage("Bien et toi ". $message['username']." ?", $channel); } else if (preg_match('/(bien et toi|ca va et toi|ça va et toi) '.$username.'/i', strtolower($message['text']),$match )){ postMessage("ca va bien", $channel); } else echo $message['username']." : ".$message['text']."\n"; } ?>