|
13 | 13 |
|
14 | 14 | namespace Guanguans\Notify\ZohoCliq\Messages; |
15 | 15 |
|
| 16 | +use Guanguans\Notify\Foundation\Support\Arr; |
| 17 | +use Symfony\Component\OptionsResolver\OptionsResolver; |
| 18 | + |
16 | 19 | /** |
17 | 20 | * @method self bot(array $bot) |
18 | 21 | * @method self buttons(array $buttons) |
|
21 | 24 | * @method self styles(array $styles) |
22 | 25 | * @method self text(mixed $text) |
23 | 26 | */ |
24 | | -class Message extends \Guanguans\Notify\ZohoCliqWebHook\Messages\Message {} |
| 27 | +abstract class Message extends \Guanguans\Notify\Foundation\Message |
| 28 | +{ |
| 29 | + protected array $required = [ |
| 30 | + // 'channel_unique_name', |
| 31 | + // 'bot_unique_name', |
| 32 | + // 'chat_id', |
| 33 | + // 'email_id', |
| 34 | + // 'text', |
| 35 | + ]; |
| 36 | + protected array $defined = [ |
| 37 | + 'text', |
| 38 | + 'bot', |
| 39 | + 'card', |
| 40 | + 'styles', |
| 41 | + 'slides', |
| 42 | + 'buttons', |
| 43 | + ]; |
| 44 | + protected array $allowedTypes = [ |
| 45 | + 'bot' => 'array', |
| 46 | + 'card' => 'array', |
| 47 | + 'styles' => 'array', |
| 48 | + 'slides' => 'array[]', |
| 49 | + 'buttons' => 'array[]', |
| 50 | + ]; |
| 51 | + protected array $options = [ |
| 52 | + 'slides' => [], |
| 53 | + 'buttons' => [], |
| 54 | + ]; |
| 55 | + |
| 56 | + final public function addSlide(array $slide): self |
| 57 | + { |
| 58 | + $this->options['slides'][] = $slide; |
| 59 | + |
| 60 | + return $this; |
| 61 | + } |
| 62 | + |
| 63 | + final public function addButton(array $button): self |
| 64 | + { |
| 65 | + $this->options['buttons'][] = $button; |
| 66 | + |
| 67 | + return $this; |
| 68 | + } |
| 69 | + |
| 70 | + protected function toPayload(): array |
| 71 | + { |
| 72 | + return Arr::except(parent::toPayload(), [ |
| 73 | + 'channel_unique_name', |
| 74 | + 'bot_unique_name', |
| 75 | + 'chat_id', |
| 76 | + 'email_id', |
| 77 | + ]); |
| 78 | + } |
| 79 | + |
| 80 | + protected function configureOptionsResolver(OptionsResolver $optionsResolver): void |
| 81 | + { |
| 82 | + $optionsResolver |
| 83 | + ->setDefault('bot', static function (OptionsResolver $optionsResolver): void { |
| 84 | + $optionsResolver |
| 85 | + ->setDefined([ |
| 86 | + 'name', |
| 87 | + 'image', |
| 88 | + ]); |
| 89 | + }) |
| 90 | + ->setDefault('card', static function (OptionsResolver $optionsResolver): void { |
| 91 | + $optionsResolver |
| 92 | + ->setDefined([ |
| 93 | + 'title', |
| 94 | + 'theme', |
| 95 | + 'thumbnail', |
| 96 | + 'icon', |
| 97 | + 'preview', |
| 98 | + ]); |
| 99 | + }) |
| 100 | + ->setDefault('styles', static function (OptionsResolver $optionsResolver): void { |
| 101 | + $optionsResolver |
| 102 | + ->setDefined([ |
| 103 | + 'highlight', |
| 104 | + ]) |
| 105 | + ->setAllowedTypes('highlight', 'bool'); |
| 106 | + }) |
| 107 | + ->setDefault('slides', static function (OptionsResolver $optionsResolver): void { |
| 108 | + $optionsResolver |
| 109 | + ->setPrototype(true) |
| 110 | + ->setDefined([ |
| 111 | + 'type', |
| 112 | + 'title', |
| 113 | + 'data', |
| 114 | + ]); |
| 115 | + }) |
| 116 | + ->setDefault('buttons', static function (OptionsResolver $optionsResolver): void { |
| 117 | + $optionsResolver |
| 118 | + ->setPrototype(true) |
| 119 | + ->setDefined([ |
| 120 | + 'label', |
| 121 | + 'hint', |
| 122 | + 'key', |
| 123 | + 'type', |
| 124 | + 'action', |
| 125 | + ]); |
| 126 | + }); |
| 127 | + } |
| 128 | +} |
0 commit comments