Skip to content

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

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
sndnvaps opened this issue Jul 31, 2016 · 21 comments
Closed

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

sndnvaps opened this issue Jul 31, 2016 · 21 comments

Comments

@sndnvaps
Copy link
Contributor

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

@sndnvaps
Copy link
Contributor Author

sndnvaps commented Jul 31, 2016

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

@jacklul
Copy link
Collaborator

jacklul commented Jul 31, 2016

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
Copy link
Collaborator

@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
Copy link
Contributor Author

sndnvaps commented Aug 1, 2016

@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
Copy link
Contributor Author

sndnvaps commented Aug 1, 2016

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

@MBoretto
Copy link
Collaborator

MBoretto commented Aug 1, 2016

Should do the trick!

@sndnvaps
Copy link
Contributor Author

sndnvaps commented Aug 1, 2016

commit 34ad807ff2d8622f1b4bf0a5bfdb4d0563448c1e
Author: sndnvaps <[email protected]>
Date:   Mon Aug 1 20:13:52 2016 +0800

    test for v0.35.0

    Signed-off-by: sndnvaps <[email protected]>

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
Copy link
Member

noplanman commented Aug 1, 2016

@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
Copy link
Contributor Author

sndnvaps commented Aug 2, 2016

[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
Copy link
Contributor Author

sndnvaps commented Aug 2, 2016

my composer.json is

{
    "require": {
        "longman/telegram-bot": "^0.28.0"
    }
}

@sndnvaps
Copy link
Contributor Author

sndnvaps commented Aug 2, 2016

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
Copy link
Member

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
Copy link
Collaborator

Any news?

@sndnvaps
Copy link
Contributor Author

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

@noplanman
Copy link
Member

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
Copy link
Contributor Author

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
Copy link
Member

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

@sndnvaps
Copy link
Contributor Author

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
Copy link
Member

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
Copy link
Member

@sndnvaps Any update on this?

@MBoretto
Copy link
Collaborator

closing feel free to reopen

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants