mirror of
https://github.com/tdlight-team/tdlight-telegram-bot-api.git
synced 2024-09-01 12:05:41 +02:00
Add setChatMenuButton.
This commit is contained in:
parent
84199e5328
commit
7a2f3715f9
@ -195,6 +195,7 @@ bool Client::init_methods() {
|
||||
methods_.emplace("getmydefaultadministratorrights", &Client::process_get_my_default_administrator_rights_query);
|
||||
methods_.emplace("setmydefaultadministratorrights", &Client::process_set_my_default_administrator_rights_query);
|
||||
methods_.emplace("getchatmenubutton", &Client::process_get_chat_menu_button_query);
|
||||
methods_.emplace("setchatmenubutton", &Client::process_set_chat_menu_button_query);
|
||||
methods_.emplace("getuserprofilephotos", &Client::process_get_user_profile_photos_query);
|
||||
methods_.emplace("sendmessage", &Client::process_send_message_query);
|
||||
methods_.emplace("sendanimation", &Client::process_send_animation_query);
|
||||
@ -4921,7 +4922,7 @@ td::Result<td_api::object_ptr<td_api::keyboardButton>> Client::get_keyboard_butt
|
||||
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"));
|
||||
TRY_RESULT(url, get_json_object_string_field(web_app_object, "url", false));
|
||||
return make_object<td_api::keyboardButton>(text, make_object<td_api::keyboardButtonTypeWebApp>(url));
|
||||
}
|
||||
|
||||
@ -5024,7 +5025,7 @@ td::Result<td_api::object_ptr<td_api::inlineKeyboardButton>> Client::get_inline_
|
||||
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"));
|
||||
TRY_RESULT(url, get_json_object_string_field(web_app_object, "url", false));
|
||||
return make_object<td_api::inlineKeyboardButton>(text, make_object<td_api::inlineKeyboardButtonTypeWebApp>(url));
|
||||
}
|
||||
|
||||
@ -5937,6 +5938,51 @@ td::Result<td::vector<td_api::object_ptr<td_api::botCommand>>> Client::get_bot_c
|
||||
return std::move(bot_commands);
|
||||
}
|
||||
|
||||
td::Result<td_api::object_ptr<td_api::botMenuButton>> Client::get_bot_menu_button(JsonValue &&value) {
|
||||
if (value.type() != JsonValue::Type::Object) {
|
||||
return Status::Error(400, "MenuButton must be an Object");
|
||||
}
|
||||
|
||||
auto &object = value.get_object();
|
||||
|
||||
TRY_RESULT(type, get_json_object_string_field(object, "type", false));
|
||||
if (type == "default") {
|
||||
return td_api::make_object<td_api::botMenuButton>("", "default");
|
||||
}
|
||||
if (type == "commands") {
|
||||
return nullptr;
|
||||
}
|
||||
if (type == "web_app") {
|
||||
TRY_RESULT(text, get_json_object_string_field(object, "text", false));
|
||||
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", false));
|
||||
return td_api::make_object<td_api::botMenuButton>(text, url);
|
||||
}
|
||||
|
||||
return Status::Error(400, "MenuButton has unsupported type");
|
||||
}
|
||||
|
||||
td::Result<td_api::object_ptr<td_api::botMenuButton>> Client::get_bot_menu_button(const Query *query) {
|
||||
auto menu_button = query->arg("menu_button");
|
||||
if (menu_button.empty()) {
|
||||
return td_api::make_object<td_api::botMenuButton>("", "default");
|
||||
}
|
||||
|
||||
LOG(INFO) << "Parsing JSON object: " << menu_button;
|
||||
auto r_value = json_decode(menu_button);
|
||||
if (r_value.is_error()) {
|
||||
LOG(INFO) << "Can't parse JSON object: " << r_value.error();
|
||||
return Status::Error(400, "Can't parse menu button JSON object");
|
||||
}
|
||||
|
||||
auto r_menu_button = get_bot_menu_button(r_value.move_as_ok());
|
||||
if (r_menu_button.is_error()) {
|
||||
return Status::Error(400, PSLICE() << "Can't parse menu button: " << r_menu_button.error().message());
|
||||
}
|
||||
return r_menu_button.move_as_ok();
|
||||
}
|
||||
|
||||
td::Result<td_api::object_ptr<td_api::chatAdministratorRights>> Client::get_chat_administrator_rights(
|
||||
JsonValue &&value) {
|
||||
if (value.type() != JsonValue::Type::Object) {
|
||||
@ -6845,6 +6891,22 @@ td::Status Client::process_get_chat_menu_button_query(PromisedQueryPtr &query) {
|
||||
return Status::OK();
|
||||
}
|
||||
|
||||
td::Status Client::process_set_chat_menu_button_query(PromisedQueryPtr &query) {
|
||||
TRY_RESULT(menu_button, get_bot_menu_button(query.get()));
|
||||
if (query->has_arg("chat_id")) {
|
||||
TRY_RESULT(user_id, get_user_id(query.get(), "chat_id"));
|
||||
check_user(user_id, std::move(query),
|
||||
[this, user_id, menu_button = std::move(menu_button)](PromisedQueryPtr query) mutable {
|
||||
send_request(make_object<td_api::setMenuButton>(user_id, std::move(menu_button)),
|
||||
td::make_unique<TdOnOkQueryCallback>(std::move(query)));
|
||||
});
|
||||
} else {
|
||||
send_request(make_object<td_api::setMenuButton>(0, std::move(menu_button)),
|
||||
td::make_unique<TdOnOkQueryCallback>(std::move(query)));
|
||||
}
|
||||
return Status::OK();
|
||||
}
|
||||
|
||||
td::Status Client::process_get_user_profile_photos_query(PromisedQueryPtr &query) {
|
||||
TRY_RESULT(user_id, get_user_id(query.get()));
|
||||
int32 offset = get_integer_arg(query.get(), "offset", 0, 0);
|
||||
|
@ -369,6 +369,10 @@ class Client final : public WebhookActor::Callback {
|
||||
|
||||
static td::Result<td::vector<object_ptr<td_api::botCommand>>> get_bot_commands(const Query *query);
|
||||
|
||||
static td::Result<object_ptr<td_api::botMenuButton>> get_bot_menu_button(const Query *query);
|
||||
|
||||
static td::Result<object_ptr<td_api::botMenuButton>> get_bot_menu_button(td::JsonValue &&value);
|
||||
|
||||
static td::Result<object_ptr<td_api::chatAdministratorRights>> get_chat_administrator_rights(td::JsonValue &&value);
|
||||
|
||||
static td::Result<object_ptr<td_api::chatAdministratorRights>> get_chat_administrator_rights(const Query *query);
|
||||
@ -460,6 +464,7 @@ class Client final : public WebhookActor::Callback {
|
||||
Status process_get_my_default_administrator_rights_query(PromisedQueryPtr &query);
|
||||
Status process_set_my_default_administrator_rights_query(PromisedQueryPtr &query);
|
||||
Status process_get_chat_menu_button_query(PromisedQueryPtr &query);
|
||||
Status process_set_chat_menu_button_query(PromisedQueryPtr &query);
|
||||
Status process_get_user_profile_photos_query(PromisedQueryPtr &query);
|
||||
Status process_send_message_query(PromisedQueryPtr &query);
|
||||
Status process_send_animation_query(PromisedQueryPtr &query);
|
||||
|
Loading…
Reference in New Issue
Block a user