-
Notifications
You must be signed in to change notification settings - Fork 0
/
Engine.php
60 lines (53 loc) · 1.37 KB
/
Engine.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
<?php
namespace Acms\Plugins\Slack;
use Field;
use Common;
use lygav\slackbot\SlackBot;
class Engine
{
/**
* @var \ACMS_POST
*/
protected $module;
/**
* @var \Field
*/
protected $config;
/**
* Engine constructor.
* @param string $code
* @param \ACMS_POST
*/
public function __construct($code, $module)
{
$info = $module->loadForm($code);
if (empty($info)) {
throw new \RuntimeException('Not Found Form.');
}
$this->config = $info['data']->getChild('mail');
$this->module = $module;
}
/**
* Send
*/
public function send()
{
$hook_url = $this->config->get('slack_incoming_hook_url');
if (empty($hook_url)) {
throw new \RuntimeException('Empty hook url.');
}
$bot = new Slackbot($this->config->get('slack_incoming_hook_url'));
$messageTpl = $this->config->get('slack_form_message');
$channel = $this->config->get('slack_form_channel');
$from = $this->config->get('slack_form_from');
$text = Common::getMailTxtFromTxt($messageTpl, $this->module->Post->getChild('field'));;
$slack = $bot->text($text);
if ($channel) {
$slack->toChannel($channel);
}
if ($from) {
$slack->from($from);
}
$slack->send();
}
}