badfarm / zanzara Goto Github PK
View Code? Open in Web Editor NEWAsynchronous PHP Telegram Bot Framework built on top of ReactPHP
License: MIT License
Asynchronous PHP Telegram Bot Framework built on top of ReactPHP
License: MIT License
when user wants to share his contact with keyboard button it gets force reply to the message own that keyboard and within conversation its sometimes necessary
Zanzara is listening...
Deprecated: Return type of Zanzara\Telegram\Type\Update::jsonSerialize() should either be compatible with JsonSerializable::jsonSerialize(): mixed, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice in /storage/emulated/0/vendor/badfarm/zanzara/src/Zanzara/Telegram/Type/Update.php on line 473
Deprecated: Return type of Zanzara\Telegram\Type\User::jsonSerialize() should either be compatible with JsonSerializable::jsonSerialize(): mixed, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice in /storage/emulated/0/vendor/badfarm/zanzara/src/Zanzara/Telegram/Type/User.php on line 225
Deprecated: Return type of Zanzara\Telegram\Type\Chat::jsonSerialize() should either be compatible with JsonSerializable::jsonSerialize(): mixed, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice in /storage/emulated/0/vendor/badfarm/zanzara/src/Zanzara/Telegram/Type/Chat.php on line 379
badfarm/zanzara version 0.6.1
I wrote a symfony command and this is the execute method:
protected function execute(InputInterface $input, OutputInterface $output)
{
$bot = $this->zanzaraFactory->create();
$bot->onCommand('start', function (Context $ctx) {
// doing stuff
$ctx->nextStep([$this, 'presentYou']);
});
}
when nextStep
is reached I get this Error:
Serialization of 'Closure' is not allowed in /Users/**/my-bot/vendor/badfarm/zanzara/src/Zanzara/ConversationManager.php:48
I tried this work-around:
$ctx->nextStep(\Closure::fromCallable([$this, 'presentYou']));
but another Error has been showed:
Call to a member function bindTo() on null in /Users/**/my-bot/vendor/opis/closure/src/SerializableClosure.php:264
Sorry for the few details but it is hard to debug asynchronous code.
A similar issue to the #4 is given when trying to edit the message produced by an inline request, for example:
$bot->onInlineQuery(function (Context $ctx) {
$ctx->answerInlineQuery([
[
'type' => 'article',
'id' => sha1(time()),
'title' => 'the title',
'input_message_content' => ['message_text' =>'content'],
'reply_markup' => [
'inline_keyboard' => [[['text' => 'Stop', 'callback_data' => 'stop']]]
]
]
], [
'cache_time' => 0
]);
});
$bot->onCbQueryData(['stop'], function (Context $ctx) {
$ctx->editMessageText('Canceled');
});
Produces:
Failed to process Telegram update , reason: Error: Call to a member function getId() on null in vendor\badfarm\zanzara\src\Zanzara\Telegram\TelegramTrait.php:1015
Stack trace:
#0 main.php(56): Zanzara\Context->editMessageText('Canceled')
#1 vendor\badfarm\zanzara\src\Zanzara\Listener\Listener.php(47): {closure}(Object(Zanzara\Context))
#2 vendor\badfarm\zanzara\src\Zanzara\Middleware\MiddlewareNode.php(46): Zanzara\Listener\Listener->handle(Object(Zanzara\Context), NULL)
#3 vendor\badfarm\zanzara\src\Zanzara\Zanzara.php(272): Zanzara\Middleware\MiddlewareNode->__invoke(Object(Zanzara\Context))
#4 vendor\badfarm\zanzara\src\Zanzara\Zanzara.php(245): Zanzara\Zanzara->processUpdate(Object(Zanzara\Telegram\Type\Update))
#5 vendor\react\promise\src\FulfilledPromise.php(28): Zanzara\Zanzara->Zanzara\{closure}(Array)
#6 vendor\react\promise\src\Promise.php(134): React\Promise\FulfilledPromise->then(Object(Closure), Object(Closure))
#7 vendor\react\promise\src\Promise.php(168): React\Promise\Promise::React\Promise\{closure}(Object(React\Promise\FulfilledPromise))
#8 vendor\react\promise\src\Promise.php(231): React\Promise\Promise->settle(Object(React\Promise\FulfilledPromise))
#9 vendor\react\promise\src\FulfilledPromise.php(42): React\Promise\Promise::React\Promise\{closure}(Array)
#10 vendor\react\promise\src\Promise.php(135): React\Promise\FulfilledPromise->done(Object(Closure), Object(Closure), Object(Closure))
#11 vendor\react\promise\src\Promise.php(168): React\Promise\Promise::React\Promise\{closure}(Object(React\Promise\FulfilledPromise))
#12 vendor\react\promise\src\Promise.php(231): React\Promise\Promise->settle(Object(React\Promise\FulfilledPromise))
#13 vendor\react\promise\src\Deferred.php(36): React\Promise\Promise::React\Promise\{closure}(Object(RingCentral\Psr7\Response))
#14 vendor\clue\buzz-react\src\Io\Transaction.php(91): React\Promise\Deferred->resolve(Object(RingCentral\Psr7\Response))
#15 vendor\react\promise\src\FulfilledPromise.php(28): Clue\React\Buzz\Io\Transaction->Clue\React\Buzz\Io\{closure}(Object(RingCentral\Psr7\Response))
#16 vendor\react\promise\src\Promise.php(134): React\Promise\FulfilledPromise->then(Object(Closure), Object(Closure))
#17 vendor\react\promise\src\Promise.php(168): React\Promise\Promise::React\Promise\{closure}(Object(React\Promise\FulfilledPromise))
#18 vendor\react\promise\src\Promise.php(231): React\Promise\Promise->settle(Object(React\Promise\FulfilledPromise))
#19 vendor\react\promise\src\FulfilledPromise.php(42): React\Promise\Promise::React\Promise\{closure}(Object(RingCentral\Psr7\Response))
#20 vendor\react\promise\src\Promise.php(135): React\Promise\FulfilledPromise->done(Object(Closure), Object(Closure), Object(Closure))
#21 vendor\react\promise\src\Promise.php(168): React\Promise\Promise::React\Promise\{closure}(Object(React\Promise\FulfilledPromise))
#22 vendor\react\promise\src\Promise.php(231): React\Promise\Promise->settle(Object(React\Promise\FulfilledPromise))
#23 vendor\react\promise\src\FulfilledPromise.php(42): React\Promise\Promise::React\Promise\{closure}(Object(RingCentral\Psr7\Response))
#24 vendor\react\promise\src\Promise.php(66): React\Promise\FulfilledPromise->done(Object(Closure), Object(Closure))
#25 vendor\react\promise\src\Promise.php(168): React\Promise\Promise::React\Promise\{closure}(Object(React\Promise\FulfilledPromise))
#26 vendor\react\promise\src\Promise.php(231): React\Promise\Promise->settle(Object(React\Promise\FulfilledPromise))
#27 vendor\react\promise\src\FulfilledPromise.php(42): React\Promise\Promise::React\Promise\{closure}(Object(RingCentral\Psr7\Response))
#28 vendor\react\promise\src\Promise.php(135): React\Promise\FulfilledPromise->done(Object(Closure), Object(Closure), Object(Closure))
#29 vendor\react\promise\src\Promise.php(168): React\Promise\Promise::React\Promise\{closure}(Object(React\Promise\FulfilledPromise))
#30 vendor\react\promise\src\Promise.php(231): React\Promise\Promise->settle(Object(React\Promise\FulfilledPromise))
#31 vendor\react\promise\src\FulfilledPromise.php(42): React\Promise\Promise::React\Promise\{closure}('{"ok":true,"res...')
#32 vendor\react\promise\src\Promise.php(135): React\Promise\FulfilledPromise->done(Object(Closure), Object(Closure), Object(Closure))
#33 vendor\react\promise\src\Promise.php(168): React\Promise\Promise::React\Promise\{closure}(Object(React\Promise\FulfilledPromise))
#34 vendor\react\promise\src\Promise.php(231): React\Promise\Promise->settle(Object(React\Promise\FulfilledPromise))
#35 vendor\react\promise-stream\src\functions.php(75): React\Promise\Promise::React\Promise\{closure}('{"ok":true,"res...')
#36 vendor\evenement\evenement\src\Evenement\EventEmitterTrait.php(123): React\Promise\Stream\{closure}()
#37 vendor\clue\buzz-react\src\Message\ReadableBodyStream.php(50): Evenement\EventEmitter->emit('close')
#38 vendor\clue\buzz-react\src\Message\ReadableBodyStream.php(151): Clue\React\Buzz\Message\ReadableBodyStream->close()
#39 vendor\clue\buzz-react\src\Message\ReadableBodyStream.php(33): Clue\React\Buzz\Message\ReadableBodyStream->handleEnd()
#40 vendor\evenement\evenement\src\Evenement\EventEmitterTrait.php(123): Clue\React\Buzz\Message\ReadableBodyStream->Clue\React\Buzz\Message\{closure}('{"ok":true,"res...')
#41 vendor\react\http-client\src\Response.php(97): Evenement\EventEmitter->emit('data', Array)
#42 vendor\evenement\evenement\src\Evenement\EventEmitterTrait.php(123): React\HttpClient\Response->handleData('{"ok":true,"res...')
#43 vendor\react\http-client\src\Request.php(169): Evenement\EventEmitter->emit('data', Array)
#44 vendor\evenement\evenement\src\Evenement\EventEmitterTrait.php(123): React\HttpClient\Request->handleData('HTTP/1.1 200 OK...')
#45 vendor\react\stream\src\Util.php(71): Evenement\EventEmitter->emit('data', Array)
#46 vendor\evenement\evenement\src\Evenement\EventEmitterTrait.php(123): React\Stream\Util::React\Stream\{closure}('HTTP/1.1 200 OK...')
#47 vendor\react\stream\src\DuplexResourceStream.php(193): Evenement\EventEmitter->emit('data', Array)
#48 vendor\react\event-loop\src\StreamSelectLoop.php(245): React\Stream\DuplexResourceStream->handleData(Resource id #187)
#49 vendor\react\event-loop\src\StreamSelectLoop.php(212): React\EventLoop\StreamSelectLoop->waitForStreamActivity(1976907)
#50 vendor\badfarm\zanzara\src\Zanzara\Zanzara.php(160): React\EventLoop\StreamSelectLoop->run()
#51 main.php(63): Zanzara\Zanzara->run()
#52 {main}
(Sorry for the iterative report, but without the previous fix i couldn't find this problem)
Hello folks Are there any plans to support PHP 8?
zanzara by default caching Closures into arrays in memory. But if you using file cache, Closures can't be serialized.
Hey i just required it with fresh laravel 8 project and i got these :
Your requirements could not be resolved to an installable set of packages.
Problem 1
- wyrihaximus/react-child-process-messenger[2.7.1, ..., 2.10.0] require doctrine/inflector ^1.0 -> found doctrine/inflector[v1.0, ..., 1.4.x-dev] but the package is fixed to 2.0.3 (lock file version) by a partial update and that version does not match. Make sure you list it as an argument for the update command.
- badfarm/zanzara 0.5.1 requires react/filesystem ^0.1.2 -> satisfiable by react/filesystem[v0.1.2, 0.1.x-dev].
- react/filesystem[v0.1.2, ..., 0.1.x-dev] require wyrihaximus/react-child-process-pool ^1.3 -> satisfiable by wyrihaximus/react-child-process-pool[1.3.0, ..., 1.6.0].
- wyrihaximus/react-child-process-pool 1.6.0 requires wyrihaximus/react-child-process-messenger ^2.10 -> satisfiable by wyrihaximus/react-child-process-messenger[2.10.0].
- wyrihaximus/react-child-process-pool[1.5.0, ..., 1.5.1] require wyrihaximus/react-child-process-messenger ^2.9 -> satisfiable by wyrihaximus/react-child-process-messenger[2.9.0, ..., 2.10.0].
- wyrihaximus/react-child-process-pool[1.3.0, ..., 1.4.2] require wyrihaximus/react-child-process-messenger ^2.7.1 -> satisfiable by wyrihaximus/react-child-process-messenger[2.7.1, ..., 2.10.0].
- Root composer.json requires badfarm/zanzara ^0.5.1 -> satisfiable by badfarm/zanzara[0.5.1].
Use the option --with-all-dependencies (-W) to allow upgrades, downgrades and removals for packages currently locked to specific versions.
Can you help me ?
Hey!
The banChatSenderChat method does not work. I specify the parameters correctly, I even tried it stupidly, the user can still send a message from the channels, also some error occurs on this method, but I cannot see it.
Example:
$target = $ctx->getMessage()->getChat()->getId();
$senderChat = $ctx->getMessage()->getSenderChat()->getId();
$ctx->banChatSenderChat($target,$senderChat);
Hello, can I get some data from the session at once
F.E:
$bot->getUserDataItem(['test', 'test1'], function ($test, $test1){
});
very inconvenient to get them one by one
Hello again, sorry for asking too many questions (I am new to this library).
How can I get chat_id outside of any listener or any methods using $bot?
like this:
$chat_id = ?; // I want to get chat_id here
$bot->onUpdate(function (Context $ctx) {
// some codes
});
$bot->onCommand('start', function (Context $ctx) {
// some other codes
});
I tried some ways:
$chat_id = $bot->getTelegram()->getChat()->getFrom()->getId(); // getChat() needs chat_id, I don't know why.
$chat_id = $bot->getTelegram()->getUpdates()->getFrom()->getId(); // I think it's just for the long polling method.
By the way, I use the webhook method.
Also, how can I access the original update (JSON) received from Telegram?
Thanks.
Hello, I cannot use zanzara with laravel
Problem 1
- Installation request for badfarm/zanzara ^0.3.1 -> satisfiable by badfarm/zanzara[0.3.1].
- Conclusion: remove doctrine/inflector 2.0.3
- Conclusion: don't install doctrine/inflector 2.0.3
- badfarm/zanzara 0.3.1 requires react/filesystem ^0.1.2 -> satisfiable by react/filesystem[0.1.x-dev, v0.1.2].
- react/filesystem 0.1.x-dev requires wyrihaximus/react-child-process-pool ^1.3 -> satisfiable by wyrihaximus/react-child-process-pool[1.3.0, 1.4.0, 1.4.1, 1.4.2, 1.5.0, 1.5.1, 1.6.0].
- react/filesystem v0.1.2 requires wyrihaximus/react-child-process-pool ^1.3 -> satisfiable by wyrihaximus/react-child-process-pool[1.3.0, 1.4.0, 1.4.1, 1.4.2, 1.5.0, 1.5.1, 1.6.0].
- wyrihaximus/react-child-process-pool 1.3.0 requires wyrihaximus/react-child-process-messenger ^2.7.1 -> satisfiable by wyrihaximus/react-child-process-messenger[2.10.0, 2.7.1, 2.7.2, 2.7.3, 2.8.0, 2.8.1, 2.8.2, 2.9.0, 2.9.1, 2.9.2, 2.9.3].
- wyrihaximus/react-child-process-pool 1.4.0 requires wyrihaximus/react-child-process-messenger ^2.7.1 -> satisfiable by wyrihaximus/react-child-process-messenger[2.10.0, 2.7.1, 2.7.2, 2.7.3, 2.8.0, 2.8.1, 2.8.2, 2.9.0, 2.9.1, 2.9.2, 2.9.3].
- wyrihaximus/react-child-process-pool 1.4.1 requires wyrihaximus/react-child-process-messenger ^2.7.1 -> satisfiable by wyrihaximus/react-child-process-messenger[2.10.0, 2.7.1, 2.7.2, 2.7.3, 2.8.0, 2.8.1, 2.8.2, 2.9.0, 2.9.1, 2.9.2, 2.9.3].
- wyrihaximus/react-child-process-pool 1.4.2 requires wyrihaximus/react-child-process-messenger ^2.7.1 -> satisfiable by wyrihaximus/react-child-process-messenger[2.10.0, 2.7.1, 2.7.2, 2.7.3, 2.8.0, 2.8.1, 2.8.2, 2.9.0, 2.9.1, 2.9.2, 2.9.3].
- wyrihaximus/react-child-process-pool 1.5.0 requires wyrihaximus/react-child-process-messenger ^2.9 -> satisfiable by wyrihaximus/react-child-process-messenger[2.10.0, 2.9.0, 2.9.1, 2.9.2, 2.9.3].
- wyrihaximus/react-child-process-pool 1.5.1 requires wyrihaximus/react-child-process-messenger ^2.9 -> satisfiable by wyrihaximus/react-child-process-messenger[2.10.0, 2.9.0, 2.9.1, 2.9.2, 2.9.3].
- wyrihaximus/react-child-process-pool 1.6.0 requires wyrihaximus/react-child-process-messenger ^2.10 -> satisfiable by wyrihaximus/react-child-process-messenger[2.10.0].
- wyrihaximus/react-child-process-messenger 2.10.0 requires doctrine/inflector ^1.0 -> satisfiable by doctrine/inflector[1.0.x-dev, 1.1.x-dev, 1.2.x-dev, 1.3.1, 1.3.x-dev, 1.4.0, 1.4.1, 1.4.2, 1.4.3, 1.4.x-dev, v1.0, v1.0.1, v1.1.0, v1.2.0, v1.3.0].
- wyrihaximus/react-child-process-messenger 2.7.1 requires doctrine/inflector ^1.0 -> satisfiable by doctrine/inflector[1.0.x-dev, 1.1.x-dev, 1.2.x-dev, 1.3.1, 1.3.x-dev, 1.4.0, 1.4.1, 1.4.2, 1.4.3, 1.4.x-dev, v1.0, v1.0.1, v1.1.0, v1.2.0, v1.3.0].
- wyrihaximus/react-child-process-messenger 2.7.2 requires doctrine/inflector ^1.0 -> satisfiable by doctrine/inflector[1.0.x-dev, 1.1.x-dev, 1.2.x-dev, 1.3.1, 1.3.x-dev, 1.4.0, 1.4.1, 1.4.2, 1.4.3, 1.4.x-dev, v1.0, v1.0.1, v1.1.0, v1.2.0, v1.3.0].
- wyrihaximus/react-child-process-messenger 2.7.3 requires doctrine/inflector ^1.0 -> satisfiable by doctrine/inflector[1.0.x-dev, 1.1.x-dev, 1.2.x-dev, 1.3.1, 1.3.x-dev, 1.4.0, 1.4.1, 1.4.2, 1.4.3, 1.4.x-dev, v1.0, v1.0.1, v1.1.0, v1.2.0, v1.3.0].
- wyrihaximus/react-child-process-messenger 2.8.0 requires doctrine/inflector ^1.0 -> satisfiable by doctrine/inflector[1.0.x-dev, 1.1.x-dev, 1.2.x-dev, 1.3.1, 1.3.x-dev, 1.4.0, 1.4.1, 1.4.2, 1.4.3, 1.4.x-dev, v1.0, v1.0.1, v1.1.0, v1.2.0, v1.3.0].
- wyrihaximus/react-child-process-messenger 2.8.1 requires doctrine/inflector ^1.0 -> satisfiable by doctrine/inflector[1.0.x-dev, 1.1.x-dev, 1.2.x-dev, 1.3.1, 1.3.x-dev, 1.4.0, 1.4.1, 1.4.2, 1.4.3, 1.4.x-dev, v1.0, v1.0.1, v1.1.0, v1.2.0, v1.3.0].
- wyrihaximus/react-child-process-messenger 2.8.2 requires doctrine/inflector ^1.0 -> satisfiable by doctrine/inflector[1.0.x-dev, 1.1.x-dev, 1.2.x-dev, 1.3.1, 1.3.x-dev, 1.4.0, 1.4.1, 1.4.2, 1.4.3, 1.4.x-dev, v1.0, v1.0.1, v1.1.0, v1.2.0, v1.3.0].
- wyrihaximus/react-child-process-messenger 2.9.0 requires doctrine/inflector ^1.0 -> satisfiable by doctrine/inflector[1.0.x-dev, 1.1.x-dev, 1.2.x-dev, 1.3.1, 1.3.x-dev, 1.4.0, 1.4.1, 1.4.2, 1.4.3, 1.4.x-dev, v1.0, v1.0.1, v1.1.0, v1.2.0, v1.3.0].
- wyrihaximus/react-child-process-messenger 2.9.1 requires doctrine/inflector ^1.0 -> satisfiable by doctrine/inflector[1.0.x-dev, 1.1.x-dev, 1.2.x-dev, 1.3.1, 1.3.x-dev, 1.4.0, 1.4.1, 1.4.2, 1.4.3, 1.4.x-dev, v1.0, v1.0.1, v1.1.0, v1.2.0, v1.3.0].
- wyrihaximus/react-child-process-messenger 2.9.2 requires doctrine/inflector ^1.0 -> satisfiable by doctrine/inflector[1.0.x-dev, 1.1.x-dev, 1.2.x-dev, 1.3.1, 1.3.x-dev, 1.4.0, 1.4.1, 1.4.2, 1.4.3, 1.4.x-dev, v1.0, v1.0.1, v1.1.0, v1.2.0, v1.3.0].
- wyrihaximus/react-child-process-messenger 2.9.3 requires doctrine/inflector ^1.0 -> satisfiable by doctrine/inflector[1.0.x-dev, 1.1.x-dev, 1.2.x-dev, 1.3.1, 1.3.x-dev, 1.4.0, 1.4.1, 1.4.2, 1.4.3, 1.4.x-dev, v1.0, v1.0.1, v1.1.0, v1.2.0, v1.3.0].
- Can only install one of: doctrine/inflector[1.4.0, 2.0.3].
- Can only install one of: doctrine/inflector[1.4.1, 2.0.3].
- Can only install one of: doctrine/inflector[1.4.2, 2.0.3].
- Can only install one of: doctrine/inflector[1.4.3, 2.0.3].
- Can only install one of: doctrine/inflector[1.4.x-dev, 2.0.3].
- Can only install one of: doctrine/inflector[1.0.x-dev, 2.0.3].
- Can only install one of: doctrine/inflector[1.1.x-dev, 2.0.3].
- Can only install one of: doctrine/inflector[1.2.x-dev, 2.0.3].
- Can only install one of: doctrine/inflector[1.3.1, 2.0.3].
- Can only install one of: doctrine/inflector[1.3.x-dev, 2.0.3].
- Can only install one of: doctrine/inflector[v1.0, 2.0.3].
- Can only install one of: doctrine/inflector[v1.0.1, 2.0.3].
- Can only install one of: doctrine/inflector[v1.1.0, 2.0.3].
- Can only install one of: doctrine/inflector[v1.2.0, 2.0.3].
- Can only install one of: doctrine/inflector[v1.3.0, 2.0.3].
- Installation request for doctrine/inflector (locked at 2.0.3) -> satisfiable by doctrine/inflector[2.0.3].```
Hey sir! @cheeghi
Thank you for the efforts on this project. I've used a couple of methods from it for my tasks today and they work very well!
I want to slightly change a $processingUpdate
workaround for the Polling class, to make a startPolling
method reference-free. It will help to make, for example, a custom delay between message processing. At the current state, this method is strictly depends on that referenced value. I want to place this logic in the more abstract code unit.
What do you think? Can I provide a pull request for this?
Thanks!
....
i have a lots of if
conditions in my app and sometimes i need to abort the script, How can i deal with such thing in zanzara ? because if i use die
zanzara closes itself
I'm testing zanzara in windows with laravel, I created a console class in laravel then pass the Context
object to another class:
After i run zanzara by php artisan zanzara
for some reason it immediately exit the script without any output (After i send one message to the bot)
I want listeners to recognize each chat type. I mean when i make new listener set that to just listen for updates from private chats
or something like this:
$bot->onMessage(function (Context $ctx){},'private');
so this function do not work when messages comes from group
(yes i can do it by
if ($ctx->getEffectiveChat()->getType() === 'private') {}
but without that would great)
a message keeps returning infinitely a few times when I run my bot.php, normal ?
message:
Zanzara is listening...
Failed to call Telegram Bot Api, method: getUpdates, params: {
"offset": 1,
"limit": 100,
"timeout": 50,
"allowed_updates": []
}, reason: {"error_code":409,"description":"Conflict: terminated by other getUpdates request; make sure that only one bot instance is running"}
I just tried this code below to show the /help command only in specified private chat with BotCommandScopeChat, but it applies on botCommandScopeDefault, where I'm wrong or how should I do this?
$ctx->setMyCommands(
[
['command' => 'help', 'description' => 'show the help message']
],
[
'scope' => [
'type' => 'chat', 'chat_id' => $ctx->getEffectiveUser()->getId()
],
'language_code' => 'en'
]);
someone help me, I want to send a message and edit it (sendmessage and editMessageText) can you send an example?
how do I use a database (Mysql - localhost) in the bot.php file?
Hey badfram, Thanks for your work.
I cant understand one thing in zanzara, Let me describe, I put some delay on the script to see if its truly an async or not :
$bot = new Zanzara("YOUR-BOT-TOKEN");
$bot->onCommand('start', function (Context $ctx) {
sleep(15);
$ctx->sendMessage('Hello');
});
$bot->run();
I send /start
with two separate account at the same time, Bot zanzara finished the updates in 30 seconds instead of 15, It responded one by one, Shouldn't it take the request and pass it to the event loop and ready for next request? Am i missing something ?
As suggested by @hamidqp, when the user calls $ctx->setGlobalData($key, $data, $ttl)
(or respectively user/chat data) the $ttl param should specific for that item. Right now, the ttl is shared for the whole data "array".
In this case:
$i = new InputFile($ctx->getEffectiveUser()->getId() . '.png');
$ctx->sendPhoto($i, [
'chat_id' => $id,
])->then(function (Message $message) {
var_dump($message);
});
The then
closure is never called. If done the the sendMessage
endpoint, works as expected.
Hi, todays the only thing i get from logs are bunch of these, but idk what could cause this problem, I guess the more users bot have the more these logs showing up.
Also im using the tdlight telegram bot api.
Failed to process Telegram update , reason: TypeError: Zanzara\Telegram\Type\Update::getUpdateType(): Return value must be of type string, null returned in /vendor/badfarm/zanzara/src/Zanzara/Telegram/Type/Update.php:339
Stack trace:
#0 /vendor/badfarm/zanzara/src/Zanzara/Listener/ListenerResolver.php(34): Zanzara\Telegram\Type\Update->getUpdateType()
#1 /vendor/badfarm/zanzara/src/Zanzara/UpdateMode/UpdateMode.php(88): Zanzara\Listener\ListenerResolver->resolveListeners()
#2 /vendor/badfarm/zanzara/src/Zanzara/UpdateMode/Polling.php(78): Zanzara\UpdateMode\UpdateMode->processUpdate()
#3 /vendor/react/promise/src/FulfilledPromise.php(28): Zanzara\UpdateMode\Polling->Zanzara\UpdateMode\{closure}()
#4 /vendor/react/promise/src/Promise.php(134): React\Promise\FulfilledPromise->then()
#5 /vendor/react/promise/src/Promise.php(168): React\Promise\Promise::React\Promise\{closure}()
...
Hi, Im running a bot 2 days and sometimes every minute Get this on logs! how I can get rid of them ?
Failed to call Telegram Bot Api, method: getUpdates, params: {
"offset": 508191280,
"limit": 100,
"timeout": 50,
"allowed_updates": []
}, reason: RuntimeException: Connection to tls://api.telegram.org:443 timed out after 60 seconds in /bot/vendor/react/socket/src/TimeoutConnector.php:41
Stack trace:
#0 /bot/vendor/react/promise/src/RejectedPromise.php(28): React\Socket\TimeoutConnector::React\Socket\{closure}()
#1 /bot/vendor/react/promise/src/Promise.php(134): React\Promise\RejectedPromise->then()
#2 /bot/vendor/react/promise/src/Promise.php(168): React\Promise\Promise::React\Promise\{closure}()
#3 /bot/vendor/react/promise/src/Promise.php(148): React\Promise\Promise->settle()
#4 /bot/vendor/react/promise/src/Promise.php(237): React\Promise\Promise->reject()
#5 /bot/vendor/react/promise-timer/src/functions.php(47): React\Promise\Promise::React\Promise\{closure}()
#6 /bot/vendor/react/event-loop/src/Timer/Timers.php(96): React\Promise\Timer\{closure}()
#7 /bot/vendor/react/event-loop/src/StreamSelectLoop.php(184): React\EventLoop\Timer\Timers->tick()
#8 /bot/vendor/badfarm/zanzara/src/Zanzara/Zanzara.php(85): React\EventLoop\StreamSelectLoop->run()
#9 /bot/bot.php(454): Zanzara\Zanzara->run()
#10 {main}
Failed to process Telegram update , reason: TypeError: Argument 1 passed to Zanzara\UpdateMode\Polling::Zanzara\UpdateMode\{closure}() must be an instance of Zanzara\Telegram\Type\Response\TelegramException, instance of RuntimeException given, called in /bot/vendor/react/promise/src/RejectedPromise.php on line 28 and defined in /bot/vendor/badfarm/zanz
ara/src/Zanzara/UpdateMode/Polling.php:83
Stack trace:
#0 /bot/vendor/react/promise/src/RejectedPromise.php(28): Zanzara\UpdateMode\Polling->Zanzara\UpdateMode\{closure}()
#1 /bot/vendor/react/promise/src/Promise.php(134): React\Promise\RejectedPromise->then()
#2 /bot/vendor/react/promise/src/Promise.php(168): React\Promise\Promise::React\Promise\{closure}()
#3 /bot/vendor/react/promise/src/Promise.php(148): React\Promise\Promise->settle()
#4 /bot/vendor/react/promise/src/Promise.php(237): React\Promise\Promise->reject()
#5 /bot/vendor/react/promise/src/RejectedPromise.php(42): React\Promise\Promise::React\Promise\{closure}()
#6 /bot/vendor/react/promise/src/Promise.php(135): React\Promise\RejectedPromise->done()
#7 /bot/vendor/react/promise/src/Promise.php(168): React\Promise\Promise::React\Promise\{closure}()
#8 /bot/vendor/react/promise/src/Promise.php(148): React\Promise\Promise->settle()
#9 /bot/vendor/react/promise/src/Promise.php(237): React\Promise\Promise->reject()
#10 /bot/vendor/react/promise/src/Deferred.php(43): React\Promise\Promise::React\Promise\{closure}()
#11 /bot/vendor/clue/buzz-react/src/Io/Transaction.php(99): React\Promise\Deferred->reject()
#12 /bot/vendor/react/promise/src/RejectedPromise.php(28): Clue\React\Buzz\Io\Transaction->Clue\React\Buzz\Io\{closure}()
#13 /bot/vendor/react/promise/src/Promise.php(134): React\Promise\RejectedPromise->then()
#14 /bot/vendor/react/promise/src/Promise.php(168): React\Promise\Promise::React\Promise\{closure}()
#15 /bot/vendor/react/promise/src/Promise.php(148): React\Promise\Promise->settle()
#16 /bot/vendor/react/promise/src/Promise.php(237): React\Promise\Promise->reject()
#17 /bot/vendor/react/promise/src/RejectedPromise.php(42): React\Promise\Promise::React\Promise\{closure}()
#18 /bot/vendor/react/promise/src/Promise.php(135): React\Promise\RejectedPromise->done()
#19 /bot/vendor/react/promise/src/Promise.php(168): React\Promise\Promise::React\Promise\{closure}()
#20 /bot/vendor/react/promise/src/Promise.php(148): React\Promise\Promise->settle()
#21 /bot/vendor/react/promise/src/Promise.php(237): React\Promise\Promise->reject()
#22 /bot/vendor/react/promise/src/RejectedPromise.php(42): React\Promise\Promise::React\Promise\{closure}()
#23 /bot/vendor/react/promise/src/Promise.php(135): React\Promise\RejectedPromise->done()
#24 /bot/vendor/react/promise/src/Promise.php(168): React\Promise\Promise::React\Promise\{closure}()
#25 /bot/vendor/react/promise/src/Promise.php(148): React\Promise\Promise->settle()
#26 /bot/vendor/react/promise/src/Promise.php(237): React\Promise\Promise->reject()
#27 /bot/vendor/react/promise/src/Deferred.php(43): React\Promise\Promise::React\Promise\{closure}()
#28 /bot/vendor/clue/buzz-react/src/Io/Sender.php(110): React\Promise\Deferred->reject()
#29 /bot/vendor/evenement/evenement/src/Evenement/EventEmitterTrait.php(123): Clue\React\Buzz\Io\Sender->Clue\React\Buzz\Io\{closure}()
#30 /bot/vendor/react/http-client/src/Request.php(203): Evenement\EventEmitter->emit()
#31 /bot/vendor/react/promise/src/RejectedPromise.php(28): React\HttpClient\Request->closeError()
#32 /bot/vendor/react/promise/src/Promise.php(134): React\Promise\RejectedPromise->then()
#33 /bot/vendor/react/promise/src/Promise.php(168): React\Promise\Promise::React\Promise\{closure}()
#34 /bot/vendor/react/promise/src/Promise.php(148): React\Promise\Promise->settle()
#35 /bot/vendor/react/promise/src/Promise.php(237): React\Promise\Promise->reject()
#36 /bot/vendor/react/promise/src/RejectedPromise.php(42): React\Promise\Promise::React\Promise\{closure}()
#37 /bot/vendor/react/promise/src/Promise.php(135): React\Promise\RejectedPromise->done()
#38 /bot/vendor/react/promise/src/Promise.php(168): React\Promise\Promise::React\Promise\{closure}()
#39 /bot/vendor/react/promise/src/Promise.php(148): React\Promise\Promise->settle()
#40 /bot/vendor/react/promise/src/Promise.php(237): React\Promise\Promise->reject()
#41 /bot/vendor/react/promise-timer/src/functions.php(47): React\Promise\Promise::React\Promise\{closure}()
#42 /bot/vendor/react/event-loop/src/Timer/Timers.php(96): React\Promise\Timer\{closure}()
#43 /bot/vendor/react/event-loop/src/StreamSelectLoop.php(184): React\EventLoop\Timer\Timers->tick()
#44 /bot/vendor/badfarm/zanzara/src/Zanzara/Zanzara.php(85): React\EventLoop\StreamSelectLoop->run()
#45 /bot/bot.php(454): Zanzara\Zanzara->run()
#46 {main}
I did what you said in the doc but my bot doesnt response to me what is the problem ?
When I use the poll that created by bot get this on Logs :
Failed to process Telegram update , reason: TypeError: Return value of Zanzara\Telegram\Type\Update::getUpdateType() must be of the type string, null returned in /home/xxx/bots/ChannelTest/ven
dor/badfarm/zanzara/src/Zanzara/Telegram/Type/Update.php:323
Stack trace:
#0 /home/xxx/bots/ChannelTest/vendor/badfarm/zanzara/src/Zanzara/Listener/ListenerResolver.php(36): Zanzara\Telegram\Type\Update->getUpdateType()
#1 /home/xxx/bots/ChannelTest/vendor/badfarm/zanzara/src/Zanzara/Zanzara.php(269): Zanzara\Listener\ListenerResolver->resolve()
#2 /home/xxx/bots/ChannelTest/vendor/badfarm/zanzara/src/Zanzara/Zanzara.php(245): Zanzara\Zanzara->processUpdate()
#3 /home/xxx/bots/ChannelTest/vendor/react/promise/src/FulfilledPromise.php(28): Zanzara\Zanzara->Zanzara\{closure}()
#4 /home/xxx/bots/ChannelTest/vendor/react/promise/src/Promise.php(134): React\Promise\FulfilledPromise->then()
#5 /home/xxx/bots/ChannelTest/vendor/react/promise/src/Promise.php(168): React\Promise\Promise::React\Promise\{closure}()
#6 /home/xxx/bots/ChannelTest/vendor/react/promise/src/Promise.php(231): React\Promise\Promise->settle()
#7 /home/xxx/bots/ChannelTest/vendor/react/promise/src/FulfilledPromise.php(42): React\Promise\Promise::React\Promise\{closure}()....
Currently, onCommand()
only supports commands alone and without parameters. I request this feature like this example:
/add_admin <chat-id> <roles> <some-other-parameteres>
/ban_user <chat-id>
...
I know I can implement these commands using onUpdate()
or listeners or other methods, but it would be great if it was using onCommand()
(As it should be).
Failed to call Telegram Bot Api, method: getWebhookInfo, params: {
"parse_mode": "HTML"
}, reason: RuntimeException: Connection to api.telegram.org:443 failed during DNS lookup. Last error for IPv4: DNS query for api.telegram.org (A) failed: too many retries. Previous error for IPv6: DNS query for api.telegram.org (AAAA) failed: too many retries in {my_path}/vendor/react/socket/src/HappyEyeBallsConnectionBuilder.php:145
Hi, everything worked before, and here people write to me that the bot has stopped working. The message above is displayed in the logs. Nothing has changed anywhere, what could have happened?
if there is not option like this please add
code:
$ctx->getMyCommands()->then(fn($result) => var_dump($result), fn($result) => var_dump($result));
result:
["message":protected]=>
string(29) "Class "Scalar" does not exist"
["string":"Exception":private]=>
string(0) ""
["code":protected]=>
int(-1)
["file":protected]=>
string(78) "/vendor/netresearch/jsonmapper/src/JsonMapper.php"
["line":protected]=>
int(655)
["trace":"Exception":private]=>
array(45) {
[0]=>
array(5) {
["file"]=>
string(78) "/vendor/netresearch/jsonmapper/src/JsonMapper.php"
["line"]=>
int(655)
["function"]=>
string(11) "__construct"
["class"]=>
string(15) "ReflectionClass"
["type"]=>
string(2) "->"
}
[1]=>
array(5) {
["file"]=>
string(78) "/vendor/netresearch/jsonmapper/src/JsonMapper.php"
["line"]=>
int(449)
["function"]=>
string(14) "createInstance"
["class"]=>
string(10) "JsonMapper"
["type"]=>
string(2) "->"
}
[2]=>
array(5) {
["file"]=>
string(82) "/vendor/badfarm/zanzara/src/Zanzara/ZanzaraMapper.php"
["line"]=>
int(54)
["function"]=>
string(8) "mapArray"
["class"]=>
string(10) "JsonMapper"
["type"]=>
string(2) "->"
}
[3]=>
array(5) {
["file"]=>
string(91) "/vendor/badfarm/zanzara/src/Zanzara/Telegram/TelegramTrait.php"
["line"]=>
int(1873)
["function"]=>
string(9) "mapObject"
["class"]=>
string(21) "Zanzara\ZanzaraMapper"
["type"]=>
string(2) "->"
}
[4]=>
array(5) {
["file"]=>
string(75) "/vendor/react/promise/src/FulfilledPromise.php"
["line"]=>
int(28)
["function"]=>
string(26) "Zanzara\Telegram\{closure}"
["class"]=>
string(15) "Zanzara\Context"
["type"]=>
string(2) "->"
}
[5]=>
array(5) {
["file"]=>
string(66) "/vendor/react/promise/src/Promise.php"
["line"]=>
int(134)
["function"]=>
string(4) "then"
["class"]=>
string(30) "React\Promise\FulfilledPromise"
["type"]=>
string(2) "->"
}
...
Is it possible to send a message to all user ids ? if so is there a way to assemble a code base for me to understand better?
In inline query replies, if an inline keyboard is added to the reply_markup, when a button on that message is pressed it throws an exception.
Snippet code:
$bot->onInlineQuery(function (Context $ctx) {
...
$ctx->answerInlineQuery([
[
'type' => 'article',
'id' => sha1(time()),
'title' => 'the title',
'input_message_content' => ['message_text' =>'content'],
'reply_markup' => [
'inline_keyboard' => [[['text' => 'OK', 'callback_data' => 'ok']]]
]
]
], [
'cache_time' => 0
]);
});
$bot->onCbQueryData(['ok'], function (Context $ctx) {
$message = $ctx->getCallbackQuery()->getMessage();
$ctx->deleteMessage($message->getChat()->getId(), $message->getMessageId());
});
Failed to process Telegram update , reason: Error: Call to a member function getChat() on null in vendor\badfarm\zanzara\src\Zanzara\Telegram\Type\Update.php:362
Stack trace:
#0 vendor\badfarm\zanzara\src\Zanzara\Zanzara.php(267): Zanzara\Telegram\Type\Update->detectUpdateType()
#1 vendor\badfarm\zanzara\src\Zanzara\Zanzara.php(245): Zanzara\Zanzara->processUpdate(Object(Zanzara\Telegram\Type\Update))
#2 vendor\react\promise\src\FulfilledPromise.php(28): Zanzara\Zanzara->Zanzara\{closure}(Array)
#3 vendor\react\promise\src\Promise.php(134): React\Promise\FulfilledPromise->then(Object(Closure), Object(Closure))
#4 vendor\react\promise\src\Promise.php(168): React\Promise\Promise::React\Promise\{closure}(Object(React\Promise\FulfilledPromise))
#5 vendor\react\promise\src\Promise.php(231): React\Promise\Promise->settle(Object(React\Promise\FulfilledPromise))
#6 vendor\react\promise\src\FulfilledPromise.php(42): React\Promise\Promise::React\Promise\{closure}(Array)
#7 vendor\react\promise\src\Promise.php(135): React\Promise\FulfilledPromise->done(Object(Closure), Object(Closure), Object(Closure))
#8 vendor\react\promise\src\Promise.php(168): React\Promise\Promise::React\Promise\{closure}(Object(React\Promise\FulfilledPromise))
#9 vendor\react\promise\src\Promise.php(231): React\Promise\Promise->settle(Object(React\Promise\FulfilledPromise))
#10 vendor\react\promise\src\Deferred.php(36): React\Promise\Promise::React\Promise\{closure}(Object(RingCentral\Psr7\Response))
#11 vendor\clue\buzz-react\src\Io\Transaction.php(91): React\Promise\Deferred->resolve(Object(RingCentral\Psr7\Response))
#12 vendor\react\promise\src\FulfilledPromise.php(28): Clue\React\Buzz\Io\Transaction->Clue\React\Buzz\Io\{closure}(Object(RingCentral\Psr7\Response))
#13 vendor\react\promise\src\Promise.php(134): React\Promise\FulfilledPromise->then(Object(Closure), Object(Closure))
#14 vendor\react\promise\src\Promise.php(168): React\Promise\Promise::React\Promise\{closure}(Object(React\Promise\FulfilledPromise))
#15 vendor\react\promise\src\Promise.php(231): React\Promise\Promise->settle(Object(React\Promise\FulfilledPromise))
#16 vendor\react\promise\src\FulfilledPromise.php(42): React\Promise\Promise::React\Promise\{closure}(Object(RingCentral\Psr7\Response))
#17 vendor\react\promise\src\Promise.php(135): React\Promise\FulfilledPromise->done(Object(Closure), Object(Closure), Object(Closure))
#18 vendor\react\promise\src\Promise.php(168): React\Promise\Promise::React\Promise\{closure}(Object(React\Promise\FulfilledPromise))
#19 vendor\react\promise\src\Promise.php(231): React\Promise\Promise->settle(Object(React\Promise\FulfilledPromise))
#20 vendor\react\promise\src\FulfilledPromise.php(42): React\Promise\Promise::React\Promise\{closure}(Object(RingCentral\Psr7\Response))
#21 vendor\react\promise\src\Promise.php(66): React\Promise\FulfilledPromise->done(Object(Closure), Object(Closure))
#22 vendor\react\promise\src\Promise.php(168): React\Promise\Promise::React\Promise\{closure}(Object(React\Promise\FulfilledPromise))
#23 vendor\react\promise\src\Promise.php(231): React\Promise\Promise->settle(Object(React\Promise\FulfilledPromise))
#24 vendor\react\promise\src\FulfilledPromise.php(42): React\Promise\Promise::React\Promise\{closure}(Object(RingCentral\Psr7\Response))
#25 vendor\react\promise\src\Promise.php(135): React\Promise\FulfilledPromise->done(Object(Closure), Object(Closure), Object(Closure))
#26 vendor\react\promise\src\Promise.php(168): React\Promise\Promise::React\Promise\{closure}(Object(React\Promise\FulfilledPromise))
#27 vendor\react\promise\src\Promise.php(231): React\Promise\Promise->settle(Object(React\Promise\FulfilledPromise))
#28 vendor\react\promise\src\FulfilledPromise.php(42): React\Promise\Promise::React\Promise\{closure}('{"ok":true,"res...')
#29 vendor\react\promise\src\Promise.php(135): React\Promise\FulfilledPromise->done(Object(Closure), Object(Closure), Object(Closure))
#30 vendor\react\promise\src\Promise.php(168): React\Promise\Promise::React\Promise\{closure}(Object(React\Promise\FulfilledPromise))
#31 vendor\react\promise\src\Promise.php(231): React\Promise\Promise->settle(Object(React\Promise\FulfilledPromise))
#32 vendor\react\promise-stream\src\functions.php(75): React\Promise\Promise::React\Promise\{closure}('{"ok":true,"res...')
#33 vendor\evenement\evenement\src\Evenement\EventEmitterTrait.php(123): React\Promise\Stream\{closure}()
#34 vendor\clue\buzz-react\src\Message\ReadableBodyStream.php(50): Evenement\EventEmitter->emit('close')
#35 vendor\clue\buzz-react\src\Message\ReadableBodyStream.php(151): Clue\React\Buzz\Message\ReadableBodyStream->close()
#36 vendor\clue\buzz-react\src\Message\ReadableBodyStream.php(33): Clue\React\Buzz\Message\ReadableBodyStream->handleEnd()
#37 vendor\evenement\evenement\src\Evenement\EventEmitterTrait.php(123): Clue\React\Buzz\Message\ReadableBodyStream->Clue\React\Buzz\Message\{closure}('{"ok":true,"res...')
#38 vendor\react\http-client\src\Response.php(97): Evenement\EventEmitter->emit('data', Array)
#39 vendor\evenement\evenement\src\Evenement\EventEmitterTrait.php(123): React\HttpClient\Response->handleData('{"ok":true,"res...')
#40 vendor\react\http-client\src\Request.php(169): Evenement\EventEmitter->emit('data', Array)
#41 vendor\evenement\evenement\src\Evenement\EventEmitterTrait.php(123): React\HttpClient\Request->handleData('HTTP/1.1 200 OK...')
#42 vendor\react\stream\src\Util.php(71): Evenement\EventEmitter->emit('data', Array)
#43 vendor\evenement\evenement\src\Evenement\EventEmitterTrait.php(123): React\Stream\Util::React\Stream\{closure}('HTTP/1.1 200 OK...')
#44 vendor\react\stream\src\DuplexResourceStream.php(193): Evenement\EventEmitter->emit('data', Array)
#45 vendor\react\event-loop\src\StreamSelectLoop.php(245): React\Stream\DuplexResourceStream->handleData(Resource id #284)
#46 vendor\react\event-loop\src\StreamSelectLoop.php(212): React\EventLoop\StreamSelectLoop->waitForStreamActivity(2000000)
#47 vendor\badfarm\zanzara\src\Zanzara\Zanzara.php(160): React\EventLoop\StreamSelectLoop->run()
#48 main.php(64): Zanzara\Zanzara->run()
#49 {main}
Hi, today I have noticed that the Conversations feature just works on text messages but I thought they can handle the next Update.
Is there a way to manage all the updates by setting the next step Or it makes deviate from the main purpose of the conversation?
Hey badfram, Thanks for your work!
Whether features are coming soon 5.5. version of the bot api?
Hey, how can I send a message without Context (without any listener or anything)?
I want to send a message on every update received from Telegram.
Another question, I'm creating a bot of tools that help people know information from a ZIPCODE
$bot->onCommand('zip', function (Context $ctx) {
however, the command (/zip) only works if the person types only /zip, but when someone tries to type the command informing the zipcode (ex: /zip 10080) the bot does not respond.
$bot = new Zanzara('...');
function asd(Context $ctx) {
$ctx->sendMessage($ctx->getCallbackQuery()->getData()); // this code is never reached on button press
}
$bot->onCommand('start', function (Context $ctx) {
$ctx->sendMessage('asdasd', [
'reply_markup' => json_encode([
'inline_keyboard' => [
[
['text' => 'test', 'callback_data' => 'test'],
],
],
]),
]);
$ctx->nextStep('asd');
});
$bot->run();
As the title says, you can't use inline keyboard/buttons to interact with the user in a conversation (snippet above). I think in general also for text messages that if the user is in an initiated coversation, you should prioritize the next handler in the conversation, over the listeners. For example https://github.com/botman/botman follow pretty much this approach.
My code - part of the code:
$bot->onCommand('start', function (Context $ctx) {
$chat_id = $ctx->getEffectiveChat()->getId();
$ctx->sendMessage("How to edit sent message?")->then(
function (\Zanzara\Telegram\Type\Message $msg) use ($ctx, $chat_id) {
$ctx->editMessageText("Just like this...", ['chat_id'=>$chat_id,'message_id' => $msg->getMessageId()]);
}
);
Terminal response:
Zanzara is listening...
Failed to call Telegram Bot Api, method: getUpdates, params: {
"offset": 1,
"limit": 100,
"timeout": 50,
"allowed_updates": []
}, reason: {"error_code":409,"description":"Conflict: terminated by other getUpdates request; make sure that only one bot instance is running"}
I wrote this code:
$bot->onCommand('start', function (Context $ctx) {
$kb = ['reply_markup' =>
['inline_keyboard' => [[
['callback_data' => '1, 'text' => 'One'],
['callback_data' => '2', 'text' => 'Two']
]], 'resize_keyboard' => true]
];
$ctx->sendMessage("How many item would you to search?", $kb);
});
// This function is called when the returned data is '1' or '2'
$bot->onCbQueryData(['1', '2'], function (Context $ctx) {
$ctx->sendMessage("Ok Thanks!");
});
How can I access the data inside onCbQueryData()
function?
$ctx->getMessage()
return null
. I want to know if '1' or '2' is returned.
Thank you for the work.
For example :
$bot = new Zanzara($_ENV['BOT_TOKEN']);
$bot->onCommand("start", function (Context $ctx) {
$ctx->sendMessage('<b>Hello')->then(
function (Message $message) {
// success
},
function (TelegramException $error) {
// failed
}
);
// ... in the meantime perform some queries on MySql
});
$bot->run();
Try to use this code, the error will not return
if you are using HTML formatting. Just for example. Therefore it is impossible to process unsent messages and send them with corrections.
Or is the problem just me?
Hi, Thanks for the full Asynchronous PHP Telegram Bot Framework it makes telegram bots so fast.
but actually, sometimes I really need several methods that work Continuous and cant use ->then for all of them.
example when want to forward a message to many chats and then save the message-id of the sent message.
or when want to send 50 messages to count 1 - 50, and many other things like that.
Got that error while installing package
Hey, how can I get message_id
of a message after sending it?
like this:
$message = $ctx->sendMessage("Editing message ...");
$message_id = $message->getMessage()->getMessageId(); // What should I do here?
And then I want to use it like this:
$ctx->editMessageText($message_id, "Message edited successfully.");
Maybe this is wrong. I did not find how to do it on the wiki.
You must know that after sending a message (or any other request), Telegram will send the result of this request in response. I want to get this response.
I think it is not possible to do this because of the use of ReactPHP in this library. Am I right?
I know there are many benefits to using ReactPHP, but how I use it confuses me.
Thank you for your effort in this project.
Hi, Im using Local Bot API Server for working with large files; but when i request for download or upload actually telegram-bot-api is downloading that and until download completed it dosnt respond to request (not like api.telegram.org) and makes this happend.
Failed to call Telegram Bot Api, method: sendDocument, params: {
"document": {},
"chat_id": 123456789,
"parse_mode": "HTML"
}, reason: RuntimeException: Request timed out after 60 seconds in /vendor/react/http/src/Io/Transaction.php:130
Stack trace:
#0 /vendor/react/event-loop/src/Timer/Timers.php(96): React\Http\Io\Transaction->React\Http\Io\{closure}()
#1 /vendor/react/event-loop/src/StreamSelectLoop.php(184): React\EventLoop\Timer\Timers->tick()
#2 /vendor/badfarm/zanzara/src/Zanzara/Zanzara.php(90): React\EventLoop\StreamSelectLoop->run()
#3 /main.php(240): Zanzara\Zanzara->run()
#4 {main}
wish i could contribute but i don't have enough knowledge :(
Hello, i am trying to use callback for inlinekeyboard, using pure example code from wiki but when i press the button one or two i don't get any response - the listener just won't execute
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.