Comments (4)
Hello! Theare are a bunch of logic mistakes in your code. As I understand you are trying to use inline mode for your bot. Сorrect me if i'm wrong.
The first thing, in your case your update is callback_query
which is not related to inline mode:
if ($update->callback_query) {
// Your code here
}
If you working with inline mode, you should validate inline_query
(also I recommend to use immediate return for cleaner syntax):
if (!$update->inline_query) return;
// Your code here
The second thing is answer for the query. Your inline result is article which don't have message_text
field. In article
type you should send input_message_content
object. Your final code should look something like this:
// Validated that update is inline_query
if (!$query = $update->inline_query) return;
// There may be should be some more validations if your query have some complex logic
$results = [];
$results[] = [
'type' => 'article',
'id' => '001',
'title' => 'Test',
'input_message_content' => [
'message_text' => 'Text of the first message'
]
];
$message = $bot->answerInlineQuery([
'inline_query_id' => $query->id,
'results' => $results
]);
Please make sure that you are fully familiar with the bot api documentation for the functionality you need. This question does not concern the library's operation. I should not help you learning bot api documentation because its free and public to read.
from telebot.
I got from telegram json started like that: {"update_id":580720058,"callback_query":{"id":"882510546334388439","from":{"id":
So I think this was callback_query.
With input_message_content in results[] I got this error: Forbidden: USER_BOT_INVALID
Thank you for your helping. I will read more about API and manual.
from telebot.
Вообще здесь какая-то путаница.
Как я делаю. Пользователь мне присылает команду, например /stop.
В обработке этого же $update->message я отправляю ему ответ, в котором есть Inline кнопка.
$message = $bot->sendMessage([
'chat_id' => $chat_id,
// 'reply_to_message_id' => $message_id,
'parse_mode' => 'HTML',
'text' => 'Ты <b>запретил</b> мне писать тебе. Теперь <b>только ты</b> сможешь снова возобновить наше общение. Напиши мне /start, чтобы снова начать.',
'reply_markup' => [
'inline_keyboard' => [[[
'text' => '/start',
'callback_data' => '/start',
]]]
]
]);
Там имеено inline keyboard https://core.telegram.org/bots/api#inlinekeyboardbutton
У кнопки есть параметр callback_data, который работает через CallbackQuery. При нажатии на кнопку, я получаю от телеграма входящий с этим callback_query, с id который int64 и начинается на 88. Но в этом же запросе у меня не получается тут же ему (юзеру) ответить на этот callback_query.
В итоге на кнопке недолго крутится индикатор, что что-то происходит, телеграм в течении двух минут 8 раз пытается забрать у меня ответ на callback_query, но ему это не удаётся сделать. И он забивает на конкретно этот callback_query.
В итоге при нажатии пользователем на кнопку ничего не происходит.
Хотя я могу не пытаться изменить то изначальное сообщение с inline кнопкой, а просто при получении callback_query запроса слать пользователю следующее сообщение. Можно и так.
Я просто видел других ботов в работе и они как-то иначе "сбрасывают" вращение этого индикатора загрузки. В мануале написано, что можно ответить пустой результат, чтобы у пользователя ничего нигде не высвечивалось, но я пока не догоняю, в чём там дело.
Почему-то какой-то разжёванной документации днём с огнём не сыщешь, не понимаю, почему так происходит.
Спасибо тебе за помощь и за библиотеку.
from telebot.
Всё. Кажется я разобрался. ;)
Ещё раз спасибо тебе огромное за твою помощь и за твою библиотеку.
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
- [Cannot cast value of type NULL to type string error in Inline mode] HOT 6
- 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.