File tree Expand file tree Collapse file tree 2 files changed +50
-0
lines changed Expand file tree Collapse file tree 2 files changed +50
-0
lines changed Original file line number Diff line number Diff line change @@ -246,6 +246,32 @@ public function toDingTalkRobot($notifiable)
246
246
}
247
247
```
248
248
249
+ ## 使用消息通知(Notification)给多个机器人发同一条消息
250
+
251
+ ``` php
252
+ use Calchen\LaravelDingtalkRobot\Robot;
253
+
254
+ $notification = new TestDingtalkNotification();
255
+
256
+ (new Robot('robot_1'))->notify($notification);
257
+ (new Robot('robot_2'))->notify($notification);
258
+
259
+ // TestDingtalkNotification 文件
260
+ use Calchen\LaravelDingtalkRobot\Message\TextMessage;
261
+
262
+ public function toDingTalkRobot($notifiable)
263
+ {
264
+ $message = new TextMessage('我就是我, @1825718XXXX 是不一样的烟火');
265
+
266
+ // 可@某人或某些人
267
+ $message->at('1825718XXXX'); // $message->at(['1825718XXXX', '1825718XXXY']);
268
+
269
+ // 可通过 setConnection 设置向指定的机器人发送消息,如果不指定则为默认机器人
270
+ $message->setConnection($notifiable->getName());
271
+
272
+ return $message;
273
+ }
274
+ ```
249
275
250
276
## 不使用消息通知(Notification)
251
277
Original file line number Diff line number Diff line change 14
14
class Robot
15
15
{
16
16
use Notifiable;
17
+
18
+ // 机器人名称,用于指定发送机器人
19
+ private $ name ;
20
+
21
+ public function __construct ($ name = 'default ' )
22
+ {
23
+ $ this ->name = $ name ;
24
+ }
25
+
26
+ /**
27
+ * @return string
28
+ */
29
+ public function getName (): string
30
+ {
31
+ return $ this ->name ;
32
+ }
33
+
34
+ /**
35
+ * @param string $name
36
+ */
37
+ public function setName (string $ name ): void
38
+ {
39
+ $ this ->name = $ name ;
40
+ }
17
41
}
You can’t perform that action at this time.
0 commit comments