// GCC 15 reports a false -Wmaybe-uninitialized on moved std::variant values (ttgui::json::Value); silenced for this file only. #pragma GCC diagnostic ignored "-Wmaybe-uninitialized" // TapiService: bots (FR-23): command list, inline query and sending a chosen inline result. Typed through tapi::Bots and // tapi::Messages::send_inline_result. #include "mologram/tapi/TapiCodec.hpp" #include "mologram/tapi/TapiService.hpp" namespace mologram { using js::Array; using js::Object; using js::Value; RpcResult TapiService::hBotCommands(const Value& p, const CancelFlag&) { Array a; for (const auto& c : client_->bots().get_commands(entity(p, "peer"))) { Object o; o["command"] = Value(c.command); o["description"] = Value(c.description); o["bot"] = Peer{PeerKind::User, c.bot_id}.toJson(); a.push_back(Value(std::move(o))); } Object r; r["commands"] = Value(std::move(a)); return RpcResult::success(Value(std::move(r))); } RpcResult TapiService::hBotInline(const Value& p, const CancelFlag&) { tapi::InlineAnswer ans = client_->bots().inline_results(entity(p, "bot"), entity(p, "peer"), js::getStr(p, "query")); Array a; for (const auto& r : ans.results) { Object o; o["id"] = Value(r.id); o["type"] = Value(r.type); o["title"] = Value(r.title); o["description"] = Value(r.description); a.push_back(Value(std::move(o))); } Object r; r["query_id"] = js::id(ans.query_id); r["next_offset"] = Value(ans.next_offset); r["results"] = Value(std::move(a)); return RpcResult::success(Value(std::move(r))); } RpcResult TapiService::hBotInlineSend(const Value& p, const CancelFlag&) { std::int64_t queryId = js::getId(p, "query_id"); if (queryId == 0) return RpcResult::failure(ErrorCode::BadParams, "bot.inline_send: query_id must be an id from bot.inline"); tapi::Message m = client_->messages().send_inline_result(entity(p, "peer"), queryId, js::getStr(p, "result_id"), 0, false, true); return RpcResult::success(TapiCodec::message(m).toJson()); } void TapiService::registerBots() { reg("bot.commands", &TapiService::hBotCommands); reg("bot.inline", &TapiService::hBotInline); reg("bot.inline_send", &TapiService::hBotInlineSend); } } // namespace mologram