Example #1
0
 public function testWildcardCallToMessage()
 {
     $client = new Client('http://fake.endpoint');
     $message = $client->to('@regan');
     $this->assertInstanceOf('Maknz\\Slack\\Message', $message);
     $this->assertSame('@regan', $message->getChannel());
 }
 public function testPlainMessage()
 {
     $expectedHttpData = ['username' => 'Archer', 'channel' => '@regan', 'text' => 'Message', 'link_names' => false, 'unfurl_links' => false, 'unfurl_media' => true, 'mrkdwn' => true, 'attachments' => []];
     $client = new Client('http://fake.endpoint');
     $message = $client->to('@regan')->from('Archer')->setText('Message');
     $payload = $client->preparePayload($message);
     $this->assertEquals($expectedHttpData, $payload);
 }
Example #3
0
 /**
  * Send report to Slack.
  *
  * $param array $to
  *   Comma separated list of Slack channels ("#") and/or users ("@") to send message to.
  * @param string $message
  *   List of message attachment options. https://github.com/maknz/slack#send-an-attachment-with-fields
  * @param array $channelNames
  *   The name of the channel to send the message to.
  */
 public function alert($channelNames, $message, $tos = ['@dee'])
 {
     $to = implode(',', $tos);
     foreach ($channelNames as $channelName) {
         $channelKey = $this->lookupChannelKey($channelName);
         $slack = new Client($channelKey);
         $slack->to($to)->attach($message)->send();
         $this->statHat->ezCount('MB_Toolbox: MB_Slack: alert', 1);
     }
 }
 /**
  * Add the receiver
  *
  * @param $to
  */
 protected function addTo($to)
 {
     if (!empty($to)) {
         $this->client = $this->client->to($to);
     }
 }
 public function send()
 {
     $this->client->to($this->config['channel'])->attach(['text' => $this->message, 'color' => $this->type === static::TYPE_SUCCESS ? 'good' : 'warning'])->send($this->subject);
 }