1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace NotificationChannels\Zendesk; |
4
|
|
|
|
5
|
|
|
use NotificationChannels\Exception\CouldNotCreateMessage; |
6
|
|
|
|
7
|
|
|
class ZendeskMessage |
8
|
|
|
{ |
9
|
|
|
/** @var string */ |
10
|
|
|
protected $subject; |
11
|
|
|
|
12
|
|
|
/** @var array */ |
13
|
|
|
protected $requester = []; |
14
|
|
|
|
15
|
|
|
/** @var string */ |
16
|
|
|
protected $description = ''; |
17
|
|
|
|
18
|
|
|
/** @var string */ |
19
|
|
|
protected $type; |
20
|
|
|
|
21
|
|
|
/** @var string */ |
22
|
|
|
protected $status = 'new'; |
23
|
|
|
|
24
|
|
|
/** @var array */ |
25
|
|
|
protected $tags = []; |
26
|
|
|
|
27
|
|
|
/** @var string */ |
28
|
|
|
protected $content = ''; |
29
|
|
|
|
30
|
|
|
/** @var bool */ |
31
|
|
|
protected $isPublic = false; |
32
|
|
|
|
33
|
|
|
/** @var string */ |
34
|
|
|
protected $priority = 'normal'; |
35
|
|
|
|
36
|
|
|
/** |
37
|
|
|
* @param string $subject |
38
|
|
|
* |
39
|
|
|
* @return static |
40
|
|
|
*/ |
41
|
1 |
|
public static function create($subject = '') |
42
|
|
|
{ |
43
|
1 |
|
return new static($subject); |
44
|
|
|
} |
45
|
|
|
|
46
|
|
|
/** |
47
|
|
|
* @param string $subject |
48
|
|
|
*/ |
49
|
6 |
|
public function __construct($subject = '') |
50
|
|
|
{ |
51
|
6 |
|
$this->subject = $subject; |
52
|
6 |
|
} |
53
|
|
|
|
54
|
|
|
/** |
55
|
|
|
* Set the ticket subject. |
56
|
|
|
* |
57
|
|
|
* @param $subject |
58
|
|
|
* |
59
|
|
|
* @return $this |
60
|
|
|
*/ |
61
|
|
|
public function subject($subject) |
62
|
|
|
{ |
63
|
|
|
$this->subject = $subject; |
64
|
|
|
|
65
|
|
|
return $this; |
66
|
|
|
} |
67
|
|
|
|
68
|
|
|
/** |
69
|
|
|
* Set the ticket customer name. |
70
|
|
|
* |
71
|
|
|
* @param string $name |
72
|
|
|
* @param string $email |
73
|
|
|
* |
74
|
|
|
* @return $this |
75
|
|
|
*/ |
76
|
3 |
|
public function from($name, $email) |
77
|
|
|
{ |
78
|
3 |
|
$this->requester = [ |
79
|
3 |
|
'name' => $name, |
80
|
3 |
|
'email' => $email, |
81
|
|
|
]; |
82
|
|
|
|
83
|
3 |
|
return $this; |
84
|
|
|
} |
85
|
|
|
|
86
|
|
|
/** |
87
|
|
|
* Set the content message. |
88
|
|
|
* |
89
|
|
|
* @param $content |
90
|
|
|
* |
91
|
|
|
* @return $this |
92
|
|
|
*/ |
93
|
2 |
|
public function content($content) |
94
|
|
|
{ |
95
|
2 |
|
$this->content = $content; |
96
|
|
|
|
97
|
2 |
|
return $this; |
98
|
|
|
} |
99
|
|
|
|
100
|
|
|
/** |
101
|
|
|
* Set the description. |
102
|
|
|
* |
103
|
|
|
* @param string $description |
104
|
|
|
* |
105
|
|
|
* @return $this |
106
|
|
|
*/ |
107
|
|
|
public function description($description) |
108
|
|
|
{ |
109
|
|
|
$this->description = $description; |
110
|
|
|
|
111
|
|
|
return $this; |
112
|
|
|
} |
113
|
|
|
|
114
|
|
|
/** |
115
|
|
|
* Set the ticket type. |
116
|
|
|
* Allowed values are problem, incident, question, or task. |
117
|
|
|
* |
118
|
|
|
* @param string $type |
119
|
|
|
* |
120
|
|
|
* @return $this |
121
|
|
|
*/ |
122
|
|
|
public function type($type) |
123
|
|
|
{ |
124
|
|
|
if (! in_array($type, ['problem', 'incident', 'question', 'task'])) { |
125
|
|
|
throw CouldNotCreateMessage::invalidIndent($priority); |
126
|
|
|
} |
127
|
|
|
$this->type = $type; |
128
|
|
|
|
129
|
|
|
return $this; |
130
|
|
|
} |
131
|
|
|
|
132
|
|
|
/** |
133
|
|
|
* Set the ticket priority. |
134
|
|
|
* Allowed values are urgent, high, normal, or low. |
135
|
|
|
* |
136
|
|
|
* @param string $priority |
137
|
|
|
* |
138
|
|
|
* @return $this |
139
|
|
|
*/ |
140
|
|
|
public function priority($priority) |
141
|
|
|
{ |
142
|
|
|
if (! in_array($priority, ['urgent', 'high', 'normal', 'low'])) { |
143
|
|
|
throw CouldNotCreateMessage::invalidPriority($priority); |
144
|
|
|
} |
145
|
|
|
$this->priority = $priority; |
146
|
|
|
|
147
|
|
|
return $this; |
148
|
|
|
} |
149
|
|
|
|
150
|
|
|
/** |
151
|
|
|
* Set the ticket status. |
152
|
|
|
* Allowed values are new, open, pending, hold, solved or closed. |
153
|
|
|
* |
154
|
|
|
* @return $this |
155
|
|
|
*/ |
156
|
|
|
public function status($status) |
157
|
|
|
{ |
158
|
|
|
$this->status = $status; |
159
|
|
|
|
160
|
|
|
return $this; |
161
|
|
|
} |
162
|
|
|
|
163
|
|
|
/** |
164
|
|
|
* Set the message to be public. |
165
|
|
|
* |
166
|
|
|
* @return $this |
167
|
|
|
*/ |
168
|
1 |
|
public function visible() |
169
|
|
|
{ |
170
|
1 |
|
$this->isPublic = true; |
171
|
|
|
|
172
|
1 |
|
return $this; |
173
|
|
|
} |
174
|
|
|
|
175
|
|
|
/** |
176
|
|
|
* Set an array of tags to add to the ticket. |
177
|
|
|
* |
178
|
|
|
* @param array $tags |
179
|
|
|
* |
180
|
|
|
* @return $this |
181
|
|
|
*/ |
182
|
|
|
public function tags(array $tags) |
183
|
|
|
{ |
184
|
|
|
$this->tags = $tags; |
185
|
|
|
|
186
|
|
|
return $this; |
187
|
|
|
} |
188
|
|
|
|
189
|
|
|
/** |
190
|
|
|
* @return array |
191
|
|
|
*/ |
192
|
6 |
|
public function toArray() |
193
|
|
|
{ |
194
|
|
|
return [ |
195
|
6 |
|
'subject' => $this->subject, |
196
|
|
|
'comment' => [ |
197
|
6 |
|
'body' => $this->content, |
198
|
6 |
|
'public' => $this->isPublic, |
199
|
6 |
|
], |
200
|
6 |
|
'requester' => $this->requester, |
201
|
6 |
|
'description' => $this->description, |
202
|
6 |
|
'type' => $this->type, |
203
|
6 |
|
'status' => $this->status, |
204
|
6 |
|
'tags' => $this->tags, |
205
|
6 |
|
'priority' => $this->priority, |
206
|
6 |
|
]; |
207
|
|
|
} |
208
|
|
|
} |
209
|
|
|
|