Commit 61481e19 authored by Marco Boretto's avatar Marco Boretto

Merge pull request #99 from noplanman/correct_readme_and_examples

Correct readme and examples
parents f11c153c a6d527f2
This diff is collapsed.
......@@ -2,66 +2,65 @@
<?php
//README
//This configuration file is intented to run the bot with the webhook method
//Uncommented parameters must be filled
//Uncommented parameters must be filled
#bash script
#while true; do ./getUpdatesCLI.php; done
//Composer Loader
$dir = realpath(__DIR__.'/..');
$loader = require $dir.'/vendor/autoload.php';
// Load composer
require __DIR__ . '/vendor/autoload.php';
$API_KEY = 'your_bot_api_key';
$BOT_NAME = 'namebot';
//$COMMANDS_FOLDER = __DIR__.'/Commands/';
$credentials = [
'host'=>'localhost',
'user'=>'dbuser',
'password'=>'dbpass',
'database'=>'dbname'
//$commands_path = __DIR__ . '/Commands/';
$mysql_credentials = [
'host' => 'localhost',
'user' => 'dbuser',
'password' => 'dbpass',
'database' => 'dbname',
];
try {
// create Telegram API object
// Create Telegram API object
$telegram = new Longman\TelegramBot\Telegram($API_KEY, $BOT_NAME);
////Options
$telegram->enableMySQL($credentials);
////Enable mysql with table prefix
//$telegram->enableMySQL($credentials, $BOT_NAME.'_');
// Enable MySQL
$telegram->enableMySQL($mysql_credentials);
//$telegram->addCommandsPath($COMMANDS_FOLDER);
//// Enable MySQL with table prefix
//$telegram->enableMySQL($mysql_credentials, $BOT_NAME . '_');
////Here you can enable admin interface ache the channel you want to manage
//// Add an additional commands path
//$telegram->addCommandsPath($commands_path);
//// Here you can enable admin interface for the channel you want to manage
//$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,
////for example, google geocode/timezone api key for date command:
//$telegram->setCommandConfig('date', array('google_api_key'=>'your_google_api_key_here'));
//// 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']);
////Logging
//// Logging
//$telegram->setLogRequests(true);
//$telegram->setLogPath($BOT_NAME.'.log');
//$telegram->setLogPath($BOT_NAME . '.log');
//$telegram->setLogVerbosity(3);
//$telegram->setDownloadPath("../Download");
//$telegram->setUploadPath("../Upload");
//// Set custom Upload and Download path
//$telegram->setDownloadPath('../Download');
//$telegram->setUploadPath('../Upload');
// handle telegram getUpdate request
// Handle telegram getUpdate request
$ServerResponse = $telegram->handleGetUpdates();
if ($ServerResponse->isOk()) {
$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 {
print(date('Y-m-d H:i:s', time())." - Fail fetch updates\n");
echo $ServerResponse->printError()."\n";
print(date('Y-m-d H:i:s', time()) . ' - Failed to fetch updates' . "\n");
echo $ServerResponse->printError() . "\n";
}
} catch (Longman\TelegramBot\Exception\TelegramException $e) {
// log telegram errors
echo $e;
echo $e;
}
<?php
//README
//This configuration file is intented to run the bot with the webhook method.
//Uncommented parameters must be filled
//This configuration file is intended to run the bot with the webhook method.
//Uncommented parameters must be filled
//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
//Composer Loader
$dir = realpath(__DIR__.'/..');
$loader = require $dir.'/vendor/autoload.php';
// Load composer
require __DIR__ . '/vendor/autoload.php';
$API_KEY = 'your_bot_api_key';
$BOT_NAME = 'namebot';
//$COMMANDS_FOLDER = __DIR__.'/Commands/';
//$credentials = [
// 'host'=>'localhost',
// 'user'=>'dbuser',
// 'password'=>'dbpass',
// 'database'=>'dbname'
//$commands_path = __DIR__ . '/Commands/';
//$mysql_credentials = [
// 'host' => 'localhost',
// 'user' => 'dbuser',
// 'password' => 'dbpass',
// 'database' => 'dbname',
//];
try {
// create Telegram API object
// Create Telegram API object
$telegram = new Longman\TelegramBot\Telegram($API_KEY, $BOT_NAME);
////Options
$telegram->enableMySQL($credentials);
////Enable mysql with table prefix
//$telegram->enableMySQL($credentials, $BOT_NAME.'_');
//// Enable MySQL
//$telegram->enableMySQL($mysql_credentials);
//$telegram->addCommandsPath($COMMANDS_FOLDER);
//// Enable MySQL with table prefix
//$telegram->enableMySQL($mysql_credentials, $BOT_NAME . '_');
////Here you can enable admin interface ache the channel you want to manage
//// Add an additional commands path
//$telegram->addCommandsPath($commands_path);
//// Here you can enable admin interface for the channel you want to manage
//$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,
////for example, google geocode/timezone api key for date command:
//$telegram->setCommandConfig('date', array('google_api_key'=>'your_google_api_key_here'));
//// 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']);
////Logging
//// Logging
//$telegram->setLogRequests(true);
//$telegram->setLogPath($BOT_NAME.'.log');
//$telegram->setLogPath($BOT_NAME . '.log');
//$telegram->setLogVerbosity(3);
//$telegram->setDownloadPath("../Download");
//$telegram->setUploadPath("../Upload");
//// Set custom Upload and Download path
//$telegram->setDownloadPath('../Download');
//$telegram->setUploadPath('../Upload');
// handle telegram webhook request
// Handle telegram webhook request
$telegram->handle();
} catch (Longman\TelegramBot\Exception\TelegramException $e) {
//Silence is gold!
// Silence is golden!
// log telegram errors
// echo $e;
}
<?php
//Composer Loader
$dir = realpath(__DIR__.'/..');
$loader = require $dir.'/vendor/autoload.php';
// Load composer
require __DIR__ . '/vendor/autoload.php';
$API_KEY = 'your_bot_api_key';
$BOT_NAME = 'namebot';
$link = 'https://yourdomain/yourpath_to_hook.php';
$hook_url = 'https://yourdomain/path/to/hook.php';
try {
// create Telegram API object
// Create Telegram API object
$telegram = new Longman\TelegramBot\Telegram($API_KEY, $BOT_NAME);
// set webhook
$result = $telegram->setWebHook($link);
//Uncomment to use certificate
//$result = $telegram->setWebHook($link, $path_certificate);
// Set webhook
$result = $telegram->setWebHook($hook_url);
// Uncomment to use certificate
//$result = $telegram->setWebHook($hook_url, $path_certificate);
if ($result->isOk()) {
echo $result->getDescription();
}
......
<?php
//Composer Loader
$loader = require __DIR__.'/vendor/autoload.php';
// Load composer
require __DIR__ . '/vendor/autoload.php';
$API_KEY = 'your_bot_api_key';
$BOT_NAME = 'namebot';
try {
// create Telegram API object
// Create Telegram API object
$telegram = new Longman\TelegramBot\Telegram($API_KEY, $BOT_NAME);
// set webhook
// Unset webhook
$result = $telegram->unsetWebHook();
//Uncomment to use certificate
//$result = $telegram->setWebHook($link, $path_certificate);
if ($result->isOk()) {
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