Skip to content

Commit

Permalink
给多个机器人发同一条消息
Browse files Browse the repository at this point in the history
优化 Robot 类,以便给多个机器人发同一条消息
  • Loading branch information
calchen committed Jan 18, 2019
1 parent 9cb92b5 commit 5f8c22e
Show file tree
Hide file tree
Showing 2 changed files with 50 additions and 0 deletions.
26 changes: 26 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -246,6 +246,32 @@ public function toDingTalkRobot($notifiable)
}
```

## 使用消息通知(Notification)给多个机器人发同一条消息

```php
use Calchen\LaravelDingtalkRobot\Robot;

$notification = new TestDingtalkNotification();

(new Robot('robot_1'))->notify($notification);
(new Robot('robot_2'))->notify($notification);

// TestDingtalkNotification 文件
use Calchen\LaravelDingtalkRobot\Message\TextMessage;

public function toDingTalkRobot($notifiable)
{
$message = new TextMessage('我就是我, @1825718XXXX 是不一样的烟火');

// 可@某人或某些人
$message->at('1825718XXXX'); // $message->at(['1825718XXXX', '1825718XXXY']);

// 可通过 setConnection 设置向指定的机器人发送消息,如果不指定则为默认机器人
$message->setConnection($notifiable->getName());

return $message;
}
```

## 不使用消息通知(Notification)

Expand Down
24 changes: 24 additions & 0 deletions src/Robot.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,28 @@
class Robot
{
use Notifiable;

// 机器人名称,用于指定发送机器人
private $name;

public function __construct($name = 'default')
{
$this->name = $name;
}

/**
* @return string
*/
public function getName(): string
{
return $this->name;
}

/**
* @param string $name
*/
public function setName(string $name): void
{
$this->name = $name;
}
}

0 comments on commit 5f8c22e

Please sign in to comment.