-
Notifications
You must be signed in to change notification settings - Fork 0
/
ZendeskOptions.php
167 lines (134 loc) · 3.68 KB
/
ZendeskOptions.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
<?php
declare(strict_types=1);
namespace Siru\Notifier\Bridge\Zendesk;
use Symfony\Component\Notifier\Message\ChatMessage;
use Symfony\Component\Notifier\Message\MessageOptionsInterface;
use Symfony\Component\Notifier\Notification\Notification;
final class ZendeskOptions implements MessageOptionsInterface
{
/**
* @var array
*/
private $options = [];
/**
* @var bool
*/
private $asRequest = false;
/**
* @var string|null
*/
private $emailAddress = null;
public static function fromNotification(Notification $notification): self
{
$options = new self();
$options->subject($notification->getSubject());
$text = '';
if ($notification->getContent()) {
$text .= $notification->getContent();
}
if ($exception = $notification->getExceptionAsString()) {
$text .= "\r\n".'```' . $exception . '```';
}
switch($notification->getImportance()) {
case Notification::IMPORTANCE_LOW:
case Notification::IMPORTANCE_HIGH:
case Notification::IMPORTANCE_URGENT:
$options->priority($notification->getImportance());
break;
case Notification::IMPORTANCE_MEDIUM:
$options->priority('normal');
break;
}
if (false === empty($text)) {
$options->text($text);
}
return $options;
}
public static function fromMessage(ChatMessage $message): self
{
$options = new self();
$options->subject($message->getSubject());
return $options;
}
public function toArray(): array
{
return $this->options;
}
/**
* Set ticket subject line.
*/
public function subject(string $text): self
{
$this->options['subject'] = $text;
return $this;
}
/**
* Set longer ticket description.
*/
public function text(string $text): self
{
$this->options['comment']['body'] = $text;
return $this;
}
/**
* Set ticket priority.
* Valid values are 'low', 'normal', 'high' and 'urgent'.
*/
public function priority(string $priority): self
{
$this->options['priority'] = $priority;
return $this;
}
/**
* Add tag to ticket.
*/
public function tag(string $tag): self
{
$this->options['tags'][] = $tag;
return $this;
}
/**
* By default, transport creates a ticket. This method changes this to request.
* To learn more about ticket vs requests, see Zendesk documentation.
*/
public function asRequest(bool $asRequest = true): self
{
$this->asRequest = $asRequest;
return $this;
}
/**
* Changes the username for authentication.
* Use this to create tickets/requests on behalf of existing Zendesk user.
*/
public function emailAddress(string $emailAddress): self
{
$this->emailAddress = $emailAddress;
return $this;
}
/**
* Set requester information for anonymous requests.
*/
public function requester(string $emailAddress, ?string $name = null): self
{
if (null === $name) {
$name = explode('@', $emailAddress, 2)[0];
}
$this->options['requester'] = [
'name' => $name,
'email' => $emailAddress
];
return $this;
}
public function isRequest() : bool
{
return $this->asRequest;
}
public function getEmailAddress() : ?string
{
return $this->emailAddress;
}
public function getRecipientId(): ?string
{
return null;
}
}