-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathroutes.php
41 lines (31 loc) · 1015 Bytes
/
routes.php
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
<?php
/**
* This file is part of the Telegram plugin for OctoberCMS.
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*
* (c) Anton Romanov <[email protected]>
*/
use Vdomah\Telegram\Classes\TelegramApi;
use \Longman\TelegramBot\Request;
use \Longman\TelegramBot\Exception\TelegramException;
use \Vdomah\Telegram\Models\TelegramInfoSettings;
Route::post('/telehook/{token}', array(function($token){
if (TelegramInfoSettings::instance()->get('token') != $token) {
\Log::error('Undefined token '.$token);
App::abort(403, 'Unauthorized action.');
return;
}
try {
Event::fire('telegram.init', []);
// Create Telegram API object
$telegram = TelegramApi::instance();
Event::fire('telegram.beforeReceive', []);
// Handle telegram webhook request
$telegram->handle();
Event::fire('telegram.afterReceive', []);
} catch (TelegramException $e) {
\Log::error($e);
}
}));