mirror of
https://github.com/PaiGramTeam/telegram-bot-api.git
synced 2024-11-22 23:42:28 +00:00
Support WebApp buttons.
This commit is contained in:
parent
8bc5730532
commit
defcb52571
@ -1545,6 +1545,19 @@ class Client::JsonCallbackGame final : public Jsonable {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
class Client::JsonWebAppInfo final : public Jsonable {
|
||||||
|
public:
|
||||||
|
explicit JsonWebAppInfo(const td::string &url) : url_(url) {
|
||||||
|
}
|
||||||
|
void store(JsonValueScope *scope) const {
|
||||||
|
auto object = scope->enter_object();
|
||||||
|
object("url", url_);
|
||||||
|
}
|
||||||
|
|
||||||
|
private:
|
||||||
|
const td::string &url_;
|
||||||
|
};
|
||||||
|
|
||||||
class Client::JsonInlineKeyboardButton final : public Jsonable {
|
class Client::JsonInlineKeyboardButton final : public Jsonable {
|
||||||
public:
|
public:
|
||||||
explicit JsonInlineKeyboardButton(const td_api::inlineKeyboardButton *button) : button_(button) {
|
explicit JsonInlineKeyboardButton(const td_api::inlineKeyboardButton *button) : button_(button) {
|
||||||
@ -1593,6 +1606,11 @@ class Client::JsonInlineKeyboardButton final : public Jsonable {
|
|||||||
object("url", PSLICE() << "tg://user?id=" << type->user_id_);
|
object("url", PSLICE() << "tg://user?id=" << type->user_id_);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
case td_api::inlineKeyboardButtonTypeWebApp::ID: {
|
||||||
|
auto type = static_cast<const td_api::inlineKeyboardButtonTypeWebApp *>(button_->type_.get());
|
||||||
|
object("web_app", JsonWebAppInfo(type->url_));
|
||||||
|
break;
|
||||||
|
}
|
||||||
default:
|
default:
|
||||||
UNREACHABLE();
|
UNREACHABLE();
|
||||||
break;
|
break;
|
||||||
@ -4808,6 +4826,13 @@ td::Result<td_api::object_ptr<td_api::keyboardButton>> Client::get_keyboard_butt
|
|||||||
text, make_object<td_api::keyboardButtonTypeRequestPoll>(force_regular, force_quiz));
|
text, make_object<td_api::keyboardButtonTypeRequestPoll>(force_regular, force_quiz));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (has_json_object_field(object, "web_app")) {
|
||||||
|
TRY_RESULT(web_app, get_json_object_field(object, "web_app", JsonValue::Type::Object, false));
|
||||||
|
auto &web_app_object = web_app.get_object();
|
||||||
|
TRY_RESULT(url, get_json_object_string_field(web_app_object, "url"));
|
||||||
|
return make_object<td_api::keyboardButton>(text, make_object<td_api::keyboardButtonTypeWebApp>(url));
|
||||||
|
}
|
||||||
|
|
||||||
return make_object<td_api::keyboardButton>(text, nullptr);
|
return make_object<td_api::keyboardButton>(text, nullptr);
|
||||||
}
|
}
|
||||||
if (button.type() == JsonValue::Type::String) {
|
if (button.type() == JsonValue::Type::String) {
|
||||||
@ -4904,6 +4929,13 @@ td::Result<td_api::object_ptr<td_api::inlineKeyboardButton>> Client::get_inline_
|
|||||||
text, make_object<td_api::inlineKeyboardButtonTypeLoginUrl>(url, bot_user_id, forward_text));
|
text, make_object<td_api::inlineKeyboardButtonTypeLoginUrl>(url, bot_user_id, forward_text));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (has_json_object_field(object, "web_app")) {
|
||||||
|
TRY_RESULT(web_app, get_json_object_field(object, "web_app", JsonValue::Type::Object, false));
|
||||||
|
auto &web_app_object = web_app.get_object();
|
||||||
|
TRY_RESULT(url, get_json_object_string_field(web_app_object, "url"));
|
||||||
|
return make_object<td_api::inlineKeyboardButton>(text, make_object<td_api::inlineKeyboardButtonTypeWebApp>(url));
|
||||||
|
}
|
||||||
|
|
||||||
return Status::Error(400, "Text buttons are unallowed in the inline keyboard");
|
return Status::Error(400, "Text buttons are unallowed in the inline keyboard");
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -9467,6 +9499,11 @@ bool Client::are_equal_inline_keyboard_buttons(const td_api::inlineKeyboardButto
|
|||||||
auto rhs_type = static_cast<const td_api::inlineKeyboardButtonTypeUser *>(rhs->type_.get());
|
auto rhs_type = static_cast<const td_api::inlineKeyboardButtonTypeUser *>(rhs->type_.get());
|
||||||
return lhs_type->user_id_ == rhs_type->user_id_;
|
return lhs_type->user_id_ == rhs_type->user_id_;
|
||||||
}
|
}
|
||||||
|
case td_api::inlineKeyboardButtonTypeWebApp::ID: {
|
||||||
|
auto lhs_type = static_cast<const td_api::inlineKeyboardButtonTypeWebApp *>(lhs->type_.get());
|
||||||
|
auto rhs_type = static_cast<const td_api::inlineKeyboardButtonTypeWebApp *>(rhs->type_.get());
|
||||||
|
return lhs_type->url_ == rhs_type->url_;
|
||||||
|
}
|
||||||
default:
|
default:
|
||||||
UNREACHABLE();
|
UNREACHABLE();
|
||||||
return false;
|
return false;
|
||||||
|
@ -119,6 +119,7 @@ class Client final : public WebhookActor::Callback {
|
|||||||
class JsonEntity;
|
class JsonEntity;
|
||||||
class JsonVectorEntities;
|
class JsonVectorEntities;
|
||||||
class JsonCallbackGame;
|
class JsonCallbackGame;
|
||||||
|
class JsonWebAppInfo;
|
||||||
class JsonInlineKeyboardButton;
|
class JsonInlineKeyboardButton;
|
||||||
class JsonInlineKeyboard;
|
class JsonInlineKeyboard;
|
||||||
class JsonReplyMarkup;
|
class JsonReplyMarkup;
|
||||||
|
Loading…
Reference in New Issue
Block a user