php-telegram-bot / core

PHP Telegram Bot based on the official Telegram Bot API
MIT License
3.87k stars 951 forks source link

only 0.26 is work for me now .. [0.26.0 + is not work for me .. ] #262

Closed sndnvaps closed 7 years ago

sndnvaps commented 8 years ago

my project is https://github.com/sndnvaps/TelegramImageBot php := 5.5

sndnvaps commented 8 years ago

my bot name is @nx511jbot now use 0.26.0 not the latest update

jacklul commented 8 years ago

There was a lot of changes between 0.26.0 and the latest version, that bot might not be compatible with new version of the library.

You could either stick with 0.26.0 for your project (not recommended) or adjust your project's code to the new version of the library.

Things for sure that needs to be changed: -InlinequeryCommand.php now requires different usage (0.26.0 uses old usage which can be discountinued by Telegram anytime) -Webhook handler

MBoretto commented 8 years ago

@sndnvaps as jacklul said lot of things has change for 0.26. You need also to change also the log system: https://github.com/sndnvaps/TelegramImageBot/blob/master/webhook.php#L17

I think that you can be able to exploit the latest version without too much work since your project don't need the database!

Let us know if you manage!

sndnvaps commented 8 years ago

@MBoretto you mean like this https://github.com/akalongman/php-telegram-bot/blob/master/examples/hook.php#L42

@jacklul -InlinequeryCommand.php this php should be remove ?...

sndnvaps commented 8 years ago

change the webhook.php && sethook.php to make it support the latest version ,do it right ?

MBoretto commented 8 years ago

Should do the trick!

sndnvaps commented 8 years ago
commit 34ad807ff2d8622f1b4bf0a5bfdb4d0563448c1e
Author: sndnvaps <sndnvaps@gmail.com>
Date:   Mon Aug 1 20:13:52 2016 +0800

    test for v0.35.0

    Signed-off-by: sndnvaps <sndnvaps@gmail.com>

diff --git a/sethook.php b/sethook.php
index f90d98f..a3a88a2 100644
--- a/sethook.php
+++ b/sethook.php
@@ -23,4 +23,3 @@ try {
 } catch (Longman\TelegramBot\Exception\TelegramException $e) {
     echo $e;
 }
-?>
diff --git a/webhook.php b/webhook.php
index 0622152..c7d57bb 100644
--- a/webhook.php
+++ b/webhook.php
@@ -1,29 +1,58 @@
 <?php
-$loader = require __DIR__.'/vendor/autoload.php';
+//README
+//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.
+// Load composer
+require __DIR__ . '/vendor/autoload.php';

 $API_KEY = 'apikey';
 $BOT_NAME = 'namebot';
-$COMMANDS_FOLDER = __DIR__.'/Commands/';

+$commands_path = __DIR__ . '/Commands/';
 $upload_path = __DIR__ . '/Upload/';
-
+//$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);
-    
-    // set up Upload pic path 
-   $telegram->setUploadPath($upload_path);
-    // Log Telegram messages
-    $telegram->setLogRequests(true);
-   $telegram->setLogPath($BOT_NAME.'.log');
-   $telegram->setLogVerbosity(1);
+    //// 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);

-   // Custom commands folder
-   $telegram->addCommandsPath($COMMANDS_FOLDER);
-   
-    // handle telegram webhook request
+    //// 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
+    //\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');
+    //// Set custom Upload and Download path
+    //$telegram->setDownloadPath('../Download');
+    $telegram->setUploadPath($upload_path);
+    //// Botan.io integration
+    //$telegram->enableBotan('your_token');
+    // Handle telegram webhook request
     $telegram->handle();
 } catch (Longman\TelegramBot\Exception\TelegramException $e) {
-    // log telegram errors
+    // Silence is gold!
     // echo $e;
+    // log telegram errors
+    \Longman\TelegramBot\TelegramLog::error($e);
+} catch (Longman\TelegramBot\Exception\TelegramLogException $e) {
+    // Silence is gold! Uncomment this to catch log initilization errors
+    //echo $e;
 }

and change composer.json to 0.35, but not work for me ...

noplanman commented 8 years ago

@sndnvaps I've edited your comment to remove your API key and bot name. Take care of them, they are to be kept secret.

I strongly suggest you create a new token by sending /token to BotFather.

sndnvaps commented 8 years ago
[root@telbot bot]# composer update
You are running composer with xdebug enabled. This has a major impact on runtime performance. See https://getcomposer.org/xdebug
Do not run Composer as root/super user! See https://getcomposer.org/root for details
Loading composer repositories with package information
Updating dependencies (including require-dev)
  - Removing longman/telegram-bot (0.29)
  - Installing longman/telegram-bot (0.28.0)
    Loading from cache

Writing lock file
Generating autoload files

now work on botname v. 0.27.0

sndnvaps commented 8 years ago

my composer.json is

{
    "require": {
        "longman/telegram-bot": "^0.28.0"
    }
}
sndnvaps commented 8 years ago

when use other command , it will set whoami command to my bot , and get the loop of set it .. when return to 0.26.0 , all thing become normal..

noplanman commented 8 years ago

Please try enabling the logging and see if there is any error output to help find the problem. Just below initialising the $telegram object:

$telegram = new Longman\TelegramBot\Telegram($API_KEY, $BOT_NAME);

// Logging
Longman\TelegramBot\TelegramLog::initErrorLog(__DIR__ . '/' . $BOT_NAME . '_error.log');
Longman\TelegramBot\TelegramLog::initDebugLog(__DIR__ . '/' . $BOT_NAME . '_debug.log');
Longman\TelegramBot\TelegramLog::initUpdateLog(__DIR__ . '/' . $BOT_NAME . '_update.log');
MBoretto commented 8 years ago

Any news?

sndnvaps commented 8 years ago

non... i just not use it .. make me so confuse ..

noplanman commented 8 years ago

Hmm, this is very strange.

Have you tried updating to the latest version 0.35?

It makes sense to keep your library up to date, because Telegram makes changes too that will otherwise not work properly.

sndnvaps commented 8 years ago

i have try it , still not work .. in 0.26,0.27, it can run . but >= 0.28 it just not work for me ..

noplanman commented 8 years ago

Could you post the current hook.php you're using? I'll then modify it to include something to help debug the problem 👍

sndnvaps commented 8 years ago

this is my sethook.php file

<?php
//Composer Loader
$loader = require __DIR__.'/vendor/autoload.php';

$API_KEY = 'you_api_token';
// botname cann't contain with '@'
$BOT_NAME = 'bot_name';
$hook_url = 'https://www.youdomain.com/path/to/webhook.php';
// you should put certificate under ./cert folder 
// the server.crt should sign the nginx as same
//
#$certificate_file = __DIR__.'/cert/server.crt';
try {
    // create Telegram API object
    $telegram = new Longman\TelegramBot\Telegram($API_KEY, $BOT_NAME);
    // set webhook

    $result = $telegram->setWebHook($hook_url);
    //$result = $telegram->setWebHook($hook_url, $certificate_path);
    if ($result->isOk()) {
        echo $result->getDescription();
    }
} catch (Longman\TelegramBot\Exception\TelegramException $e) {
    echo $e;
}
noplanman commented 8 years ago

That's the sethook.php, not hook.php.

Anyway, add the following line to the hook.php file, just under the $telegram = ... line, like so:

// create Telegram API object
$telegram = new Longman\TelegramBot\Telegram($API_KEY, $BOT_NAME);

// test with custom input
$telegram->setCustomInput('{"update_id":12345, "message":{"message_id":1,"from":{"id":<your-id>,"first_name":"First","username":"<your-username>"},"chat":{"id":<your-chat-id>,"first_name":"First","username":"<your-username>","type":"private"},"date":1,"text":"\/echo Working!"}}');

Be sure to change the <your-*> fields to the correct values. For a private chat, <your-id> and <your-chat-id> will be the same.

Now call the hook.php file directly in your web browser. You should get a Working! message on Telegram and the output of the page should be empty.

If there is an error there, post it here please.

noplanman commented 8 years ago

@sndnvaps Any update on this?

MBoretto commented 7 years ago

closing feel free to reopen