Add td_api::getChatRevenueStatistics.
This commit is contained in:
parent
6848380bb7
commit
520062085d
@ -1184,7 +1184,7 @@ supergroup id:int53 usernames:usernames date:int32 status:ChatMemberStatus membe
|
|||||||
//@can_set_sticker_set True, if the supergroup sticker set can be changed
|
//@can_set_sticker_set True, if the supergroup sticker set can be changed
|
||||||
//@can_set_location True, if the supergroup location can be changed
|
//@can_set_location True, if the supergroup location can be changed
|
||||||
//@can_get_statistics True, if the supergroup or channel statistics are available
|
//@can_get_statistics True, if the supergroup or channel statistics are available
|
||||||
//@can_get_revenue True, if the supergroup or channel revenue statistics are available
|
//@can_get_revenue_statistics True, if the supergroup or channel revenue statistics are available
|
||||||
//@can_toggle_aggressive_anti_spam True, if aggressive anti-spam checks can be enabled or disabled in the supergroup
|
//@can_toggle_aggressive_anti_spam True, if aggressive anti-spam checks can be enabled or disabled in the supergroup
|
||||||
//@is_all_history_available True, if new chat members will have access to old messages. In public, discussion, of forum groups and all channels, old messages are always available,
|
//@is_all_history_available True, if new chat members will have access to old messages. In public, discussion, of forum groups and all channels, old messages are always available,
|
||||||
//-so this option affects only private non-forum supergroups without a linked chat. The value of this field is only available to chat administrators
|
//-so this option affects only private non-forum supergroups without a linked chat. The value of this field is only available to chat administrators
|
||||||
@ -1200,7 +1200,7 @@ supergroup id:int53 usernames:usernames date:int32 status:ChatMemberStatus membe
|
|||||||
//@bot_commands List of commands of bots in the group
|
//@bot_commands List of commands of bots in the group
|
||||||
//@upgraded_from_basic_group_id Identifier of the basic group from which supergroup was upgraded; 0 if none
|
//@upgraded_from_basic_group_id Identifier of the basic group from which supergroup was upgraded; 0 if none
|
||||||
//@upgraded_from_max_message_id Identifier of the last message in the basic group from which supergroup was upgraded; 0 if none
|
//@upgraded_from_max_message_id Identifier of the last message in the basic group from which supergroup was upgraded; 0 if none
|
||||||
supergroupFullInfo photo:chatPhoto description:string member_count:int32 administrator_count:int32 restricted_count:int32 banned_count:int32 linked_chat_id:int53 slow_mode_delay:int32 slow_mode_delay_expires_in:double can_get_members:Bool has_hidden_members:Bool can_hide_members:Bool can_set_sticker_set:Bool can_set_location:Bool can_get_statistics:Bool can_get_revenue:Bool can_toggle_aggressive_anti_spam:Bool is_all_history_available:Bool can_have_sponsored_messages:Bool has_aggressive_anti_spam_enabled:Bool has_pinned_stories:Bool my_boost_count:int32 unrestrict_boost_count:int32 sticker_set_id:int64 custom_emoji_sticker_set_id:int64 location:chatLocation invite_link:chatInviteLink bot_commands:vector<botCommands> upgraded_from_basic_group_id:int53 upgraded_from_max_message_id:int53 = SupergroupFullInfo;
|
supergroupFullInfo photo:chatPhoto description:string member_count:int32 administrator_count:int32 restricted_count:int32 banned_count:int32 linked_chat_id:int53 slow_mode_delay:int32 slow_mode_delay_expires_in:double can_get_members:Bool has_hidden_members:Bool can_hide_members:Bool can_set_sticker_set:Bool can_set_location:Bool can_get_statistics:Bool can_get_revenue_statistics:Bool can_toggle_aggressive_anti_spam:Bool is_all_history_available:Bool can_have_sponsored_messages:Bool has_aggressive_anti_spam_enabled:Bool has_pinned_stories:Bool my_boost_count:int32 unrestrict_boost_count:int32 sticker_set_id:int64 custom_emoji_sticker_set_id:int64 location:chatLocation invite_link:chatInviteLink bot_commands:vector<botCommands> upgraded_from_basic_group_id:int53 upgraded_from_max_message_id:int53 = SupergroupFullInfo;
|
||||||
|
|
||||||
|
|
||||||
//@class SecretChatState @description Describes the current secret chat state
|
//@class SecretChatState @description Describes the current secret chat state
|
||||||
@ -6578,6 +6578,16 @@ chatStatisticsSupergroup period:dateRange member_count:statisticalValue message_
|
|||||||
chatStatisticsChannel period:dateRange member_count:statisticalValue mean_message_view_count:statisticalValue mean_message_share_count:statisticalValue mean_message_reaction_count:statisticalValue mean_story_view_count:statisticalValue mean_story_share_count:statisticalValue mean_story_reaction_count:statisticalValue enabled_notifications_percentage:double member_count_graph:StatisticalGraph join_graph:StatisticalGraph mute_graph:StatisticalGraph view_count_by_hour_graph:StatisticalGraph view_count_by_source_graph:StatisticalGraph join_by_source_graph:StatisticalGraph language_graph:StatisticalGraph message_interaction_graph:StatisticalGraph message_reaction_graph:StatisticalGraph story_interaction_graph:StatisticalGraph story_reaction_graph:StatisticalGraph instant_view_interaction_graph:StatisticalGraph recent_interactions:vector<chatStatisticsInteractionInfo> = ChatStatistics;
|
chatStatisticsChannel period:dateRange member_count:statisticalValue mean_message_view_count:statisticalValue mean_message_share_count:statisticalValue mean_message_reaction_count:statisticalValue mean_story_view_count:statisticalValue mean_story_share_count:statisticalValue mean_story_reaction_count:statisticalValue enabled_notifications_percentage:double member_count_graph:StatisticalGraph join_graph:StatisticalGraph mute_graph:StatisticalGraph view_count_by_hour_graph:StatisticalGraph view_count_by_source_graph:StatisticalGraph join_by_source_graph:StatisticalGraph language_graph:StatisticalGraph message_interaction_graph:StatisticalGraph message_reaction_graph:StatisticalGraph story_interaction_graph:StatisticalGraph story_reaction_graph:StatisticalGraph instant_view_interaction_graph:StatisticalGraph recent_interactions:vector<chatStatisticsInteractionInfo> = ChatStatistics;
|
||||||
|
|
||||||
|
|
||||||
|
//@description A detailed statistics about revenue earned from sponsored messages in a chat
|
||||||
|
//@revenue_by_hour_graph A graph containing amount of revenue in a given hour
|
||||||
|
//@revenue_graph A graph containing amount of revenue
|
||||||
|
//@cryptocurrency Cryptocurrency in which revenue is calculated
|
||||||
|
//@cryptocurrency_total_amount Total amount of the cryptocurrency earned, in the smallest units of the cryptocurrency
|
||||||
|
//@cryptocurrency_balance_amount Amount of the cryptocurrency that isn't withdrawn yet, in the smallest units of the cryptocurrency
|
||||||
|
//@cryptocurrency_available_amount Amount of the cryptocurrency available for withdrawal, in the smallest units of the cryptocurrency
|
||||||
|
//@usd_rate Current conversion rate of the cryptocurrency to USD
|
||||||
|
chatRevenueStatistics revenue_by_hour_graph:StatisticalGraph revenue_graph:StatisticalGraph cryptocurrency:string cryptocurrency_total_amount:int64 cryptocurrency_balance_amount:int64 cryptocurrency_available_amount:int64 usd_rate:double = ChatRevenueStatistics;
|
||||||
|
|
||||||
//@description A detailed statistics about a message
|
//@description A detailed statistics about a message
|
||||||
//@message_interaction_graph A graph containing number of message views and shares
|
//@message_interaction_graph A graph containing number of message views and shares
|
||||||
//@message_reaction_graph A graph containing number of message reactions
|
//@message_reaction_graph A graph containing number of message reactions
|
||||||
@ -10090,6 +10100,9 @@ reportMessageReactions chat_id:int53 message_id:int53 sender_id:MessageSender =
|
|||||||
//@description Returns detailed statistics about a chat. Currently, this method can be used only for supergroups and channels. Can be used only if supergroupFullInfo.can_get_statistics == true @chat_id Chat identifier @is_dark Pass true if a dark theme is used by the application
|
//@description Returns detailed statistics about a chat. Currently, this method can be used only for supergroups and channels. Can be used only if supergroupFullInfo.can_get_statistics == true @chat_id Chat identifier @is_dark Pass true if a dark theme is used by the application
|
||||||
getChatStatistics chat_id:int53 is_dark:Bool = ChatStatistics;
|
getChatStatistics chat_id:int53 is_dark:Bool = ChatStatistics;
|
||||||
|
|
||||||
|
//@description Returns detailed revemue statistics about a chat. Currently, this method can be used only for channels. Can be used only if supergroupFullInfo.can_get_revenue_statistics == true @chat_id Chat identifier @is_dark Pass true if a dark theme is used by the application
|
||||||
|
getChatRevenueStatistics chat_id:int53 is_dark:Bool = ChatRevenueStatistics;
|
||||||
|
|
||||||
//@description Returns detailed statistics about a message. Can be used only if message.can_get_statistics == true @chat_id Chat identifier @message_id Message identifier @is_dark Pass true if a dark theme is used by the application
|
//@description Returns detailed statistics about a message. Can be used only if message.can_get_statistics == true @chat_id Chat identifier @message_id Message identifier @is_dark Pass true if a dark theme is used by the application
|
||||||
getMessageStatistics chat_id:int53 message_id:int53 is_dark:Bool = MessageStatistics;
|
getMessageStatistics chat_id:int53 message_id:int53 is_dark:Bool = MessageStatistics;
|
||||||
|
|
||||||
|
@ -12,6 +12,7 @@
|
|||||||
#include "td/telegram/Global.h"
|
#include "td/telegram/Global.h"
|
||||||
#include "td/telegram/MessageId.h"
|
#include "td/telegram/MessageId.h"
|
||||||
#include "td/telegram/MessagesManager.h"
|
#include "td/telegram/MessagesManager.h"
|
||||||
|
#include "td/telegram/misc.h"
|
||||||
#include "td/telegram/ServerMessageId.h"
|
#include "td/telegram/ServerMessageId.h"
|
||||||
#include "td/telegram/StoryId.h"
|
#include "td/telegram/StoryId.h"
|
||||||
#include "td/telegram/StoryManager.h"
|
#include "td/telegram/StoryManager.h"
|
||||||
@ -265,6 +266,62 @@ class GetBroadcastStatsQuery final : public Td::ResultHandler {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
static td_api::object_ptr<td_api::chatRevenueStatistics> convert_broadcast_revenue_stats(
|
||||||
|
telegram_api::object_ptr<telegram_api::stats_broadcastRevenueStats> obj) {
|
||||||
|
CHECK(obj != nullptr);
|
||||||
|
auto get_amount = [](int64 amount) {
|
||||||
|
if (amount < 0 || !check_currency_amount(amount)) {
|
||||||
|
LOG(ERROR) << "Receive currency amount = " << amount;
|
||||||
|
return static_cast<int64>(0);
|
||||||
|
}
|
||||||
|
return amount;
|
||||||
|
};
|
||||||
|
return td_api::make_object<td_api::chatRevenueStatistics>(
|
||||||
|
convert_stats_graph(std::move(obj->top_hours_graph_)), convert_stats_graph(std::move(obj->revenue_graph_)), "TON",
|
||||||
|
get_amount(obj->overall_revenue_), get_amount(obj->current_balance_), get_amount(obj->available_balance_),
|
||||||
|
obj->usd_rate_ > 0 ? clamp(obj->usd_rate_ * 1e-7, 1e-18, 1e18) : 1.0);
|
||||||
|
}
|
||||||
|
|
||||||
|
class GetBroadcastRevenueStatsQuery final : public Td::ResultHandler {
|
||||||
|
Promise<td_api::object_ptr<td_api::chatRevenueStatistics>> promise_;
|
||||||
|
ChannelId channel_id_;
|
||||||
|
|
||||||
|
public:
|
||||||
|
explicit GetBroadcastRevenueStatsQuery(Promise<td_api::object_ptr<td_api::chatRevenueStatistics>> &&promise)
|
||||||
|
: promise_(std::move(promise)) {
|
||||||
|
}
|
||||||
|
|
||||||
|
void send(ChannelId channel_id, bool is_dark) {
|
||||||
|
channel_id_ = channel_id;
|
||||||
|
|
||||||
|
auto input_channel = td_->chat_manager_->get_input_channel(channel_id);
|
||||||
|
if (input_channel == nullptr) {
|
||||||
|
return on_error(Status::Error(500, "Chat info not found"));
|
||||||
|
}
|
||||||
|
|
||||||
|
int32 flags = 0;
|
||||||
|
if (is_dark) {
|
||||||
|
flags |= telegram_api::stats_getBroadcastRevenueStats::DARK_MASK;
|
||||||
|
}
|
||||||
|
send_query(G()->net_query_creator().create(
|
||||||
|
telegram_api::stats_getBroadcastRevenueStats(flags, false /*ignored*/, std::move(input_channel))));
|
||||||
|
}
|
||||||
|
|
||||||
|
void on_result(BufferSlice packet) final {
|
||||||
|
auto result_ptr = fetch_result<telegram_api::stats_getBroadcastRevenueStats>(packet);
|
||||||
|
if (result_ptr.is_error()) {
|
||||||
|
return on_error(result_ptr.move_as_error());
|
||||||
|
}
|
||||||
|
|
||||||
|
promise_.set_value(convert_broadcast_revenue_stats(result_ptr.move_as_ok()));
|
||||||
|
}
|
||||||
|
|
||||||
|
void on_error(Status status) final {
|
||||||
|
td_->chat_manager_->on_get_channel_error(channel_id_, status, "GetBroadcastStatsQuery");
|
||||||
|
promise_.set_error(std::move(status));
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
static td_api::object_ptr<td_api::messageStatistics> convert_message_stats(
|
static td_api::object_ptr<td_api::messageStatistics> convert_message_stats(
|
||||||
telegram_api::object_ptr<telegram_api::stats_messageStats> obj) {
|
telegram_api::object_ptr<telegram_api::stats_messageStats> obj) {
|
||||||
return td_api::make_object<td_api::messageStatistics>(
|
return td_api::make_object<td_api::messageStatistics>(
|
||||||
@ -498,6 +555,17 @@ void StatisticsManager::send_get_channel_stats_query(DcId dc_id, ChannelId chann
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void StatisticsManager::get_channel_revenue_statistics(
|
||||||
|
DialogId dialog_id, bool is_dark, Promise<td_api::object_ptr<td_api::chatRevenueStatistics>> &&promise) {
|
||||||
|
if (!td_->dialog_manager_->have_dialog_force(dialog_id, "get_channel_revenue_statistics")) {
|
||||||
|
return promise.set_error(Status::Error(400, "Chat not found"));
|
||||||
|
}
|
||||||
|
if (!td_->dialog_manager_->is_broadcast_channel(dialog_id)) {
|
||||||
|
return promise.set_error(Status::Error(400, "Chat is not a channel"));
|
||||||
|
}
|
||||||
|
td_->create_handler<GetBroadcastRevenueStatsQuery>(std::move(promise))->send(dialog_id.get_channel_id(), is_dark);
|
||||||
|
}
|
||||||
|
|
||||||
void StatisticsManager::get_channel_message_statistics(
|
void StatisticsManager::get_channel_message_statistics(
|
||||||
MessageFullId message_full_id, bool is_dark, Promise<td_api::object_ptr<td_api::messageStatistics>> &&promise) {
|
MessageFullId message_full_id, bool is_dark, Promise<td_api::object_ptr<td_api::messageStatistics>> &&promise) {
|
||||||
auto dc_id_promise = PromiseCreator::lambda([actor_id = actor_id(this), message_full_id, is_dark,
|
auto dc_id_promise = PromiseCreator::lambda([actor_id = actor_id(this), message_full_id, is_dark,
|
||||||
|
@ -30,6 +30,9 @@ class StatisticsManager final : public Actor {
|
|||||||
void get_channel_statistics(DialogId dialog_id, bool is_dark,
|
void get_channel_statistics(DialogId dialog_id, bool is_dark,
|
||||||
Promise<td_api::object_ptr<td_api::ChatStatistics>> &&promise);
|
Promise<td_api::object_ptr<td_api::ChatStatistics>> &&promise);
|
||||||
|
|
||||||
|
void get_channel_revenue_statistics(DialogId dialog_id, bool is_dark,
|
||||||
|
Promise<td_api::object_ptr<td_api::chatRevenueStatistics>> &&promise);
|
||||||
|
|
||||||
void get_channel_message_statistics(MessageFullId message_full_id, bool is_dark,
|
void get_channel_message_statistics(MessageFullId message_full_id, bool is_dark,
|
||||||
Promise<td_api::object_ptr<td_api::messageStatistics>> &&promise);
|
Promise<td_api::object_ptr<td_api::messageStatistics>> &&promise);
|
||||||
|
|
||||||
|
@ -8542,6 +8542,12 @@ void Td::on_request(uint64 id, const td_api::getChatStatistics &request) {
|
|||||||
statistics_manager_->get_channel_statistics(DialogId(request.chat_id_), request.is_dark_, std::move(promise));
|
statistics_manager_->get_channel_statistics(DialogId(request.chat_id_), request.is_dark_, std::move(promise));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void Td::on_request(uint64 id, const td_api::getChatRevenueStatistics &request) {
|
||||||
|
CHECK_IS_USER();
|
||||||
|
CREATE_REQUEST_PROMISE();
|
||||||
|
statistics_manager_->get_channel_revenue_statistics(DialogId(request.chat_id_), request.is_dark_, std::move(promise));
|
||||||
|
}
|
||||||
|
|
||||||
void Td::on_request(uint64 id, const td_api::getMessageStatistics &request) {
|
void Td::on_request(uint64 id, const td_api::getMessageStatistics &request) {
|
||||||
CHECK_IS_USER();
|
CHECK_IS_USER();
|
||||||
CREATE_REQUEST_PROMISE();
|
CREATE_REQUEST_PROMISE();
|
||||||
|
@ -1613,6 +1613,8 @@ class Td final : public Actor {
|
|||||||
|
|
||||||
void on_request(uint64 id, const td_api::getChatStatistics &request);
|
void on_request(uint64 id, const td_api::getChatStatistics &request);
|
||||||
|
|
||||||
|
void on_request(uint64 id, const td_api::getChatRevenueStatistics &request);
|
||||||
|
|
||||||
void on_request(uint64 id, const td_api::getMessageStatistics &request);
|
void on_request(uint64 id, const td_api::getMessageStatistics &request);
|
||||||
|
|
||||||
void on_request(uint64 id, const td_api::getStoryStatistics &request);
|
void on_request(uint64 id, const td_api::getStoryStatistics &request);
|
||||||
|
@ -6464,6 +6464,11 @@ class CliClient final : public Actor {
|
|||||||
bool is_dark;
|
bool is_dark;
|
||||||
get_args(args, chat_id, is_dark);
|
get_args(args, chat_id, is_dark);
|
||||||
send_request(td_api::make_object<td_api::getChatStatistics>(chat_id, is_dark));
|
send_request(td_api::make_object<td_api::getChatStatistics>(chat_id, is_dark));
|
||||||
|
} else if (op == "gcrst") {
|
||||||
|
ChatId chat_id;
|
||||||
|
bool is_dark;
|
||||||
|
get_args(args, chat_id, is_dark);
|
||||||
|
send_request(td_api::make_object<td_api::getChatRevenueStatistics>(chat_id, is_dark));
|
||||||
} else {
|
} else {
|
||||||
op_not_found_count++;
|
op_not_found_count++;
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user