MCPcopy Create free account
hub / github.com/TDesktop-x64/tdesktop / SendBotCallbackData

Function SendBotCallbackData

Telegram/SourceFiles/api/api_bot.cpp:52–172  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

50namespace {
51
52void SendBotCallbackData(
53 not_null<Window::SessionController*> controller,
54 not_null<HistoryItem*> item,
55 int row,
56 int column,
57 std::optional<Core::CloudPasswordResult> password,
58 Fn<void()> done = nullptr,
59 Fn<void(const QString &)> handleError = nullptr) {
60 if (!item->isRegular()) {
61 return;
62 }
63 const auto history = item->history();
64 const auto session = &history->session();
65 const auto owner = &history->owner();
66 const auto api = &session->api();
67 const auto bot = item->getMessageBot();
68 const auto fullId = item->fullId();
69 const auto getButton = [=] {
70 return HistoryMessageMarkupButton::Get(owner, fullId, row, column);
71 };
72 const auto button = getButton();
73 if (!button || button->requestId) {
74 return;
75 }
76
77 using ButtonType = HistoryMessageMarkupButton::Type;
78 const auto isGame = (button->type == ButtonType::Game);
79
80 auto flags = MTPmessages_GetBotCallbackAnswer::Flags(0);
81 QByteArray sendData;
82 if (isGame) {
83 flags |= MTPmessages_GetBotCallbackAnswer::Flag::f_game;
84 } else if (button->type == ButtonType::Callback
85 || button->type == ButtonType::CallbackWithPassword) {
86 flags |= MTPmessages_GetBotCallbackAnswer::Flag::f_data;
87 sendData = button->data;
88 }
89 const auto withPassword = password.has_value();
90 if (withPassword) {
91 flags |= MTPmessages_GetBotCallbackAnswer::Flag::f_password;
92 }
93 const auto weak = base::make_weak(controller);
94 const auto show = controller->uiShow();
95 button->requestId = api->request(MTPmessages_GetBotCallbackAnswer(
96 MTP_flags(flags),
97 history->peer->input(),
98 MTP_int(item->id),
99 MTP_bytes(sendData),
100 password ? password->result : MTP_inputCheckPasswordEmpty()
101 )).done([=](const MTPmessages_BotCallbackAnswer &result) {
102 const auto guard = gsl::finally([&] {
103 if (done) {
104 done();
105 }
106 });
107 const auto item = owner->message(fullId);
108 if (!item) {
109 return;

Callers 2

ActivateBotCommandFunction · 0.85

Calls 15

MTP_flagsFunction · 0.85
MTP_bytesFunction · 0.85
qsFunction · 0.85
MakeInformBoxFunction · 0.85
isRegularMethod · 0.80
apiMethod · 0.80
getMessageBotMethod · 0.80
has_valueMethod · 0.80
requestItemRepaintMethod · 0.80
messageUpdatedMethod · 0.80
GetFunction · 0.50

Tested by

no test coverage detected