|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
declare(strict_types=1); |
|
4
|
|
|
|
|
5
|
|
|
namespace FondBot\Conversation; |
|
6
|
|
|
|
|
7
|
|
|
use FondBot\Drivers\Chat; |
|
8
|
|
|
use FondBot\Drivers\User; |
|
9
|
|
|
use FondBot\Drivers\ReceivedMessage; |
|
10
|
|
|
|
|
11
|
|
|
class Context |
|
12
|
|
|
{ |
|
13
|
|
|
private $channel; |
|
14
|
|
|
private $chat; |
|
15
|
|
|
private $user; |
|
16
|
|
|
private $message; |
|
17
|
|
|
private $intent; |
|
18
|
|
|
private $interaction; |
|
19
|
|
|
private $values; |
|
20
|
|
|
|
|
21
|
9 |
|
public function __construct( |
|
22
|
|
|
string $channel, |
|
23
|
|
|
Chat $chat, |
|
24
|
|
|
User $user, |
|
25
|
|
|
ReceivedMessage $message, |
|
26
|
|
|
Intent $intent = null, |
|
27
|
|
|
Interaction $interaction = null, |
|
28
|
|
|
array $values = [] |
|
29
|
|
|
) { |
|
30
|
9 |
|
$this->channel = $channel; |
|
31
|
9 |
|
$this->chat = $chat; |
|
32
|
9 |
|
$this->user = $user; |
|
33
|
9 |
|
$this->message = $message; |
|
34
|
9 |
|
$this->intent = $intent; |
|
35
|
9 |
|
$this->interaction = $interaction; |
|
36
|
9 |
|
$this->values = $values; |
|
37
|
9 |
|
} |
|
38
|
|
|
|
|
39
|
|
|
/** |
|
40
|
|
|
* Get channel name. |
|
41
|
|
|
* |
|
42
|
|
|
* @return string |
|
43
|
|
|
*/ |
|
44
|
1 |
|
public function getChannel(): string |
|
45
|
|
|
{ |
|
46
|
1 |
|
return $this->channel; |
|
47
|
|
|
} |
|
48
|
|
|
|
|
49
|
|
|
/** |
|
50
|
|
|
* Get chat. |
|
51
|
|
|
* |
|
52
|
|
|
* @return Chat |
|
53
|
|
|
*/ |
|
54
|
1 |
|
public function getChat(): Chat |
|
55
|
|
|
{ |
|
56
|
1 |
|
return $this->chat; |
|
57
|
|
|
} |
|
58
|
|
|
|
|
59
|
|
|
/** |
|
60
|
|
|
* Get user. |
|
61
|
|
|
* |
|
62
|
|
|
* @return User |
|
63
|
|
|
*/ |
|
64
|
1 |
|
public function getUser(): User |
|
65
|
|
|
{ |
|
66
|
1 |
|
return $this->user; |
|
67
|
|
|
} |
|
68
|
|
|
|
|
69
|
|
|
/** |
|
70
|
|
|
* Get message received from user. |
|
71
|
|
|
* |
|
72
|
|
|
* @return ReceivedMessage |
|
73
|
|
|
*/ |
|
74
|
1 |
|
public function getMessage(): ReceivedMessage |
|
75
|
|
|
{ |
|
76
|
1 |
|
return $this->message; |
|
77
|
|
|
} |
|
78
|
|
|
|
|
79
|
|
|
/** |
|
80
|
|
|
* Get current intent instance. |
|
81
|
|
|
* |
|
82
|
|
|
* @return Intent|Conversable|null |
|
83
|
|
|
*/ |
|
84
|
1 |
|
public function getIntent(): ?Intent |
|
85
|
|
|
{ |
|
86
|
1 |
|
return $this->intent; |
|
87
|
|
|
} |
|
88
|
|
|
|
|
89
|
|
|
/** |
|
90
|
|
|
* Set intent instance. |
|
91
|
|
|
* |
|
92
|
|
|
* @param Intent $intent |
|
93
|
|
|
*/ |
|
94
|
1 |
|
public function setIntent(Intent $intent): void |
|
95
|
|
|
{ |
|
96
|
1 |
|
$this->intent = $intent; |
|
97
|
1 |
|
} |
|
98
|
|
|
|
|
99
|
|
|
/** |
|
100
|
|
|
* Get current interaction instance. |
|
101
|
|
|
* |
|
102
|
|
|
* @return Interaction|Conversable|null |
|
103
|
|
|
*/ |
|
104
|
1 |
|
public function getInteraction(): ?Interaction |
|
105
|
|
|
{ |
|
106
|
1 |
|
return $this->interaction; |
|
107
|
|
|
} |
|
108
|
|
|
|
|
109
|
|
|
/** |
|
110
|
|
|
* Set interaction instance. |
|
111
|
|
|
* |
|
112
|
|
|
* @param Interaction|null $interaction |
|
113
|
|
|
*/ |
|
114
|
1 |
|
public function setInteraction(?Interaction $interaction): void |
|
115
|
|
|
{ |
|
116
|
1 |
|
$this->interaction = $interaction; |
|
117
|
1 |
|
} |
|
118
|
|
|
|
|
119
|
|
|
/** |
|
120
|
|
|
* Get stored values. |
|
121
|
|
|
* |
|
122
|
|
|
* @return array |
|
123
|
|
|
*/ |
|
124
|
1 |
|
public function getValues(): array |
|
125
|
|
|
{ |
|
126
|
1 |
|
return $this->values; |
|
127
|
|
|
} |
|
128
|
|
|
|
|
129
|
|
|
/** |
|
130
|
|
|
* Set values to be stored. |
|
131
|
|
|
* |
|
132
|
|
|
* @param array $values |
|
133
|
|
|
*/ |
|
134
|
1 |
|
public function setValues(array $values): void |
|
135
|
|
|
{ |
|
136
|
1 |
|
$this->values = $values; |
|
137
|
1 |
|
} |
|
138
|
|
|
|
|
139
|
|
|
/** |
|
140
|
|
|
* Store value. |
|
141
|
|
|
* |
|
142
|
|
|
* @param string $key |
|
143
|
|
|
* @param mixed $value |
|
144
|
|
|
*/ |
|
145
|
1 |
|
public function setValue(string $key, $value): void |
|
146
|
|
|
{ |
|
147
|
1 |
|
$this->values[$key] = $value; |
|
148
|
1 |
|
} |
|
149
|
|
|
|
|
150
|
|
|
/** |
|
151
|
|
|
* Get the instance as an array. |
|
152
|
|
|
* |
|
153
|
|
|
* @return array |
|
154
|
|
|
*/ |
|
155
|
1 |
|
public function toArray(): array |
|
156
|
|
|
{ |
|
157
|
|
|
return [ |
|
158
|
1 |
|
'intent' => $this->intent !== null ? get_class($this->intent) : null, |
|
159
|
1 |
|
'interaction' => $this->interaction !== null ? get_class($this->interaction) : null, |
|
160
|
1 |
|
'values' => $this->values, |
|
161
|
|
|
]; |
|
162
|
|
|
} |
|
163
|
|
|
} |
|
164
|
|
|
|