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\Channels\Channel; |
10
|
|
|
use FondBot\Contracts\Arrayable; |
11
|
|
|
use FondBot\Drivers\ReceivedMessage; |
12
|
|
|
|
13
|
|
|
class Session implements Arrayable |
14
|
|
|
{ |
15
|
|
|
private $channel; |
16
|
|
|
private $chat; |
17
|
|
|
private $user; |
18
|
|
|
private $message; |
19
|
|
|
private $intent; |
20
|
|
|
private $interaction; |
21
|
|
|
|
22
|
8 |
|
public function __construct( |
23
|
|
|
Channel $channel, |
24
|
|
|
Chat $chat, |
25
|
|
|
User $user, |
26
|
|
|
ReceivedMessage $message, |
27
|
|
|
Intent $intent = null, |
28
|
|
|
Interaction $interaction = null |
29
|
|
|
) { |
30
|
8 |
|
$this->channel = $channel; |
31
|
8 |
|
$this->chat = $chat; |
32
|
8 |
|
$this->user = $user; |
33
|
8 |
|
$this->message = $message; |
34
|
8 |
|
$this->intent = $intent; |
35
|
8 |
|
$this->interaction = $interaction; |
36
|
8 |
|
} |
37
|
|
|
|
38
|
|
|
/** |
39
|
|
|
* Get channel name. |
40
|
|
|
* |
41
|
|
|
* @return Channel |
42
|
|
|
*/ |
43
|
1 |
|
public function getChannel(): Channel |
44
|
|
|
{ |
45
|
1 |
|
return $this->channel; |
46
|
|
|
} |
47
|
|
|
|
48
|
|
|
/** |
49
|
|
|
* Get chat. |
50
|
|
|
* |
51
|
|
|
* @return Chat |
52
|
|
|
*/ |
53
|
1 |
|
public function getChat(): Chat |
54
|
|
|
{ |
55
|
1 |
|
return $this->chat; |
56
|
|
|
} |
57
|
|
|
|
58
|
|
|
/** |
59
|
|
|
* Get user. |
60
|
|
|
* |
61
|
|
|
* @return User |
62
|
|
|
*/ |
63
|
1 |
|
public function getUser(): User |
64
|
|
|
{ |
65
|
1 |
|
return $this->user; |
66
|
|
|
} |
67
|
|
|
|
68
|
|
|
/** |
69
|
|
|
* Get message received from user. |
70
|
|
|
* |
71
|
|
|
* @return ReceivedMessage |
72
|
|
|
*/ |
73
|
1 |
|
public function getMessage(): ReceivedMessage |
74
|
|
|
{ |
75
|
1 |
|
return $this->message; |
76
|
|
|
} |
77
|
|
|
|
78
|
|
|
/** |
79
|
|
|
* Get current intent. |
80
|
|
|
* |
81
|
|
|
* @return Intent|Conversable|null |
82
|
|
|
*/ |
83
|
1 |
|
public function getIntent(): ?Intent |
84
|
|
|
{ |
85
|
1 |
|
return $this->intent; |
86
|
|
|
} |
87
|
|
|
|
88
|
|
|
/** |
89
|
|
|
* Set intent. |
90
|
|
|
* |
91
|
|
|
* @param Intent $intent |
92
|
|
|
*/ |
93
|
1 |
|
public function setIntent(Intent $intent): void |
94
|
|
|
{ |
95
|
1 |
|
$this->intent = $intent; |
96
|
1 |
|
} |
97
|
|
|
|
98
|
|
|
/** |
99
|
|
|
* Get interaction. |
100
|
|
|
* |
101
|
|
|
* @return Interaction|Conversable|null |
102
|
|
|
*/ |
103
|
1 |
|
public function getInteraction(): ?Interaction |
104
|
|
|
{ |
105
|
1 |
|
return $this->interaction; |
106
|
|
|
} |
107
|
|
|
|
108
|
|
|
/** |
109
|
|
|
* Set interaction. |
110
|
|
|
* |
111
|
|
|
* @param Interaction|null $interaction |
112
|
|
|
*/ |
113
|
1 |
|
public function setInteraction(?Interaction $interaction): void |
114
|
|
|
{ |
115
|
1 |
|
$this->interaction = $interaction; |
116
|
1 |
|
} |
117
|
|
|
|
118
|
|
|
/** |
119
|
|
|
* Get the instance as an array. |
120
|
|
|
* |
121
|
|
|
* @return array |
122
|
|
|
*/ |
123
|
1 |
|
public function toArray(): array |
124
|
|
|
{ |
125
|
|
|
return [ |
126
|
1 |
|
'intent' => $this->intent !== null ? get_class($this->intent) : null, |
127
|
1 |
|
'interaction' => $this->interaction !== null ? get_class($this->interaction) : null, |
128
|
|
|
]; |
129
|
|
|
} |
130
|
|
|
} |
131
|
|
|
|