-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathprocess-commands.example.php
More file actions
62 lines (53 loc) · 1.68 KB
/
Copy pathprocess-commands.example.php
File metadata and controls
62 lines (53 loc) · 1.68 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
59
60
61
62
<?php
use tweet9ra\Logux\App;
use tweet9ra\Logux\CommandsProcessor;
use tweet9ra\Logux\CurlActionsDispatcher;
use tweet9ra\Logux\EventsHandler;
require_once "vendor/autoload.php";
$input = file_get_contents('php://input');
$inputDecoded = json_decode($input, true);
// Creating app
$eventsHandler = new EventsHandler();
$app = new App(
new CommandsProcessor($eventsHandler),
new CurlActionsDispatcher('http://localhost:31338'),
$eventsHandler,
'secret'
);
class Foo {
/**
* Processing subscribe action
* @param \tweet9ra\Logux\ProcessableAction $action
* @return void Return result of actions callback is not used, but you can affect Action Object for response
*/
public function subscribe (\tweet9ra\Logux\ProcessableAction $action, string $chatId, int $channelId)
{
// Not nessessary, this will do automatically if Action was not affected
$action->approved()
->processed();
}
/**
* Check user credentials
* @param string|null $userId
* @param string|null $token
* @param string $authId Authentication command ID
* @return bool
*/
public function auth(string $authId, $userId = null, $token = null) : bool
{
return true;
}
}
// You can set callback class method or use closure
$app->setActionsMap([
'logux/subscribe' => [
'chat/:chatId/:channelId' => 'Foo@subscribe',
'chat/:chatId' => function (\tweet9ra\Logux\ProcessableAction $action, string $chatId, int $channelId) {
$action->approved()
->processed();
}
],
'auth' => 'Foo@auth'
]);
$response = $app->processRequest($inputDecoded);
echo json_encode($response);