@@ -4359,6 +4359,34 @@ class Client::TdOnStopPollCallback final : public TdQueryCallback {
4359
4359
PromisedQueryPtr query_;
4360
4360
};
4361
4361
4362
+ class Client::TdOnStopBusinessPollCallback final : public TdQueryCallback {
4363
+ public:
4364
+ TdOnStopBusinessPollCallback(Client *client, const td::string &business_connection_id, PromisedQueryPtr query)
4365
+ : client_(client), business_connection_id_(business_connection_id), query_(std::move(query)) {
4366
+ }
4367
+
4368
+ void on_result(object_ptr<td_api::Object> result) final {
4369
+ if (result->get_id() == td_api::error::ID) {
4370
+ return fail_query_with_error(std::move(query_), move_object_as<td_api::error>(result));
4371
+ }
4372
+
4373
+ CHECK(result->get_id() == td_api::businessMessage::ID);
4374
+ auto message = client_->create_business_message(std::move(business_connection_id_),
4375
+ move_object_as<td_api::businessMessage>(result));
4376
+ if (message->content->get_id() != td_api::messagePoll::ID) {
4377
+ LOG(ERROR) << "Poll not found in a business message from connection " << business_connection_id_;
4378
+ return fail_query_with_error(std::move(query_), 400, "message poll not found");
4379
+ }
4380
+ auto message_poll = static_cast<const td_api::messagePoll *>(message->content.get());
4381
+ answer_query(JsonPoll(message_poll->poll_.get(), client_), std::move(query_));
4382
+ }
4383
+
4384
+ private:
4385
+ Client *client_;
4386
+ td::string business_connection_id_;
4387
+ PromisedQueryPtr query_;
4388
+ };
4389
+
4362
4390
class Client::TdOnOkQueryCallback final : public TdQueryCallback {
4363
4391
public:
4364
4392
explicit TdOnOkQueryCallback(PromisedQueryPtr query) : query_(std::move(query)) {
@@ -10021,15 +10049,33 @@ td::Status Client::process_send_poll_query(PromisedQueryPtr &query) {
10021
10049
}
10022
10050
10023
10051
td::Status Client::process_stop_poll_query(PromisedQueryPtr &query) {
10052
+ auto business_connection_id = query->arg("business_connection_id");
10024
10053
auto chat_id = query->arg("chat_id");
10025
10054
auto message_id = get_message_id(query.get());
10026
10055
TRY_RESULT(reply_markup, get_reply_markup(query.get(), bot_user_ids_));
10027
10056
10028
10057
resolve_reply_markup_bot_usernames(
10029
10058
std::move(reply_markup), std::move(query),
10030
- [this, chat_id = chat_id.str(), message_id](object_ptr<td_api::ReplyMarkup> reply_markup,
10031
- PromisedQueryPtr query) {
10032
- check_message(chat_id, message_id, false, AccessRights::Edit, "message with poll to stop", std::move(query),
10059
+ [this, business_connection_id = business_connection_id.str(), chat_id_str = chat_id.str(), message_id](
10060
+ object_ptr<td_api::ReplyMarkup> reply_markup, PromisedQueryPtr query) {
10061
+ if (!business_connection_id.empty()) {
10062
+ auto r_chat_id = get_business_connection_chat_id(chat_id_str);
10063
+ if (r_chat_id.is_error()) {
10064
+ return fail_query_with_error(std::move(query), 400, r_chat_id.error().message());
10065
+ }
10066
+ auto chat_id = r_chat_id.move_as_ok();
10067
+ return check_business_connection(
10068
+ business_connection_id, std::move(query),
10069
+ [this, business_connection_id, chat_id, message_id, reply_markup = std::move(reply_markup)](
10070
+ const BusinessConnection *business_connection, PromisedQueryPtr query) mutable {
10071
+ send_request(
10072
+ make_object<td_api::stopBusinessPoll>(business_connection_id, chat_id, message_id,
10073
+ std::move(reply_markup)),
10074
+ td::make_unique<TdOnStopBusinessPollCallback>(this, business_connection_id, std::move(query)));
10075
+ });
10076
+ }
10077
+
10078
+ check_message(chat_id_str, message_id, false, AccessRights::Edit, "message with poll to stop", std::move(query),
10033
10079
[this, reply_markup = std::move(reply_markup)](int64 chat_id, int64 message_id,
10034
10080
PromisedQueryPtr query) mutable {
10035
10081
send_request(
0 commit comments