예제 #1
0
 private function sendAlert($feedItem, $application)
 {
     $client = new HipChat($this->config['hipchat_auth_token']);
     $message = sprintf("%s\n%s\n\n%s", $feedItem->title, $feedItem->link, $feedItem->description);
     $client->message_room($this->config['hipchat_channel_id'], $application, $message, true, HipChat::COLOR_RED, HipChat::FORMAT_TEXT);
     $this->rememberItem($feedItem);
 }
예제 #2
0
 public function sendHipchatMessage($message, $color = HipChat::COLOR_YELLOW, $notify = true)
 {
     if (is_null($this->hipchatClient)) {
         return false;
     }
     $this->hipchatClient->message_room($this->hipchatClient->drunkenRoom, $this->hipchatClient->drunkenFrom, $message, $notify, $color);
 }
예제 #3
0
 /**
  * @param \Namshi\Notificator\Notification\HipChat\HipChatNotification $hipChatNotification
  * @param \HipChat\HipChat $hipChatClient
  */
 function it_handles_hipchat_notifications($hipChatNotification, $hipChatClient)
 {
     $hipChatNotification->getParameter(Argument::any())->willReturn('something');
     $hipChatNotification->getHipChatRoom()->willReturn('something');
     $hipChatNotification->getHipChatSenderId()->willReturn('someId');
     $hipChatNotification->getMessage()->willReturn('something');
     $hipChatClient->message_room('something', 'someId', 'something', 'something', 'something', 'something')->shouldBeCalled();
     $this->handle($hipChatNotification);
 }
예제 #4
0
 /**
  * {@inheritdoc}
  */
 public function send($message, array $options)
 {
     try {
         return $this->client->message_room($this->room, $this->user, $message, false, $options['color']);
     } catch (\HipChat\HipChat_Exception $e) {
         $this->logger->error($e);
         return false;
     }
 }
 /**
  * Create a HipChat instance and send the notification
  *
  * @param  User                $user
  * @param  Notification        $notification
  * @param  NotificationContent $content
  * @return bool
  */
 public function sendNotification(User $user, Notification $notification, NotificationContent $content)
 {
     $hipChat = new HipChat($this->_config['api_key'], $this->_config['endpoint']);
     $message = $content->render('hipchat_message', $notification);
     $room = isset($notification->transport_config['room']) ? $notification->transport_config['room'] : $this->_config['defaultRoom'];
     $sentFrom = isset($notification->transport_config['sentFrom']) ? $notification->transport_config['sentFrom'] : $this->_config['defaultSentFrom'];
     $messageFormat = isset($notification->transport_config['messageFormat']) ? $notification->transport_config['messageFormat'] : HipChat::FORMAT_TEXT;
     $textColor = isset($notification->transport_config['textColor']) ? $notification->transport_config['textColor'] : HipChat::COLOR_YELLOW;
     return $hipChat->message_room($room, $sentFrom, $message, false, $textColor, $messageFormat);
 }
예제 #6
0
 public function Run($input)
 {
     $roomid = $this->resolveParameter('roomid', $input);
     $apitoken = $this->resolveParameter('apitoken', $input);
     $message = $this->resolveParameter('message', $input);
     $fromname = $this->resolveParameter('fromname', $input);
     echo "\n### SendMessageAction: [{$roomid}] " . $message . "\n{$fromname}\n";
     $hc = new HipChat\HipChat($apitoken);
     $hc->message_room($roomid, $fromname, $message);
 }
예제 #7
0
 /**
  * Handle a notification
  *
  * @return bool
  */
 public function handle(NotificationInterface $notification, $level)
 {
     if ($notification instanceof AttributeAwareInterface) {
         $notify = $notification->attribute('notify');
         $format = $notification->attribute('format') ?: HipChat::FORMAT_HTML;
     } else {
         $format = HipChat::FORMAT_HTML;
         $notify = true;
     }
     return $this->hipchat->message_room($this->room, $this->from, $notification->message(), $notify, $this->levelMapping[$level], $format);
 }
예제 #8
0
 public function handle(array $config, $lastSuccessStatus)
 {
     if ($config['hipchat']['from'] == 'HOST_NAME') {
         $from = gethostname();
     } else {
         $from = $config['hipchat']['from'];
     }
     $from = substr($from, 0, 15);
     $hc = new HipChat($config['hipchat']['api_key']);
     $hc->message_room($config['hipchat']['room'], $from, '<b>[host:' . gethostname() . ']</b> - ' . $config['hipchat']['message'], true, HipChat::COLOR_RED);
     $hc->message_room($config['hipchat']['room'], $from, json_encode(json_decode($lastSuccessStatus), JSON_PRETTY_PRINT), false, HipChat::COLOR_RED, HipChat::FORMAT_TEXT);
 }
예제 #9
0
 public function sendMessage($message)
 {
     if (!$this->active) {
         return;
     }
     $this->hipChat->set_verify_ssl(false);
     try {
         $this->hipChat->message_room($this->room, $this->sender, $message);
     } catch (HipChat_Exception $e) {
         if ($e->getCode() == 403) {
             // do nothing it's rate limit exceeded
         } else {
             throw $e;
         }
     }
 }
예제 #10
0
 public function roomSetTopicAction()
 {
     $room = $this->params('room');
     $topic = $this->params('topic');
     $from = $this->params('from', $this->from);
     try {
         $this->hipchat->set_room_topic($room, $topic, $from);
         $this->console->writeLine(sprintf('Room "%s" has topic "%s"', $room, $topic), Color::GREEN);
     } catch (Exception $e) {
         $this->console->writeLine($e->getMessage(), Color::RED);
     }
 }
예제 #11
0
 /**
  * The main function of this class - send a message
  *
  *
  * @param string $message
  * @param array $options Same options as class constructor
  * @param string $room name of the destination room of the message
  * @return bool|mixed
  * @throws HipchatNotifierException
  */
 public function message($message, array $options = [], $room = null)
 {
     $options = array_merge($this->options, $options);
     if ($room) {
         $options['room'] = $room;
     }
     if (!in_array($options['color'], $this->colors)) {
         $msg = "Selected color [{$options['color']}] is not in list of available colors. Please refer to docs.";
         throw new HipchatNotifierException($msg);
     }
     if ($options['queue']) {
         return $this->queue($message, $options);
     }
     $format = $options['format'] === 'auto' ? $this->getFormat($message) : $options['format'];
     return $this->hipchat->message_room($options['room'], $options['from'], $message, $options['notify'], $options['color'], $format);
 }
예제 #12
0
 public function undeleteUser()
 {
     $this->checkUser();
     return $this->hipchat->undelete_user($this->user);
 }