php-telegram-bot / core

PHP Telegram Bot based on the official Telegram Bot API
MIT License
3.9k stars 953 forks source link

getUpdateCLI.php Fail fetch updates #33

Closed camagenta closed 8 years ago

camagenta commented 9 years ago

Hi, I tried php-telegram-bot in my local server using Fail fetch getUpdateCLI.php

I just copied getUpdateCLI.php from D:\xampp\htdocs\tgbot\vendor\longman\telegram-bot to D:\xampp\htdocs\tgbot and edit botkey and boname, I'm also edit database config and import structure.sql.

when I tried to run getUpdateCLI.php, it said 2015-09-12 16:19:13 - Fail fetch updates

but, when I'm using https://api.telegram.org/bot-key/getUpdates It can give me the updates.

Can u tell me, what's wrong? Am I miss someting?

camagenta commented 9 years ago

update, when I'm enable the log feature.

$telegram->setLogRequests(true);
$telegram->setLogPath($BOT_NAME.'.log');

the result is:


D:\xampp\htdocs\tgbot>php getUpdatesCLI.php

Catchable fatal error: Object of class Longman\TelegramBot\Entities\ServerResponse could not be converted to string in D:\xampp\htdocs\tgbot\vendor\longman\telegram-bot\src\Request.php on line 80


line 80 Request.php : $status = file_put_contents($path, self::$input . "\n", FILE_APPEND);

I'm also tried to make emty file for log file manually : botname.log The result is still the same

then I open ServerResponse.php, on line 93, I enable this : throw new TelegramException('ok(variable) is not set!');

so, the result come like this


D:\xampp\htdocs\tgbot>php getUpdatesCLI.php ok(variable) is not set!


just to make sure, this getUpdate result using http api


{"ok":true,"result":[{"update_id":113043923, "message":{"message_id":12,"from":{"id":2212531,"first_name":"Kurnia","last_name":"Adhiwibowo","username":"camagenta"},"chat":{"id":2212531,"first_name":"Kurnia","last_name":"Adhiwibowo","username":"camagenta"},"date":1442067302,"text":"hi"}},{"update_id":113043924, "message":{"message_id":13,"from":{"id":2212531,"first_name":"Kurnia","last_name":"Adhiwibowo","username":"camagenta"},"chat":{"id":2212531,"first_name":"Kurnia","last_name":"Adhiwibowo","username":"camagenta"},"date":1442067304,"text":"hi"}}]}


weiddolo commented 9 years ago

Hi @camagenta, you have my same error, i have opened this issue (https://github.com/akalongman/php-telegram-bot/issues/31) but i am still without an answer!

camagenta commented 9 years ago

yes @weiddolo. But I'm not using webhook methods. I'm using the getUpdate methods.

Dunno, maybe the cause is same

MBoretto commented 9 years ago

Have you enabled the db?

MBoretto commented 9 years ago

Can you perform the procedure described here (the phpunit one) Did you define PHPUNIT_TESTSUITE somewhere?

weiddolo commented 9 years ago

@MBoretto I have added the MySQL credentials, i've opened getUpdatesCLI.php and i have got this message: 2015-09-16 16:14:32 - Fail fetch updates

weiddolo commented 9 years ago

@MBoretto I receive this error because I had previously set webhook. Now I reset the bot configuration and the bot responds when I update the page getUpdatesCLI.php.

Now work. But i how can I do a automatically replies without me surf on Page getUpdatesCLI.php

larknart commented 9 years ago

before i use webhook, i used getUpdatesCLI.php. To automatically replies without me surf on Page getUpdatesCLI.php, i used deamon:-

create a daemon configuration script under /etc/init ( NOT /etc/init.d ):-

nano /etc/init/mybot.conf

code sample:-

description "MyBot Daemon" author "larknart"

start on startup stop on shutdown respawn

exec /usr/share/getUpdateCLI.php

alter getUpdateCLI.php:-

below code:

while true; do ./getUpdatesCLI.php; done

add:-

$seconds = 5; $micro = $seconds * 1000000;

at end of code below:

}

add:-

usleep($micro);

create symbolic link to /usr/share/

ln -s /var/www/html/bot/getUpdateCLI.php /usr/share

after finish all those steps...now you can use " stop mybot | start mybot | status mybot " in terminal then you'll automatically get update.

MBoretto commented 8 years ago

@larknart Why don't you report your solution in the wiki page of your bot? It wuold be great!

MBoretto commented 8 years ago

feel free to reopen this