-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathBotCommand.php
More file actions
58 lines (52 loc) · 1.51 KB
/
Copy pathBotCommand.php
File metadata and controls
58 lines (52 loc) · 1.51 KB
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
<?php
/**
* Class BotCommand
* This is the base class of all bot command implementations.
*
* @author: Angelito Sardez, Jr.
* @date: 12/11/2017
*/
abstract class BotCommand {
public function __construct($command, $sender, $user) {
$this->command = $command;
$this->sender = $sender;
$this->user = $user;
}
protected $command;
protected $sender;
protected $user;
abstract protected function executeCommand($parameter);
public function execute($parameter) {
$this->executeCommand($parameter);
}
protected function send($message) {
$this->sender->send($message);
}
protected function sendTextWithHelp($message, $showCompleteHelp = true) {
$template = ["attachment"=>[
"type"=>"template",
"payload"=>[
"template_type"=>"button",
"text"=>$message,
"buttons"=>[
[
"type"=>'postback',
"title"=>'See '.$this->command.' Help',
"payload"=>'help '.$this->command
]
]
]
]];
if ($showCompleteHelp) {
$template['attachment']['payload']['buttons'][] = [
"type"=>'postback',
"title"=>'See Complete Help',
"payload"=>'help'
];
}
$this->sender->send($template);
}
protected function sendAction($action) {
$this->sender->sendAction($action);
}
}