Comments (6)
Dublicate of #59. I tested inline mode and it works well, attaching script below. Again - your description is unclear. You are only telling that something is not working, but not providing code examples and full error trace. I'm not responsible for mistakes you make in your project.
<?php
use WeStacks\TeleBot\Objects\Update;
use WeStacks\TeleBot\TeleBot;
require_once 'vendor/autoload.php';
$bot = new TeleBot([
'token' => '<token>'
]);
$bot->addHandler(function (TeleBot $bot, Update $update, callable $next) {
if (!isset($update->inline_query)) {
return $next();
}
return $bot->answerInlineQuery([
'inline_query_id' => $update->inline_query->id,
'results' => [[
'type' => 'article',
'id' => 'google',
'title' => 'Google',
'url' => 'http://google.com/',
'input_message_content' => [
'message_text' => $update->inline_query->query
]
]]
]);
});
$last_offset = 0;
while (true) {
$updates = $bot->getUpdates([
'offset' => $last_offset + 1
]);
foreach ($updates as $update) {
$bot->handleUpdate($update);
$last_offset = $update->update_id;
}
}
from telebot.
This is a test and in the file SearchMoviesInlineQuery.php
You can see is a very simple handler
But the update doesn't reach the handler and it exits in Type.php:96 because $value_type is equal to NULL
from telebot.
I've just cloned your project, and everything works as intended.
from telebot.
I really don't understand that it works properly in long polling mode
But it gives an error in the webhook
from telebot.
I figured it out. It is actually a bug. There is a weird behavior in Telegram's API: when the incoming update is inline query, there is a field - inline_query.offset
. Documentation says that this field is actually a string, however - when you receive updates using long polling, it sends an empty string, as docs say. But when they send a webhook request - they send NULL
, that is not passing validation in our library. It's kind of weird, but I guess we can write some "crutches" to expect this from webhooks.
UPD. Actually, by second though, it's not Telegram's API, but Laravel's middleware, that converts empty strings to NULL on every request. It's even easier to fix then. For quick fix: enter app/Http/Kernel.php
and remove ConvertEmptyStringsToNull
middleware from your global middleware list. In the next update, I'll write the webhook route in a way to bypass Laravel's global middleware
protected $middleware = [
// \Illuminate\Foundation\Http\Middleware\ConvertEmptyStringsToNull::class,
];
from telebot.
ok thank you
from telebot.
Related Issues (20)
- Wrong response from the webhook: 403 Forbidden HOT 1
- Clean up political shit from where it's fucked up like no place HOT 1
- Method answerInlineQuery missing in PHPDoc
- WebApps support HOT 1
- Invalid handler type HOT 1
- Error Handling HOT 4
- get error when use many hendlers in laravel HOT 2
- How can I make a Menu button which opening a web app? HOT 2
- Ошибка в документации HOT 1
- Can't run 2.0 on PHP 7.4 HOT 1
- Tests are failing when using handleUpdate() in loop HOT 2
- Cannot cast value of type NULL to type string in Inline mode HOT 3
- Upgrading from v1 to v2.4 HOT 2
- [BUG] message thread not found HOT 2
- [BUG] Declaration of Handler::write(array $record): void must be compatible with AbstractProcessingHandler::write(Monolog\LogRecord $record): void HOT 7
- Can you provide an example of a bot with laravel? HOT 1
- [BUG] Argument #1 ($bot) must be of type TeleBot, WeStacks\TeleBot\TeleBot given HOT 1
- Error in RequestInputHandler while executing $this->acceptInput()
- Laravel telebot config on database
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from telebot.