HipChat::say PHP Method

say() public static method

Send a notification to a HipChat room.
public static say ( string $message = '', string $color = "green" )
$message string
$color string
    public static function say($message = '', $color = "green")
    {
        if (!c('HipChat.Token') || !c('HipChat.Account')) {
            return;
        }
        // Prepare our API endpoint.
        $url = sprintf('https://%1$s.hipchat.com/v2/room/%2$s/notification?auth_token=%3$s', c('HipChat.Account'), c('HipChat.Room'), c('HipChat.Token'));
        $data = ["color" => $color, "message" => $message, "notify" => false, "message_format" => "html"];
        $data = json_encode($data);
        $ch = curl_init();
        curl_setopt($ch, CURLOPT_URL, $url);
        curl_setopt($ch, CURLOPT_HTTPHEADER, ["Content-Type: application/json"]);
        curl_setopt($ch, CURLOPT_POST, 1);
        curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
        curl_setopt($ch, CURLOPT_TIMEOUT, 5);
        curl_exec($ch);
        curl_close($ch);
    }

Usage Example

Esempio n. 1
0
 /**
  * Post every new registration to HipChat.
  *
  * @param UserModel $sender
  * @param array $args
  */
 public function userModel_afterInsertUser_handler($sender, $args)
 {
     // Determine how to link their name.
     $name = val('Name', $args['InsertFields']);
     if (c('Garden.Registration.Method') == 'Approval') {
         $user = anchor($name, '/user/applicants', '', array('WithDomain' => true));
         $reason = sliceParagraph(val('DiscoveryText', $args['InsertFields']));
         $message = sprintf(t('New member: %1$s (%2$s)'), $user, $reason);
     } else {
         // Use conservative name linking structure.
         $user = anchor($name, '/profile/' . $args['InsertUserID'] . '/' . $name, '', array('WithDomain' => true));
         $message = sprintf(t('New member: %1$s'), $user);
     }
     // Say it.
     HipChat::say($message);
 }
All Usage Examples Of HipChat::say
HipChat