|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace NotificationChannels\Workplace; |
|
4
|
|
|
|
|
5
|
|
|
use GuzzleHttp\ClientInterface; |
|
6
|
|
|
use GuzzleHttp\Exception\ClientException; |
|
7
|
|
|
use Illuminate\Notifications\Notification; |
|
8
|
|
|
use NotificationChannels\Workplace\Exceptions\CouldNotSendNotification; |
|
9
|
|
|
|
|
10
|
|
|
class WorkplaceChannel |
|
11
|
|
|
{ |
|
12
|
|
|
const FORMATTING_MARKDOWN = 'MARKDOWN'; |
|
13
|
|
|
|
|
14
|
|
|
/** @var ClientInterface Http client. */ |
|
15
|
|
|
protected $httpClient; |
|
16
|
|
|
|
|
17
|
3 |
|
public function __construct(ClientInterface $httpClient) |
|
18
|
|
|
{ |
|
19
|
3 |
|
$this->httpClient = $httpClient; |
|
20
|
3 |
|
} |
|
21
|
|
|
|
|
22
|
|
|
/** |
|
23
|
|
|
* Send the given notification. |
|
24
|
|
|
* |
|
25
|
|
|
* @param mixed $notifiable |
|
26
|
|
|
* @param \Illuminate\Notifications\Notification $notification |
|
27
|
|
|
* |
|
28
|
|
|
* @throws \NotificationChannels\Workplace\Exceptions\CouldNotSendNotification |
|
29
|
|
|
*/ |
|
30
|
3 |
|
public function send($notifiable, Notification $notification) |
|
31
|
|
|
{ |
|
32
|
3 |
|
if (! $to = $notifiable->routeNotificationFor('workplace', $notification)) { |
|
33
|
1 |
|
throw CouldNotSendNotification::endpointNotProvided(); |
|
34
|
|
|
} |
|
35
|
|
|
|
|
36
|
2 |
|
$message = $notification->toWorkplace($notifiable); |
|
|
|
|
|
|
37
|
|
|
|
|
38
|
2 |
|
if (is_string($message)) { |
|
39
|
1 |
|
$message = new WorkplaceMessage($message); |
|
40
|
|
|
} |
|
41
|
|
|
|
|
42
|
|
|
$body = [ |
|
43
|
2 |
|
'message' => $message->getContent(), |
|
44
|
2 |
|
'formatting' => ($message->isMarkdown() ? static::FORMATTING_MARKDOWN : null), |
|
45
|
|
|
]; |
|
46
|
|
|
|
|
47
|
|
|
try { |
|
48
|
2 |
|
return $this->httpClient->post( |
|
49
|
2 |
|
$to, |
|
50
|
2 |
|
['json' => $body] |
|
51
|
|
|
); |
|
52
|
|
|
} catch (ClientException $exception) { |
|
53
|
|
|
throw CouldNotSendNotification::workplaceRespondedWithAnError($exception); |
|
54
|
|
|
} catch (\Exception $exception) { |
|
55
|
|
|
throw CouldNotSendNotification::couldNotCommunicateWithWorkplace($exception); |
|
56
|
|
|
} |
|
57
|
|
|
} |
|
58
|
|
|
} |
|
59
|
|
|
|
This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.
This is most likely a typographical error or the method has been renamed.