Closed foremtehan closed 4 years ago
Hi, without further details it's difficult to say where is the problem, can you send us your code? Do you see any error message in console?
I did these:
<?php
use Zanzara\Zanzara;
use Zanzara\Context;
require __DIR__ . '/vendor/autoload.php';
$bot = new Zanzara("TOKEN");
$bot->onCommand('onText', function (Context $ctx) {
$ctx->sendMessage('Hello');
});
$bot->run();
ini_set('max_execution_time', 0)
it will close)So, if you use $bot->onCommand('onText')
the bot will reply only on command /onText
. If you want the bot to reply to any message you can use the $bot->onMessage()
method.
For the problem of closing itself after 20s it's not necessary to set the max_execution_time
to 0
. When you run your script (php index.php
) do you see the Zanzara is listening...
message? Which version of PHP are you using?
you can use the $bot->onMessage()
Ok i change it but not working:
$bot->onMessage(function (Context $ctx) {
$ctx->sendMessage('Hello');
});
do you see the Zanzara is listening... message?
No, I dont (it doenst on cmd either):
Which version of PHP are you using?
PHP 7.4.1 (on XAMPP)
Hi, it's a certification problem of xampp. To fix this problem you need to change some configuration of the php.ini file. You can try with this way:
@bohzio thanks but its not working i also stop/started the xampp
We have just released the 0.3.1 version, this one doesn't resolve the problem, but the error should now be logged in console, so we can troubleshoot it. Can you upgrade to this version and check if there's any error in console? Thank you
@cheeghi :
Failed to call Telegram Bot Api, reason: RuntimeException: Connection to api.telegram.org:443 failed during DNS lookup: DNS error in C:\Users\\Docum
ents\TelegramBots\test\vendor\react\socket\src\HappyEyeBallsConnectionBuilder.php:129
Stack trace:
#0 C:\Users\\Documents\TelegramBots\test\vendor\react\promise\src\RejectedPromise.php(28): React\Socket\HappyEyeBallsConnectionBuilder->React\Socket
\{closure}(Object(RuntimeException))
#1 C:\Users\\Documents\TelegramBots\test\vendor\react\promise\src\Promise.php(134): React\Promise\RejectedPromise->then(NULL, Object(Closure))
#2 C:\Users\\Documents\TelegramBots\test\vendor\react\promise\src\Promise.php(168): React\Promise\Promise::React\Promise\{closure}(Object(React\Prom
ise\RejectedPromise))
#3 C:\Users\\Documents\TelegramBots\test\vendor\react\promise\src\Promise.php(148): React\Promise\Promise->settle(Object(React\Promise\RejectedPromi
se))
#4 C:\Users\\Documents\TelegramBots\test\vendor\react\promise\src\Promise.php(237): React\Promise\Promise->reject(Object(RuntimeException))
#5 C:\Users\\Documents\TelegramBots\test\vendor\react\promise\src\RejectedPromise.php(42): React\Promise\Promise::React\Promise\{closure}(Object(Run
timeException))
#6 C:\Users\\Documents\TelegramBots\test\vendor\react\promise\src\Promise.php(135): React\Promise\RejectedPromise->done(Object(Closure), Object(Clos
ure), Object(Closure))
#7 C:\Users\\Documents\TelegramBots\test\vendor\react\promise\src\Promise.php(168): React\Promise\Promise::React\Promise\{closure}(Object(React\Prom
ise\RejectedPromise))
#8 C:\Users\\Documents\TelegramBots\test\vendor\react\promise\src\Promise.php(148): React\Promise\Promise->settle(Object(React\Promise\RejectedPromi
se))
#9 C:\Users\\Documents\TelegramBots\test\vendor\react\promise\src\Promise.php(237): React\Promise\Promise->reject(Object(RuntimeException))
#10 C:\Users\\Documents\TelegramBots\test\vendor\react\dns\src\Query\CachingExecutor.php(56): React\Promise\Promise::React\Promise\{closure}(Object(
RuntimeException))
#11 C:\Users\\Documents\TelegramBots\test\vendor\react\promise\src\RejectedPromise.php(28): React\Dns\Query\CachingExecutor->React\Dns\Query\{closur
e}(Object(RuntimeException))
#12 C:\Users\\Documents\TelegramBots\test\vendor\react\promise\src\Promise.php(134): React\Promise\RejectedPromise->then(Object(Closure), Object(Clo
sure))
#13 C:\Users\\Documents\TelegramBots\test\vendor\react\promise\src\Promise.php(168): React\Promise\Promise::React\Promise\{closure}(Object(React\Pro
mise\RejectedPromise))
#14 C:\Users\\Documents\TelegramBots\test\vendor\react\promise\src\Promise.php(148): React\Promise\Promise->settle(Object(React\Promise\RejectedProm
ise))
#15 C:\Users\\Documents\TelegramBots\test\vendor\react\promise\src\Promise.php(237): React\Promise\Promise->reject(Object(RuntimeException))
#16 C:\Users\\Documents\TelegramBots\test\vendor\react\promise\src\RejectedPromise.php(42): React\Promise\Promise::React\Promise\{closure}(Object(Ru
ntimeException))
#17 C:\Users\\Documents\TelegramBots\test\vendor\react\promise\src\Promise.php(135): React\Promise\RejectedPromise->done(Object(Closure), Object(Clo
sure), Object(Closure))
#18 C:\Users\\Documents\TelegramBots\test\vendor\react\promise\src\Promise.php(168): React\Promise\Promise::React\Promise\{closure}(Object(React\Pro
mise\RejectedPromise))
#19 C:\Users\\Documents\TelegramBots\test\vendor\react\promise\src\Promise.php(148): React\Promise\Promise->settle(Object(React\Promise\RejectedProm
ise))
#20 C:\Users\\Documents\TelegramBots\test\vendor\react\promise\src\Promise.php(237): React\Promise\Promise->reject(Object(RuntimeException))
#21 C:\Users\\Documents\TelegramBots\test\vendor\react\promise\src\RejectedPromise.php(28): React\Promise\Promise::React\Promise\{closure}(Object(Ru
ntimeException))
#22 C:\Users\\Documents\TelegramBots\test\vendor\react\promise\src\Promise.php(134): React\Promise\RejectedPromise->then(Object(Closure), Object(Clo
sure))
#23 C:\Users\\Documents\TelegramBots\test\vendor\react\promise\src\Promise.php(168): React\Promise\Promise::React\Promise\{closure}(Object(React\Pro
mise\RejectedPromise))
#24 C:\Users\\Documents\TelegramBots\test\vendor\react\promise\src\Promise.php(148): React\Promise\Promise->settle(Object(React\Promise\RejectedProm
ise))
#25 C:\Users\\Documents\TelegramBots\test\vendor\react\promise\src\Promise.php(237): React\Promise\Promise->reject(Object(RuntimeException))
#26 C:\Users\\Documents\TelegramBots\test\vendor\react\dns\src\Query\SelectiveTransportExecutor.php(76): React\Promise\Promise::React\Promise\{closu
re}(Object(RuntimeException))
#27 C:\Users\\Documents\TelegramBots\test\vendor\react\promise\src\RejectedPromise.php(28): React\Dns\Query\SelectiveTransportExecutor->React\Dns\Qu
ery\{closure}(Object(RuntimeException))
#28 C:\Users\\Documents\TelegramBots\test\vendor\react\promise\src\Promise.php(134): React\Promise\RejectedPromise->then(Object(Closure), Object(Clo
sure))
#29 C:\Users\\Documents\TelegramBots\test\vendor\react\promise\src\Promise.php(168): React\Promise\Promise::React\Promise\{closure}(Object(React\Pro
mise\RejectedPromise))
#30 C:\Users\\Documents\TelegramBots\test\vendor\react\promise\src\Promise.php(148): React\Promise\Promise->settle(Object(React\Promise\RejectedProm
ise))
#31 C:\Users\\Documents\TelegramBots\test\vendor\react\promise\src\Promise.php(237): React\Promise\Promise->reject(Object(RuntimeException))
#32 C:\Users\\Documents\TelegramBots\test\vendor\react\promise\src\Deferred.php(43): React\Promise\Promise::React\Promise\{closure}(Object(RuntimeEx
ception))
#33 C:\Users\\Documents\TelegramBots\test\vendor\react\dns\src\Query\RetryExecutor.php(45): React\Promise\Deferred->reject(Object(RuntimeException))
#34 C:\Users\\Documents\TelegramBots\test\vendor\react\promise\src\RejectedPromise.php(28): React\Dns\Query\RetryExecutor->React\Dns\Query\{closure}
(Object(RuntimeException))
#35 C:\Users\\Documents\TelegramBots\test\vendor\react\promise\src\Promise.php(134): React\Promise\RejectedPromise->then(Object(Closure), Object(Clo
sure))
#36 C:\Users\\Documents\TelegramBots\test\vendor\react\promise\src\Promise.php(168): React\Promise\Promise::React\Promise\{closure}(Object(React\Pro
mise\RejectedPromise))
#37 C:\Users\\Documents\TelegramBots\test\vendor\react\promise\src\Promise.php(148): React\Promise\Promise->settle(Object(React\Promise\RejectedProm
ise))
#38 C:\Users\\Documents\TelegramBots\test\vendor\react\promise\src\Promise.php(237): React\Promise\Promise->reject(Object(React\Dns\Query\TimeoutExc
eption))
#39 C:\Users\\Documents\TelegramBots\test\vendor\react\promise\src\RejectedPromise.php(42): React\Promise\Promise::React\Promise\{closure}(Object(Re
act\Dns\Query\TimeoutException))
#40 C:\Users\\Documents\TelegramBots\test\vendor\react\promise\src\Promise.php(135): React\Promise\RejectedPromise->done(Object(Closure), Object(Clo
sure), Object(Closure))
#41 C:\Users\\Documents\TelegramBots\test\vendor\react\promise\src\Promise.php(168): React\Promise\Promise::React\Promise\{closure}(Object(React\Pro
mise\RejectedPromise))
#42 C:\Users\\Documents\TelegramBots\test\vendor\react\promise\src\Promise.php(148): React\Promise\Promise->settle(Object(React\Promise\RejectedProm
ise))
#43 C:\Users\\Documents\TelegramBots\test\vendor\react\promise\src\Promise.php(237): React\Promise\Promise->reject(Object(React\Promise\Timer\Timeou
tException))
#44 C:\Users\\Documents\TelegramBots\test\vendor\react\promise-timer\src\functions.php(47): React\Promise\Promise::React\Promise\{closure}(Object(Re
act\Promise\Timer\TimeoutException))
#45 C:\Users\\Documents\TelegramBots\test\vendor\react\event-loop\src\Timer\Timers.php(96): React\Promise\Timer\{closure}(Object(React\EventLoop\Tim
er\Timer))
#46 C:\Users\\Documents\TelegramBots\test\vendor\react\event-loop\src\StreamSelectLoop.php(184): React\EventLoop\Timer\Timers->tick()
#47 C:\Users\\Documents\TelegramBots\test\vendor\badfarm\zanzara\src\Zanzara\Zanzara.php(160): React\EventLoop\StreamSelectLoop->run()
#48 C:\Users\\Documents\TelegramBots\test\index.php(14): Zanzara\Zanzara->run()
#49 {main}
could you run this curl request? (be sure to keep "bot" in front of the token)
curl https://api.telegram.org/botYOUR-BOT-TOKEN/getMe
Yes it returns a json with my bot information, One thing, In my country telegram is blocked, But i'm behind a vpn , I can make a request via browser and git bash, ngrok, etc.., i can see the api.telegram.org:443
in the browser it redirect me to https://core.telegram.org/bots
Ok, could you try to manually set a dns server that works in your country?
<?php
use React\Socket\Connector;
use Zanzara\Zanzara;
use Zanzara\Context;
use Zanzara\Config;
require __DIR__ . '/vendor/autoload.php';
$loop = React\EventLoop\Factory::create();
$connector = new Connector($loop, array(
'timeout' => 3.0,
'dns' => '8.8.8.8'
));
$config = new Config();
$config->setConnector($connector);
$config->setLoop($loop);
$bot = new Zanzara("TOKEN", $config);
$bot->onCommand('start', function (Context $ctx) {
$ctx->sendMessage('Hello');
});
$bot->run();
Now this is working thanks you very much.
I did what you said in the doc but my bot doesnt response to me what is the problem ?