|
1
|
|
|
<?php namespace nyx\notify\transports\slack; |
|
2
|
|
|
|
|
3
|
|
|
/** |
|
4
|
|
|
* Slack Response Message |
|
5
|
|
|
* |
|
6
|
|
|
* A Response is a special kind of Message that is sent after an Action of an Attachment has been invoked |
|
7
|
|
|
* inside Slack and Slack has called the designated callback URL. |
|
8
|
|
|
* |
|
9
|
|
|
* @package Nyx\Notify |
|
10
|
|
|
* @version 0.1.0 |
|
11
|
|
|
* @author Michal Chojnacki <[email protected]> |
|
12
|
|
|
* @copyright 2012-2017 Nyx Dev Team |
|
13
|
|
|
* @link https://github.com/unyx/nyx |
|
14
|
|
|
* @todo PHP7.1 pass for nullable return types (missing ?string on most methods). |
|
15
|
|
|
*/ |
|
16
|
|
|
class Response extends Message |
|
17
|
|
|
{ |
|
18
|
|
|
/** |
|
19
|
|
|
* The types a Response can be of. |
|
20
|
|
|
*/ |
|
21
|
|
|
const TYPE_CHANNEL = 'in_channel'; |
|
22
|
|
|
const TYPE_EPHEMERAL = 'ephemeral'; |
|
23
|
|
|
|
|
24
|
|
|
/** |
|
25
|
|
|
* @var string The type of the Response. One of the TYPE_* class constants. |
|
26
|
|
|
*/ |
|
27
|
|
|
protected $type; |
|
28
|
|
|
|
|
29
|
|
|
/** |
|
30
|
|
|
* @var bool Whether the original Message should be replaced by this Response. When false, this Response |
|
31
|
|
|
* will be considered a brand new Message. |
|
32
|
|
|
*/ |
|
33
|
|
|
protected $replaceOriginal; |
|
34
|
|
|
|
|
35
|
|
|
/** |
|
36
|
|
|
* @var bool Whether the original Message should be deleted. If a new one is sent along this Response, |
|
37
|
|
|
* it will be published as a brand new Message. |
|
38
|
|
|
*/ |
|
39
|
|
|
protected $deleteOriginal; |
|
40
|
|
|
|
|
41
|
|
|
/** |
|
42
|
|
|
* Returns the type of the Response. |
|
43
|
|
|
* |
|
44
|
|
|
* @return string |
|
45
|
|
|
*/ |
|
46
|
|
|
public function getType() |
|
47
|
|
|
{ |
|
48
|
|
|
return $this->type; |
|
49
|
|
|
} |
|
50
|
|
|
|
|
51
|
|
|
/** |
|
52
|
|
|
* Sets the type of the Response. |
|
53
|
|
|
* |
|
54
|
|
|
* @param string $type |
|
55
|
|
|
* @return $this |
|
56
|
|
|
* @throws \InvalidArgumentException |
|
57
|
|
|
*/ |
|
58
|
|
|
public function setType(string $type) : Response |
|
59
|
|
|
{ |
|
60
|
|
|
if ($type !== self::TYPE_CHANNEL && $type !== self::TYPE_EPHEMERAL) { |
|
61
|
|
|
throw new \InvalidArgumentException('Expected type to be one of ['.self::TYPE_CHANNEL.', '.self::TYPE_CHANNEL.'], got ['.$type.'] instead.'); |
|
62
|
|
|
} |
|
63
|
|
|
|
|
64
|
|
|
$this->type = $type; |
|
65
|
|
|
|
|
66
|
|
|
return $this; |
|
67
|
|
|
} |
|
68
|
|
|
|
|
69
|
|
|
/** |
|
70
|
|
|
* Checks whether the original Message should be replaced by this Response. |
|
71
|
|
|
* |
|
72
|
|
|
* @return bool |
|
73
|
|
|
*/ |
|
74
|
|
|
public function shouldReplaceOriginal() : bool |
|
75
|
|
|
{ |
|
76
|
|
|
return $this->replaceOriginal === true; |
|
77
|
|
|
} |
|
78
|
|
|
|
|
79
|
|
|
/** |
|
80
|
|
|
* Sets whether the original Message should be replaced by this Response. |
|
81
|
|
|
* |
|
82
|
|
|
* @param bool $replace |
|
83
|
|
|
* @return $this |
|
84
|
|
|
*/ |
|
85
|
|
|
public function setReplaceOriginal(bool $replace) : Response |
|
86
|
|
|
{ |
|
87
|
|
|
$this->replaceOriginal = $replace; |
|
88
|
|
|
|
|
89
|
|
|
return $this; |
|
90
|
|
|
} |
|
91
|
|
|
|
|
92
|
|
|
/** |
|
93
|
|
|
* Checks whether the original Message should be deleted. |
|
94
|
|
|
* |
|
95
|
|
|
* @return bool |
|
96
|
|
|
*/ |
|
97
|
|
|
public function shouldDeleteOriginal() : bool |
|
98
|
|
|
{ |
|
99
|
|
|
return $this->deleteOriginal === true; |
|
100
|
|
|
} |
|
101
|
|
|
|
|
102
|
|
|
/** |
|
103
|
|
|
* Sets whether the original Message should be deleted. |
|
104
|
|
|
* |
|
105
|
|
|
* @param bool $delete |
|
106
|
|
|
* @return $this |
|
107
|
|
|
*/ |
|
108
|
|
|
public function setDeleteOriginal(bool $delete) : Response |
|
109
|
|
|
{ |
|
110
|
|
|
$this->deleteOriginal = $delete; |
|
111
|
|
|
|
|
112
|
|
|
return $this; |
|
113
|
|
|
} |
|
114
|
|
|
} |
|
115
|
|
|
|