#!/usr/bin/env php <?php #bash script #while true; do ./getUpdatesCLI.php; done //Composer Loader $loader = (require __DIR__ . '/vendor/autoload.php'); $API_KEY = 'your_bot_api_key'; $BOT_NAME = 'namebot'; //$COMMANDS_FOLDER = __DIR__.'/Commands/'; $credentials = array('host' => 'localhost', 'user' => 'dbuser', 'password' => 'dbpass', 'database' => 'dbname'); try { // create Telegram API object $telegram = new Longman\TelegramBot\Telegram($API_KEY, $BOT_NAME); //Options $telegram->enableMySQL($credentials); //$telegram->enableMySQL($credentials, $BOT_NAME.'_'); //$telegram->addCommandsPath($COMMANDS_FOLDER); //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')); //$telegram->setLogRequests(true); //$telegram->setLogPath($BOT_NAME.'.log'); // handle telegram getUpdate request $telegram->handleGetUpdates(); } catch (Longman\TelegramBot\Exception\TelegramException $e) { // log telegram errors echo $e->getMessage(); }
<?php // Load composer require __DIR__ . '/vendor/autoload.php'; $API_KEY = 'your_bot_api_key'; $BOT_NAME = 'namebot'; $hook_url = 'https://yourdomain/path/to/hook.php'; try { // Create Telegram API object $telegram = new Longman\TelegramBot\Telegram($API_KEY, $BOT_NAME); // Set webhook $result = $telegram->setWebHook($hook_url); // Uncomment to use certificate //$result = $telegram->setWebHook($hook_url, $path_certificate); if ($result->isOk()) { echo $result->getDescription(); } } catch (Longman\TelegramBot\Exception\TelegramException $e) { echo $e; }
<?php //Composer Loader $loader = (require __DIR__ . '/vendor/autoload.php'); $API_KEY = 'your_bot_api_key'; $BOT_NAME = 'namebot'; //$COMMANDS_FOLDER = __DIR__.'/Commands/'; //$credentials = array('host'=>'localhost', 'user'=>'dbuser', 'password'=>'dbpass', 'database'=>'dbname'); try { // create Telegram API object $telegram = new Longman\TelegramBot\Telegram($API_KEY, $BOT_NAME); //Options //$telegram->enableMySQL($credentials); //$telegram->enableMySQL($credentials, $BOT_NAME.'_'); //$telegram->addCommandsPath($COMMANDS_FOLDER); // 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')); //$telegram->setLogRequests(true); //$telegram->setLogPath($BOT_NAME.'.log'); // handle telegram webhook request $telegram->handle(); } catch (Longman\TelegramBot\Exception\TelegramException $e) { // log telegram errors // echo $e; }
<?php require_once 'lib/medoo.php'; require_once 'class/log.class.php'; require __DIR__ . '/vendor/autoload.php'; if (file_exists('config.php')) { require_once 'config.php'; } else { die('Local config not found. Please create one from config.sample.php and name it config.php'); } require_once 'class/log.class.php'; require __DIR__ . '/vendor/autoload.php'; try { log::addLog('Chiamata webhooks'); // create Telegram API object $telegram = new Longman\TelegramBot\Telegram($token, $botname); $telegram->enableMySQL($credentials); $telegram->enableAdmins(array($adminId)); $telegram->setLogRequests(true); $telegram->setLogPath($botname . '.log'); $COMMANDS_FOLDER = __DIR__ . '/command/'; $telegram->addCommandsPath($COMMANDS_FOLDER); } catch (Longman\TelegramBot\Exception\TelegramException $e) { log::addLog(print_r($e, true)); }
<?php //Composer Loader $loader = (require __DIR__ . '/vendor/autoload.php'); $API_KEY = 'your_bot_api_key'; $BOT_NAME = 'namebot'; try { // create Telegram API object $telegram = new Longman\TelegramBot\Telegram($API_KEY, $BOT_NAME); // set webhook $result = $telegram->unsetWebHook(); //Uncomment to use certificate //$result = $telegram->setWebHook($link, $path_certificate); if ($result->isOk()) { echo $result->getDescription(); } } catch (Longman\TelegramBot\Exception\TelegramException $e) { echo $e; }
#!/usr/bin/env php <?php //README //This configuration file is intented to run the bot with the webhook method //Uncommented parameters must be filled #bash script #while true; do ./getUpdatesCLI.php; done // Load composer require __DIR__ . '/vendor/autoload.php'; $API_KEY = 'your_bot_api_key'; $BOT_NAME = 'username_bot'; //$commands_path = __DIR__ . '/Commands/'; $mysql_credentials = ['host' => 'localhost', 'user' => 'dbuser', 'password' => 'dbpass', 'database' => 'dbname']; try { // Create Telegram API object $telegram = new Longman\TelegramBot\Telegram($API_KEY, $BOT_NAME); // 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); //// 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']); //// 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 //$telegram->setLogRequests(true); //$telegram->setLogPath($BOT_NAME . '.log');
<?php //Composer Loader $loader = (require __DIR__ . '/vendor/autoload.php'); $API_KEY = '146668771:AAE9_zVF-YnDco0RcR-xxycUXeh1Cs15E6o'; $BOT_NAME = 'OfertixItBot'; $COMMANDS_FOLDER = __DIR__ . '/src/Commands/'; //$credentials = array('host'=>'localhost', 'user'=>'dbuser', 'password'=>'dbpass', 'database'=>'dbname'); try { // create Telegram API object $telegram = new Longman\TelegramBot\Telegram($API_KEY, $BOT_NAME); //Options //$telegram->enableMySQL($credentials); //$telegram->enableMySQL($credentials, $BOT_NAME.'_'); $telegram->addCommandsPath($COMMANDS_FOLDER); // 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')); $telegram->setLogRequests(true); $telegram->setLogPath($BOT_NAME . '.log'); $telegram->setLogVerbosity(4); //$telegram->setDownloadPath("../Download"); //$telegram->setUploadPath("../Upload"); // handle telegram webhook request $telegram->handle(); } catch (Longman\TelegramBot\Exception\TelegramException $e) { // log telegram errors echo $e; } catch (\Exception $e) { echo $e->getMessage(); }
<?php require __DIR__ . '/../vendor/autoload.php'; $filename = 'logfile.log'; $API_KEY = 'random'; $BOT_NAME = 'bot_name'; define('PHPUNIT_TESTSUITE', 'some value'); $CREDENTIALS = array('host' => 'localhost', 'user' => '', 'password' => '', 'database' => ''); $update = null; try { // Create Telegram API object $telegram = new Longman\TelegramBot\Telegram($API_KEY, $BOT_NAME); $telegram->enableMySQL($CREDENTIALS); foreach (new SplFileObject($filename) as $current_line) { $json_decoded = json_decode($update, true); if (!is_null($json_decoded)) { echo $update . "\n\n"; $update = null; if (empty($json_decoded)) { echo "Empty update: \n"; echo $update . "\n\n"; continue; } $telegram->processUpdate(new Longman\TelegramBot\Entities\Update($json_decoded, $BOT_NAME)); } $update .= $current_line; } } catch (Longman\TelegramBot\Exception\TelegramException $e) { // log telegram errors echo $e; }
//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'); $API_KEY = 'your_bot_api_key'; $BOT_NAME = 'namebot'; //$COMMANDS_FOLDER = __DIR__.'/Commands/'; //$credentials = [ // 'host'=>'localhost', // 'user'=>'dbuser', // 'password'=>'dbpass', // 'database'=>'dbname' //]; try { // 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.'_'); //$telegram->addCommandsPath($COMMANDS_FOLDER); ////Here you can enable admin interface ache the channel you want to manage //$telegram->enableAdmins(['your_telegram_id']); //$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')); ////Logging //$telegram->setLogRequests(true); //$telegram->setLogPath($BOT_NAME.'.log'); //$telegram->setLogVerbosity(3);
<?php //Composer Loader $loader = (require __DIR__ . '/vendor/autoload.php'); $API_KEY = 'your_bot_api_key'; $BOT_NAME = 'namebot'; $link = 'https://yourdomain/yourpath_to_hook.php'; try { // 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); if ($result->isOk()) { echo $result->getDescription(); } } catch (Longman\TelegramBot\Exception\TelegramException $e) { echo $e; }
<?php $loader = (require __DIR__ . '/vendor/autoload.php'); $API_KEY = '134756484:AAFXhc12rFLKWrnLDHCl-t1AU9d3-4oiOms'; $BOT_NAME = 'pintxobot'; try { // create Telegram API object $telegram = new Longman\TelegramBot\Telegram($API_KEY, $BOT_NAME); // set webhook //echo $telegram->setWebHook('https://opedue.appspot.com/'); echo $telegram->setWebHook('https://pintxobot.herokuapp.com/hook.php'); } catch (Longman\TelegramBot\Exception\TelegramException $e) { echo $e->getMessage(); }
<?php $loader = (require __DIR__ . '/vendor/autoload.php'); $API_KEY = 'your_bot_api_key'; $BOT_NAME = 'namebot'; try { // create Telegram API object $telegram = new Longman\TelegramBot\Telegram($API_KEY, $BOT_NAME); // 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')); // handle telegram webhook request $telegram->handle(); } catch (Longman\TelegramBot\Exception\TelegramException $e) { // log telegram errors // echo $e->getMessage(); }
<?php //Composer Loader $loader = (require __DIR__ . '/vendor/autoload.php'); $API_KEY = 'your_bot_api_key'; $BOT_NAME = 'namebot'; try { // create Telegram API object $telegram = new Longman\TelegramBot\Telegram($API_KEY, $BOT_NAME); // set webhook echo $telegram->setWebHook('https://yourdomain/yourpath_to_hook.php'); } catch (Longman\TelegramBot\Exception\TelegramException $e) { echo $e->getMessage(); }