mirror of
https://github.com/tdlight-team/tdlight-telegram-bot-api.git
synced 2024-12-26 04:05:49 +01:00
Add custom methods
This commit is contained in:
commit
185885c2d2
@ -11,12 +11,17 @@ TDLight Telegram Bot API is 100% compatible with the official version.
|
||||
### Command `optimize_memory`
|
||||
Calling `optimize_memory` will remove old data from the in-memory cache and give the freed memory back to the os
|
||||
|
||||
### Additional features
|
||||
- getChat now resolves username for users
|
||||
- the `message` object now has the `views` field and `forwards` field
|
||||
- new method `getMessageInfo` to get a message (params: chat_id, message_id)
|
||||
|
||||
-----
|
||||
|
||||
|
||||
The Telegram Bot API provides an HTTP API for creating [Telegram Bots](https://core.telegram.org/bots).
|
||||
|
||||
If you've got any questions about bots or would like to report an issue with your bot, kindly contact us at [@BotSupport](https://t.me/BotSupport) in Telegram.
|
||||
If you've got any questions about bots or would like to report an issue with your bot, kindly contact [@BotSupport](https://t.me/BotSupport) in Telegram.
|
||||
|
||||
Please note that only global Bot API issues that affect all bots are suitable for this repository.
|
||||
|
||||
|
@ -250,6 +250,14 @@ bool Client::init_methods() {
|
||||
methods_.emplace("deletewebhook", &Client::process_set_webhook_query);
|
||||
methods_.emplace("getwebhookinfo", &Client::process_get_webhook_info_query);
|
||||
methods_.emplace("getfile", &Client::process_get_file_query);
|
||||
|
||||
//custom methods
|
||||
methods_.emplace("getmessageinfo", &Client::process_get_message_info_query);
|
||||
methods_.emplace("getparticipants", &Client::process_get_participants_query);
|
||||
methods_.emplace("deletemessages", &Client::process_delete_messages_query);
|
||||
methods_.emplace("togglegroupinvites", &Client::process_toggle_group_invites_query);
|
||||
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
@ -1479,6 +1487,12 @@ void Client::JsonMessage::store(JsonValueScope *scope) const {
|
||||
if (message_->edit_date > 0) {
|
||||
object("edit_date", message_->edit_date);
|
||||
}
|
||||
if (message_->views != 0) {
|
||||
object("views", message_->views);
|
||||
}
|
||||
if (message_->forwards != 0) {
|
||||
object("forwards", message_->forwards);
|
||||
}
|
||||
if (message_->initial_send_date > 0) {
|
||||
if (message_->initial_sender_user_id != 0) {
|
||||
object("forward_from", JsonUser(message_->initial_sender_user_id, client_));
|
||||
@ -3538,7 +3552,7 @@ void Client::check_chat(Slice chat_id_str, AccessRights access_rights, PromisedQ
|
||||
|
||||
if (chat_id_str[0] == '@') {
|
||||
return send_request(make_object<td_api::searchPublicChat>(chat_id_str.str()),
|
||||
std::make_unique<TdOnCheckChatCallback<OnSuccess>>(this, true, access_rights, std::move(query),
|
||||
std::make_unique<TdOnCheckChatCallback<OnSuccess>>(this, false, access_rights, std::move(query),
|
||||
std::move(on_success)));
|
||||
}
|
||||
|
||||
@ -7360,6 +7374,38 @@ td::Status Client::process_get_file_query(PromisedQueryPtr &query) {
|
||||
return Status::OK();
|
||||
}
|
||||
|
||||
|
||||
//start custom methods impl
|
||||
|
||||
td::Status Client::process_get_message_info_query(PromisedQueryPtr &query) {
|
||||
auto chat_id = query->arg("chat_id");
|
||||
auto message_id = get_message_id(query.get(), "message_id");
|
||||
check_message(chat_id, message_id, false, AccessRights::Read, "message", std::move(query),[this] (int64 chat_id, int64 message_id, PromisedQueryPtr query) {
|
||||
auto message = get_message(chat_id, message_id);
|
||||
answer_query(JsonMessage(message, false, "get message info", this), std::move(query));
|
||||
});
|
||||
|
||||
return Status::OK();
|
||||
}
|
||||
|
||||
td::Status Client::process_get_participants_query(PromisedQueryPtr &query) {
|
||||
answer_query(td::JsonFalse(), std::move(query), "Not implemented");
|
||||
return Status::OK();
|
||||
}
|
||||
|
||||
td::Status Client::process_delete_messages_query(PromisedQueryPtr &query) {
|
||||
answer_query(td::JsonFalse(), std::move(query), "Not implemented");
|
||||
return Status::OK();
|
||||
|
||||
}
|
||||
|
||||
td::Status Client::process_toggle_group_invites_query(PromisedQueryPtr &query) {
|
||||
answer_query(td::JsonFalse(), std::move(query), "Not implemented");
|
||||
return Status::OK();
|
||||
}
|
||||
|
||||
//end custom methods impl
|
||||
|
||||
void Client::do_get_file(object_ptr<td_api::file> file, PromisedQueryPtr query) {
|
||||
if (!parameters_->local_mode_ &&
|
||||
td::max(file->expected_size_, file->local_->downloaded_size_) > MAX_DOWNLOAD_FILE_SIZE) { // speculative check
|
||||
@ -7994,7 +8040,7 @@ void Client::json_store_file(td::JsonObjectScope &object, const td_api::file *fi
|
||||
object("file_size", file->size_);
|
||||
}
|
||||
if (with_path && file->local_->is_downloading_completed_) {
|
||||
if (parameters_->local_mode_) {
|
||||
if (parameters_->local_mode_ && !parameters_->use_relative_path_) {
|
||||
if (td::check_utf8(file->local_->path_)) {
|
||||
object("file_path", file->local_->path_);
|
||||
} else {
|
||||
@ -8922,6 +8968,11 @@ Client::FullMessageId Client::add_message(object_ptr<td_api::message> &&message,
|
||||
}
|
||||
}
|
||||
|
||||
if (message->interaction_info_ != nullptr) {
|
||||
message_info->views = message->interaction_info_->view_count_;
|
||||
message_info->forwards = message->interaction_info_->forward_count_;
|
||||
}
|
||||
|
||||
message_info->author_signature = std::move(message->author_signature_);
|
||||
|
||||
if (message->reply_in_chat_id_ != chat_id && message->reply_to_message_id_ != 0) {
|
||||
|
@ -487,6 +487,13 @@ class Client : public WebhookActor::Callback {
|
||||
Status process_get_webhook_info_query(PromisedQueryPtr &query);
|
||||
Status process_get_file_query(PromisedQueryPtr &query);
|
||||
|
||||
//custom methods
|
||||
Status process_get_message_info_query(PromisedQueryPtr &query);
|
||||
Status process_get_participants_query(PromisedQueryPtr &query);
|
||||
Status process_delete_messages_query(PromisedQueryPtr &query);
|
||||
Status process_toggle_group_invites_query(PromisedQueryPtr &query);
|
||||
|
||||
|
||||
void webhook_verified(td::string cached_ip_address) override;
|
||||
void webhook_success() override;
|
||||
void webhook_error(Status status) override;
|
||||
@ -643,6 +650,9 @@ class Client : public WebhookActor::Callback {
|
||||
object_ptr<td_api::MessageContent> content;
|
||||
object_ptr<td_api::ReplyMarkup> reply_markup;
|
||||
|
||||
int32 views = 0;
|
||||
int32 forwards = 0;
|
||||
|
||||
mutable bool is_reply_to_message_deleted = false;
|
||||
mutable bool is_content_changed = false;
|
||||
};
|
||||
|
@ -55,6 +55,8 @@ struct SharedData {
|
||||
|
||||
struct ClientParameters {
|
||||
bool local_mode_ = false;
|
||||
bool allow_http_ = false;
|
||||
bool use_relative_path_ = false;
|
||||
|
||||
td::int32 api_id_ = 0;
|
||||
td::string api_hash_;
|
||||
|
@ -171,6 +171,9 @@ int main(int argc, char *argv[]) {
|
||||
options.add_option('h', "help", "display this help text and exit", [&] { need_print_usage = true; });
|
||||
options.add_option('\0', "local", "allow the Bot API server to serve local requests",
|
||||
[&] { parameters->local_mode_ = true; });
|
||||
options.add_option('\0', "insecure", "allow the Bot API to send request via insecure HTTP", [&] { parameters->allow_http_ = true; });
|
||||
options.add_option('\0', "relative", "use relative file path in local mode", [&] { parameters->use_relative_path_ = true; });
|
||||
|
||||
options.add_checked_option(
|
||||
'\0', "api-id",
|
||||
"application identifier for Telegram API access, which can be obtained at https://my.telegram.org (defaults to "
|
||||
|
Loading…
Reference in New Issue
Block a user