getText() public method

Get text
public getText ( ) : string
return string
Ejemplo n.º 1
0
 /**
  * @param Message $message
  * @return string
  */
 public function execute(Message $message)
 {
     $commandName = explode(' ', $message->getText())[0];
     if ($this->isCommandNative($commandName)) {
         return $this->processNativeCommands($commandName);
     }
     if ($this->isCommandExists($commandName)) {
         $command = $this->commandList[$commandName];
         return $command->execute($message);
     } else {
         return sprintf("Command '%s' is not exists.", $commandName);
     }
 }
Ejemplo n.º 2
0
 /**
  * @covers Slack\Notifier::notify
  */
 public function testNotify()
 {
     $client = $this->getMockBuilder('\\Slack\\Client')->disableOriginalConstructor()->getMock(array('post'));
     $request = $this->getMockBuilder('\\Guzzle\\Http\\Message\\Request')->disableOriginalConstructor()->getMock(array('send'));
     $message = new Message('Hello world');
     $message->setChannel('#test')->setIconEmoji(':ghost:')->setUsername('slack-php');
     $attachment = new \Slack\Message\MessageAttachment();
     $field = new \Slack\Message\MessageField();
     $field->setTitle('foo')->setValue('bar')->setShort(false);
     $attachment->addField($field);
     $message->addAttachment($attachment);
     $expectedDatas = json_encode(array('text' => $message->getText(), 'channel' => $message->getChannel(), 'username' => 'slack-php', 'icon_emoji' => ':ghost:', 'attachments' => array(array('fields' => array(array('title' => 'foo', 'value' => 'bar', 'short' => false))))));
     $client->expects($this->once())->method('post')->with($this->equalTo('/services/hooks/incoming-webhook'), $this->anything(), $this->equalTo($expectedDatas), $this->anything())->will($this->returnValue($request));
     $notifier = new Notifier($client);
     $notifier->notify($message);
 }
Ejemplo n.º 3
0
 public function testGetText()
 {
     $text = $this->faker->sentence;
     $message = new Message($this->client, ['text' => $text]);
     $this->assertEquals($text, $message->getText());
 }
Ejemplo n.º 4
0
 /**
  * Posts a message.
  *
  * @param \Slack\Message\Message $message The message to post.
  *
  * @return \React\Promise\PromiseInterface
  */
 public function postMessage(Message $message)
 {
     $options = ['text' => $message->getText(), 'channel' => $message->data['channel'], 'as_user' => true];
     if ($message->hasAttachments()) {
         $options['attachments'] = json_encode($message->getAttachments());
     }
     return $this->apiCall('chat.postMessage', $options);
 }