php-telegram-bot / core

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

Fatal error: Call to undefined method Longman\TelegramBot\Telegram::setWebHook() #153

Closed igimastudio closed 8 years ago

noplanman commented 8 years ago

Some context or something would be very helpful here. What exactly did you try and where did the error appear?

igimastudio commented 8 years ago

I just try to setWebHook and used set.php from example this part $telegram = new Longman\TelegramBot\Telegram($API_KEY, $BOT_NAME); is ok $result = $telegram->setWebHook($hook_url); is error

noplanman commented 8 years ago

That's strange... I don't understand how the first command can be ok but then it doesn't find the method 😕

To maybe help us, could you enter the following line directly after the $telegram = ... line and post the result here when you open the URL to your set.php:

die(var_dump($telegram));
igimastudio commented 8 years ago

object(Longman\TelegramBot\Telegram)#2 (6) { ["api_key":protected]=> string(45) "**_MY_APIKEY*******" ["input":protected]=> NULL ["commands_dir":protected]=> array(0) { } ["update":protected]=> NULL ["log_requests":protected]=> NULL ["log_path":protected]=> NULL }

noplanman commented 8 years ago

Right, so you have a valid object. @MBoretto Any idea why it doesn't find the method?!

MBoretto commented 8 years ago

Seems impossible also to me! php version system ?

igimastudio commented 8 years ago

PHP 5.6.19

noplanman commented 8 years ago

@igimastudio Have you managed to find out what the problem is/was? For us it's still a mystery why you get this error...

Are you maybe including the vendor autoloader multiple times?!

noplanman commented 8 years ago

@igimastudio If this is still an issue for you, feel free to reopen.

lawrencegs commented 8 years ago

This happened to me as well. Object created, but found the error:

PHP Fatal error: Call to undefined method Longman\TelegramBot\Telegram::handleGetUpdates() in /var/www/redacted/getUpdateCLI.php on line 22

Here is the getUpdateCLI.php code:

#!/usr/bin/env php
<?php
require __DIR__ . '/vendor/autoload.php';

$API_KEY = 'redacted:redacted';
$BOT_NAME = 'redactedBot';
$mysql_credentials = [
   'host'     => 'localhost',
   'user'     => 'root',
   'password' => 'redacted',
   'database' => 'redacted',
];

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

    // Enable MySQL
    $telegram->enableMySQL($mysql_credentials);

    // Handle telegram getUpdate request
    $telegram->handleGetUpdates();
} catch (Longman\TelegramBot\Exception\TelegramException $e) {
    // log telegram errors
    echo $e;
}
lawrencegs commented 8 years ago

Fixed. I created the composer.json manually (following README.md) and for some reason it didn't work. I then removed all the files, and use the composer require longman/telegram-bot method and it just works.

noplanman commented 8 years ago

@lawrencegs Do you know what was different in the automatically generated composer.json file?

I still can't understand how this happens.

MBoretto commented 8 years ago

What about put \ in front of longman?

 $telegram = new \Longman\TelegramBot\Telegram($API_KEY, $BOT_NAME);
hectorfarahani commented 7 years ago

I have same problem. Fatal error: Class 'Longman\TelegramBot\TelegramLog' not found in hook.php on line 35 Also I've noticed setWebHook worked correctly, but when i'm trying to unset it, unsetWebHook function is undefined. The set and unset methods are defined in same file.