Commit 1954213e authored by Armando Lüscher's avatar Armando Lüscher

Revise README file and correct code snippets.

Prettify example code files.
parent f11c153c
This diff is collapsed.
...@@ -7,60 +7,59 @@ ...@@ -7,60 +7,59 @@
#bash script #bash script
#while true; do ./getUpdatesCLI.php; done #while true; do ./getUpdatesCLI.php; done
//Composer Loader // Load composer
$dir = realpath(__DIR__.'/..'); require __DIR__ . '/vendor/autoload.php';
$loader = require $dir.'/vendor/autoload.php';
$API_KEY = 'your_bot_api_key'; $API_KEY = 'your_bot_api_key';
$BOT_NAME = 'namebot'; $BOT_NAME = 'namebot';
//$COMMANDS_FOLDER = __DIR__.'/Commands/'; //$commands_path = __DIR__ . '/Commands/';
$credentials = [ $mysql_credentials = [
'host'=>'localhost', 'host' => 'localhost',
'user'=>'dbuser', 'user' => 'dbuser',
'password'=>'dbpass', 'password' => 'dbpass',
'database'=>'dbname' 'database' => 'dbname',
]; ];
try { try {
// create Telegram API object // Create Telegram API object
$telegram = new Longman\TelegramBot\Telegram($API_KEY, $BOT_NAME); $telegram = new Longman\TelegramBot\Telegram($API_KEY, $BOT_NAME);
////Options // Enable MySQL
$telegram->enableMySQL($credentials); $telegram->enableMySQL($mysql_credentials);
////Enable mysql with table prefix //// Enable MySQL with table prefix
//$telegram->enableMySQL($credentials, $BOT_NAME.'_'); //$telegram->enableMySQL($mysql_credentials, $BOT_NAME . '_');
//$telegram->addCommandsPath($COMMANDS_FOLDER); //// Add an additional commands path
//$telegram->addCommandsPath($commands_path);
////Here you can enable admin interface ache the channel you want to manage //// Here you can enable admin interface for the channel you want to manage
//$telegram->enableAdmins(['your_telegram_id']); //$telegram->enableAdmins(['your_telegram_id']);
//$telegram->setCommandConfig('sendtochannel', ['your_channel'=>'@type_here_your_channel']); //$telegram->setCommandConfig('sendtochannel', ['your_channel' => '@type_here_your_channel']);
////Here you can set some command specified parameters, //// Here you can set some command specific parameters,
////for example, google geocode/timezone api key for date command: //// for example, google geocode/timezone api key for date command:
//$telegram->setCommandConfig('date', array('google_api_key'=>'your_google_api_key_here')); //$telegram->setCommandConfig('date', ['google_api_key' => 'your_google_api_key_here']);
////Logging //// Logging
//$telegram->setLogRequests(true); //$telegram->setLogRequests(true);
//$telegram->setLogPath($BOT_NAME.'.log'); //$telegram->setLogPath($BOT_NAME . '.log');
//$telegram->setLogVerbosity(3); //$telegram->setLogVerbosity(3);
//$telegram->setDownloadPath("../Download"); //// Set custom Upload and Download path
//$telegram->setUploadPath("../Upload"); //$telegram->setDownloadPath('../Download');
//$telegram->setUploadPath('../Upload');
// handle telegram getUpdate request // Handle telegram getUpdate request
$ServerResponse = $telegram->handleGetUpdates(); $ServerResponse = $telegram->handleGetUpdates();
if ($ServerResponse->isOk()) { if ($ServerResponse->isOk()) {
$n_update = count($ServerResponse->getResult()); $n_update = count($ServerResponse->getResult());
print(date('Y-m-d H:i:s', time()) . ' - Processed ' . $n_update . ' updates' . "\n");
print(date('Y-m-d H:i:s', time()).' - Processed '.$n_update." updates\n");
} else { } else {
print(date('Y-m-d H:i:s', time())." - Fail fetch updates\n"); print(date('Y-m-d H:i:s', time()) . ' - Failed to fetch updates' . "\n");
echo $ServerResponse->printError()."\n"; echo $ServerResponse->printError() . "\n";
} }
} catch (Longman\TelegramBot\Exception\TelegramException $e) { } catch (Longman\TelegramBot\Exception\TelegramException $e) {
// log telegram errors // log telegram errors
echo $e; echo $e;
......
<?php <?php
//README //README
//This configuration file is intented to run the bot with the webhook method. //This configuration file is intended to run the bot with the webhook method.
//Uncommented parameters must be filled //Uncommented parameters must be filled
//Please notice that if you open this file with your browser you'll get the "Input is empty!" Exception. //Please notice 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 //This is a normal behaviour because this address has to be reached only by Telegram server
//Composer Loader // Load composer
$dir = realpath(__DIR__.'/..'); require __DIR__ . '/vendor/autoload.php';
$loader = require $dir.'/vendor/autoload.php';
$API_KEY = 'your_bot_api_key'; $API_KEY = 'your_bot_api_key';
$BOT_NAME = 'namebot'; $BOT_NAME = 'namebot';
//$COMMANDS_FOLDER = __DIR__.'/Commands/'; //$commands_path = __DIR__ . '/Commands/';
//$credentials = [ //$mysql_credentials = [
// 'host'=>'localhost', // 'host' => 'localhost',
// 'user'=>'dbuser', // 'user' => 'dbuser',
// 'password'=>'dbpass', // 'password' => 'dbpass',
// 'database'=>'dbname' // 'database' => 'dbname',
//]; //];
try { try {
// create Telegram API object // Create Telegram API object
$telegram = new Longman\TelegramBot\Telegram($API_KEY, $BOT_NAME); $telegram = new Longman\TelegramBot\Telegram($API_KEY, $BOT_NAME);
////Options //// Enable MySQL
$telegram->enableMySQL($credentials); //$telegram->enableMySQL($mysql_credentials);
////Enable mysql with table prefix //// Enable MySQL with table prefix
//$telegram->enableMySQL($credentials, $BOT_NAME.'_'); //$telegram->enableMySQL($mysql_credentials, $BOT_NAME . '_');
//$telegram->addCommandsPath($COMMANDS_FOLDER); //// Add an additional commands path
//$telegram->addCommandsPath($commands_path);
////Here you can enable admin interface ache the channel you want to manage //// Here you can enable admin interface for the channel you want to manage
//$telegram->enableAdmins(['your_telegram_id']); //$telegram->enableAdmins(['your_telegram_id']);
//$telegram->setCommandConfig('sendtochannel', ['your_channel'=>'@type_here_your_channel']); //$telegram->setCommandConfig('sendtochannel', ['your_channel' => '@type_here_your_channel']);
////Here you can set some command specified parameters, //// Here you can set some command specific parameters,
////for example, google geocode/timezone api key for date command: //// for example, google geocode/timezone api key for date command:
//$telegram->setCommandConfig('date', array('google_api_key'=>'your_google_api_key_here')); //$telegram->setCommandConfig('date', ['google_api_key' => 'your_google_api_key_here']);
////Logging //// Logging
//$telegram->setLogRequests(true); //$telegram->setLogRequests(true);
//$telegram->setLogPath($BOT_NAME.'.log'); //$telegram->setLogPath($BOT_NAME . '.log');
//$telegram->setLogVerbosity(3); //$telegram->setLogVerbosity(3);
//$telegram->setDownloadPath("../Download"); //// Set custom Upload and Download path
//$telegram->setUploadPath("../Upload"); //$telegram->setDownloadPath('../Download');
//$telegram->setUploadPath('../Upload');
// handle telegram webhook request // Handle telegram webhook request
$telegram->handle(); $telegram->handle();
} catch (Longman\TelegramBot\Exception\TelegramException $e) { } catch (Longman\TelegramBot\Exception\TelegramException $e) {
//Silence is gold! // Silence is golden!
// log telegram errors // log telegram errors
// echo $e; // echo $e;
} }
<?php <?php
//Composer Loader // Load composer
$dir = realpath(__DIR__.'/..'); require __DIR__ . '/vendor/autoload.php';
$loader = require $dir.'/vendor/autoload.php';
$API_KEY = 'your_bot_api_key'; $API_KEY = 'your_bot_api_key';
$BOT_NAME = 'namebot'; $BOT_NAME = 'namebot';
$link = 'https://yourdomain/yourpath_to_hook.php'; $hook_url = 'https://yourdomain/path/to/hook.php';
try { try {
// create Telegram API object // Create Telegram API object
$telegram = new Longman\TelegramBot\Telegram($API_KEY, $BOT_NAME); $telegram = new Longman\TelegramBot\Telegram($API_KEY, $BOT_NAME);
// set webhook
$result = $telegram->setWebHook($link); // Set webhook
//Uncomment to use certificate $result = $telegram->setWebHook($hook_url);
//$result = $telegram->setWebHook($link, $path_certificate);
// Uncomment to use certificate
//$result = $telegram->setWebHook($hook_url, $path_certificate);
if ($result->isOk()) { if ($result->isOk()) {
echo $result->getDescription(); echo $result->getDescription();
} }
......
<?php <?php
//Composer Loader // Load composer
$loader = require __DIR__.'/vendor/autoload.php'; require __DIR__ . '/vendor/autoload.php';
$API_KEY = 'your_bot_api_key'; $API_KEY = 'your_bot_api_key';
$BOT_NAME = 'namebot'; $BOT_NAME = 'namebot';
try { try {
// create Telegram API object // Create Telegram API object
$telegram = new Longman\TelegramBot\Telegram($API_KEY, $BOT_NAME); $telegram = new Longman\TelegramBot\Telegram($API_KEY, $BOT_NAME);
// set webhook
// Unset webhook
$result = $telegram->unsetWebHook(); $result = $telegram->unsetWebHook();
//Uncomment to use certificate
//$result = $telegram->setWebHook($link, $path_certificate);
if ($result->isOk()) { if ($result->isOk()) {
echo $result->getDescription(); echo $result->getDescription();
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment