forked from php-telegram-bot/core
-
Notifications
You must be signed in to change notification settings - Fork 0
/
hook.php
77 lines (62 loc) · 2.64 KB
/
hook.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
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
<?php
/**
* README
* This configuration file is intended to run the bot with the webhook method.
* Uncommented parameters must be filled
*
* Please note that if you open this file with your browser you'll get the "Input is empty!" Exception.
* This is a normal behaviour because this address has to be reached only by Telegram server.
*/
// Load composer
require __DIR__ . '/vendor/autoload.php';
// Add you bot's API key and name
$API_KEY = 'your_bot_api_key';
$BOT_NAME = 'username_bot';
// Define a path for your custom commands
//$commands_path = __DIR__ . '/Commands/';
// Enter your MySQL database credentials
//$mysql_credentials = [
// 'host' => 'localhost',
// 'user' => 'dbuser',
// 'password' => 'dbpass',
// 'database' => 'dbname',
//];
try {
// Create Telegram API object
$telegram = new Longman\TelegramBot\Telegram($API_KEY, $BOT_NAME);
// Error, Debug and Raw Update logging
//Longman\TelegramBot\TelegramLog::initialize($your_external_monolog_instance);
//Longman\TelegramBot\TelegramLog::initErrorLog($path . '/' . $BOT_NAME . '_error.log');
//Longman\TelegramBot\TelegramLog::initDebugLog($path . '/' . $BOT_NAME . '_debug.log');
//Longman\TelegramBot\TelegramLog::initUpdateLog($path . '/' . $BOT_NAME . '_update.log');
// Enable MySQL
//$telegram->enableMySql($mysql_credentials);
// Enable MySQL with table prefix
//$telegram->enableMySql($mysql_credentials, $BOT_NAME . '_');
// Add an additional commands path
//$telegram->addCommandsPath($commands_path);
// Enable admin user(s)
//$telegram->enableAdmin(your_telegram_id);
//$telegram->enableAdmins([your_telegram_id, other_telegram_id]);
// Add the channel you want to manage
//$telegram->setCommandConfig('sendtochannel', ['your_channel' => '@type_here_your_channel']);
// Here you can set some command specific parameters,
// for example, google geocode/timezone api key for /date command:
//$telegram->setCommandConfig('date', ['google_api_key' => 'your_google_api_key_here']);
// Set custom Upload and Download path
//$telegram->setDownloadPath('../Download');
//$telegram->setUploadPath('../Upload');
// Botan.io integration
//$telegram->enableBotan('your_token');
// Handle telegram webhook request
$telegram->handle();
} catch (Longman\TelegramBot\Exception\TelegramException $e) {
// Silence is golden!
//echo $e;
// Log telegram errors
Longman\TelegramBot\TelegramLog::error($e);
} catch (Longman\TelegramBot\Exception\TelegramLogException $e) {
// Silence is golden!
// Uncomment this to catch log initilization errors
//echo $e;
}