Comments (5)
здесь есть решения от автора через
public function on(Closure $event, Closure $checker = null)
{
$this->events->add($event, $checker);
return $this;
}
у меня почему-то так и не удалось принять через этот метод
через php://input можно принять
$output = json_decode(file_get_contents('php://input'), true);
file_put_contents('log.txt', print_r($output, true));
from api.
автор вы не могли бы залить в репозиторий рабочего бота с примером данного метода? смотрю просто полно вопросов об одном и том же...
from api.
@dddobriak для InlineKeyboardMarkup
использую file_get_contents
, метод command
не получится использовать для такого случая если динамический ответ может быть.
Свой код сейчас показывать не буду, попробую вечером сделать обработчик, дописать существующий или новый т.к. тот что сейчас я не делал, если не получится выложу уже просто код который сейчас использую на одном из проектов.
from api.
Я использую вот такую конструкцию.
Да, кстати, данные для callback'а передаются, как текст. /answer или answer - без разницы, передано будет "как есть". Поскольку это не команда боту в чате, то можно не заморачиваться со слэшем, боту всё равно. Если вам удобно/нужно - можно ставить.
$callback_loc, $find_command - это closures, которые выполняют, собственно, callback-команды
`$bot->on(function($update) use ($bot, $callback_loc, $find_command){
$callback = $update->getCallbackQuery();
$data = $callback->getData();
if (preg_match('/^location@[-\d.]+,[-\d.]+$/', $data))
$callback_loc($callback);
else
if (preg_match('/^find \d+ .+$/', $data))
$find_command($callback);
}, function($update){
$callback = $update->getCallbackQuery();
if (is_null($callback) || !strlen($callback->getData()))
return false;
return true;
});
`
Мы проверяем данные, переданные в callback, в зависимости от этих данных вызываем обработчик.
Внутри обработчика делаем так:
`$callback_loc = function ($callback) use ($bot) {
$message = $callback->getMessage();
$chatid = $message->getChat()->getId();
...
Получаем данные
$data = $callback->getData();
проверяем/обрабатываем
preg_match('/^location@([-\d.]+),([-\d.]+)$/', $data, $matches);
...
#Тут что-то делаем
В конце (или в начале, зависит от логики) обязательно вызываем этот метод, чтобы убрать "часики" к callback-кнопки
$bot->answerCallbackQuery($callback->getId());
};
`
from api.
@metavirus @dddobriak пример ещё можно посмотреть здесь: #29
from api.
Related Issues (20)
- Bot
- Can't Instantiate UserProfilePhotos HOT 1
- Не работает кнопка запроса номера телефона из телеграм бота. HOT 3
- Creating a Channel Invite Link with a Bot HOT 5
- Support chat_member and my_chat_member update
- No description provided.
- how to use ForceReply HOT 2
- how to send message with entities ?
- 悬赏求定制telegrambot
- Внезапно перестали работать БОТы HOT 2
- Как получить ID отправленного сообщения и ID чата HOT 8
- Need up setting up HOT 5
- delete_message
- Support BOT API 7.0 (december 29 2023)
- Support BOT API 7.1 (february 16 2024)
- Support BOT API 7.2 (march 31, 2024)
- Add a Compatibility Table HOT 1
- composer require telegram-bot/api
- Support Bot API 7.3 (may 6 2024)
- @lav095
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 api.