1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/* |
4
|
|
|
* This file is part of the WoW-Apps/Symfony-Slack-Bot bundle for Symfony. |
5
|
|
|
* https://github.com/wow-apps/symfony-slack-bot |
6
|
|
|
* |
7
|
|
|
* For the full copyright and license information, please view the LICENSE |
8
|
|
|
* file that was distributed with this source code. |
9
|
|
|
* https://github.com/wow-apps/symfony-slack-bot/blob/master/LICENSE |
10
|
|
|
* |
11
|
|
|
* For technical documentation. |
12
|
|
|
* https://wow-apps.github.io/symfony-slack-bot/docs/ |
13
|
|
|
* |
14
|
|
|
* Author Alexey Samara <[email protected]> |
15
|
|
|
* |
16
|
|
|
* Copyright 2016 WoW-Apps. |
17
|
|
|
*/ |
18
|
|
|
|
19
|
|
|
namespace WowApps\SlackBundle\Service; |
20
|
|
|
|
21
|
|
|
use WowApps\SlackBundle\DTO\SlackMessage; |
22
|
|
|
use WowApps\SlackBundle\Templating\SlackTemplateInterface; |
23
|
|
|
|
24
|
|
|
/** |
25
|
|
|
* Class SlackBot. |
26
|
|
|
* |
27
|
|
|
* @author Alexey Samara <[email protected]> |
28
|
|
|
*/ |
29
|
|
|
class SlackBot |
30
|
|
|
{ |
31
|
|
|
/** @var SlackMessageBuilder */ |
32
|
|
|
private $builder; |
33
|
|
|
|
34
|
|
|
/** @var SlackProvider */ |
35
|
|
|
private $provider; |
36
|
|
|
|
37
|
|
|
/** @var SlackTemplatingManager */ |
38
|
|
|
private $templatingManager; |
39
|
|
|
|
40
|
|
|
/** @var array */ |
41
|
|
|
private $config; |
42
|
|
|
|
43
|
|
|
/** |
44
|
|
|
* SlackBot constructor. |
45
|
|
|
* |
46
|
|
|
* @param array $config |
47
|
|
|
* @param SlackMessageBuilder $builder |
48
|
|
|
* @param SlackProvider $provider |
49
|
|
|
* @param SlackTemplatingManager $templatingManager |
50
|
|
|
*/ |
51
|
|
|
public function __construct( |
52
|
|
|
array $config, |
53
|
|
|
SlackMessageBuilder $builder, |
54
|
|
|
SlackProvider $provider, |
55
|
|
|
SlackTemplatingManager $templatingManager |
56
|
|
|
) { |
57
|
3 |
|
$this->config = $config; |
58
|
|
|
$this->builder = $builder; |
59
|
3 |
|
$this->provider = $provider; |
60
|
3 |
|
$this->templatingManager = $templatingManager; |
61
|
3 |
|
} |
62
|
3 |
|
|
63
|
|
|
/** |
64
|
|
|
* @param SlackMessage $slackMessage |
65
|
|
|
* |
66
|
|
|
* @return bool |
67
|
2 |
|
*/ |
68
|
|
|
public function send(SlackMessage $slackMessage): bool |
69
|
2 |
|
{ |
70
|
|
|
return $this->provider->send( |
71
|
|
|
$this->builder->buildRequestBody($slackMessage) |
72
|
|
|
); |
73
|
|
|
} |
74
|
|
|
|
75
|
3 |
|
/** |
76
|
|
|
* @param SlackTemplateInterface $slackTemplate |
77
|
3 |
|
* |
78
|
3 |
|
* @return bool |
79
|
|
|
*/ |
80
|
|
|
public function sendTemplate(SlackTemplateInterface $slackTemplate): bool |
81
|
|
|
{ |
82
|
|
|
return $this->send( |
83
|
|
|
$this->templatingManager->setTemplate($slackTemplate)->getMessage() |
84
|
1 |
|
); |
85
|
|
|
} |
86
|
1 |
|
|
87
|
1 |
|
/** |
88
|
|
|
* @return array |
89
|
|
|
*/ |
90
|
1 |
|
public function getConfig(): array |
91
|
|
|
{ |
92
|
|
|
return $this->config; |
93
|
|
|
} |
94
|
|
|
} |
95
|
|
|
|