1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace WowApps\SlackBotBundle\Command; |
4
|
|
|
|
5
|
|
|
use SensioLabs\Security\Exception\RuntimeException; |
6
|
|
|
use Symfony\Bundle\FrameworkBundle\Command\ContainerAwareCommand; |
7
|
|
|
use Symfony\Component\Console\Input\InputArgument; |
8
|
|
|
use Symfony\Component\Console\Input\InputInterface; |
9
|
|
|
use Symfony\Component\Console\Input\InputOption; |
10
|
|
|
use Symfony\Component\Console\Output\OutputInterface; |
11
|
|
|
use Symfony\Component\Console\Style\SymfonyStyle; |
12
|
|
|
use WowApps\SlackBotBundle\DTO\SlackMessage; |
13
|
|
|
use WowApps\SlackBotBundle\Service\SlackBot; |
14
|
|
|
use WowApps\SlackBotBundle\Traits\SlackMessageTrait; |
15
|
|
|
|
16
|
|
|
class SlackbotTestCommand extends ContainerAwareCommand |
17
|
|
|
{ |
18
|
|
|
use SlackMessageTrait; |
19
|
|
|
|
20
|
|
|
protected function configure() |
21
|
|
|
{ |
22
|
|
|
$this |
23
|
|
|
->setName('slackbot:test') |
24
|
|
|
->setDescription('Test your settings and try to send messages') |
25
|
|
|
; |
26
|
|
|
} |
27
|
|
|
|
28
|
|
|
protected function execute(InputInterface $input, OutputInterface $output) |
29
|
|
|
{ |
30
|
|
|
/** @var SlackBot $slackBot */ |
31
|
|
|
$slackBot = $this->getContainer()->get('wowapps.slackbot'); |
32
|
|
|
$slackBotConfig = $slackBot->getConfig(); |
33
|
|
|
|
34
|
|
|
$symfonyStyle = new SymfonyStyle($input, $output); |
35
|
|
|
|
36
|
|
|
echo PHP_EOL; |
37
|
|
|
$output->writeln('<bg=blue;options=bold;fg=white> </>'); |
38
|
|
|
$output->writeln('<bg=blue;options=bold;fg=white> S L A C K B O T T E S T </>'); |
39
|
|
|
$output->writeln('<bg=blue;options=bold;fg=white> </>'); |
40
|
|
|
echo PHP_EOL; |
41
|
|
|
|
42
|
|
|
$symfonyStyle->section('SlackBot general settings'); |
43
|
|
|
|
44
|
|
|
$symfonyStyle->table( |
45
|
|
|
['api url'], |
46
|
|
|
[[$slackBotConfig['api_url']]] |
47
|
|
|
); |
48
|
|
|
|
49
|
|
|
$symfonyStyle->table( |
50
|
|
|
['default icon'], |
51
|
|
|
[[$slackBotConfig['default_icon']]] |
52
|
|
|
); |
53
|
|
|
|
54
|
|
|
$symfonyStyle->table( |
55
|
|
|
['default recipient'], |
56
|
|
|
[[$slackBotConfig['default_channel']]] |
57
|
|
|
); |
58
|
|
|
|
59
|
|
|
$symfonyStyle->section('SlackBot quote colors'); |
60
|
|
|
|
61
|
|
|
$symfonyStyle->table( |
62
|
|
|
['default', 'info', 'warning', 'success', 'danger'], |
63
|
|
|
[ |
64
|
|
|
[ |
65
|
|
|
$slackBotConfig['quote_color']['default'], |
66
|
|
|
$slackBotConfig['quote_color']['info'], |
67
|
|
|
$slackBotConfig['quote_color']['warning'], |
68
|
|
|
$slackBotConfig['quote_color']['success'], |
69
|
|
|
$slackBotConfig['quote_color']['danger'] |
70
|
|
|
] |
71
|
|
|
] |
72
|
|
|
); |
73
|
|
|
|
74
|
|
|
$symfonyStyle->section('Sending short message...'); |
75
|
|
|
|
76
|
|
|
if ($this->sendTestMessage($slackBot)) { |
77
|
|
|
$symfonyStyle->success('Message sent successfully'); |
78
|
|
|
} else { |
79
|
|
|
$symfonyStyle->error('Message not sent'); |
80
|
|
|
} |
81
|
|
|
} |
82
|
|
|
|
83
|
|
|
/** |
84
|
|
|
* @param SlackBot $slackBot |
85
|
|
|
* @return bool |
86
|
|
|
*/ |
87
|
|
|
private function sendTestMessage(SlackBot $slackBot) |
88
|
|
|
{ |
89
|
|
|
$slackMessage = new SlackMessage(); |
90
|
|
|
|
91
|
|
|
$quoteText = [ |
92
|
|
|
'This is ' . $this->formatBold('test') . ' message sent by SlackBot', |
93
|
|
|
$this->formatCode([ |
94
|
|
|
'<?php', |
95
|
|
|
'$someString = \'Hello world!\';', |
96
|
|
|
'echo $someString;' |
97
|
|
|
]) |
98
|
|
|
]; |
99
|
|
|
|
100
|
|
|
$slackMessage |
101
|
|
|
->setIcon('http://cdn.wow-apps.pro/slackbot/slack-bot-icon-48.png') |
102
|
|
|
->setText('If you read this - SlackBot is working!') |
103
|
|
|
->setRecipient('general') |
104
|
|
|
->setSender('WoW-Apps') |
105
|
|
|
->setShowQuote(true) |
106
|
|
|
->setQuoteType(SlackBot::QUOTE_SUCCESS) |
107
|
|
|
->setQuoteText($this->inlineMultilines($quoteText)) |
108
|
|
|
->setQuoteTitle('SlackBot for Symfony 3') |
109
|
|
|
->setQuoteTitleLink('https://github.com/wow-apps/symfony-slack-bot') |
110
|
|
|
; |
111
|
|
|
|
112
|
|
|
return $slackBot->sendMessage($slackMessage); |
113
|
|
|
} |
114
|
|
|
} |
115
|
|
|
|