Git Product home page Git Product logo

Comments (6)

punyflash avatar punyflash commented on June 17, 2024

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.

DyarWeb avatar DyarWeb commented on June 17, 2024

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.

punyflash avatar punyflash commented on June 17, 2024

I've just cloned your project, and everything works as intended.
image
image

from telebot.

DyarWeb avatar DyarWeb commented on June 17, 2024

I really don't understand that it works properly in long polling mode
Screenshot from 2022-12-16 17-14-49
image

But it gives an error in the webhook
Screenshot from 2022-12-16 17-23-51
image

from telebot.

punyflash avatar punyflash commented on June 17, 2024

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.

DyarWeb avatar DyarWeb commented on June 17, 2024

ok thank you

from telebot.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.