| 4495 | } |
| 4496 | |
| 4497 | void ApiWrap::sendBotStart( |
| 4498 | std::shared_ptr<Ui::Show> show, |
| 4499 | not_null<UserData*> bot, |
| 4500 | PeerData *chat, |
| 4501 | const QString &startTokenForChat) { |
| 4502 | Expects(bot->isBot()); |
| 4503 | |
| 4504 | if (chat && chat->isChannel() && !chat->isMegagroup()) { |
| 4505 | ShowAddParticipantsError(show, "USER_BOT", chat, bot); |
| 4506 | return; |
| 4507 | } |
| 4508 | |
| 4509 | auto &info = bot->botInfo; |
| 4510 | const auto token = chat ? startTokenForChat : info->startToken; |
| 4511 | if (token.isEmpty()) { |
| 4512 | auto message = MessageToSend( |
| 4513 | Api::SendAction(_session->data().history(chat |
| 4514 | ? chat |
| 4515 | : bot.get()))); |
| 4516 | message.textWithTags = { u"/start"_q, TextWithTags::Tags() }; |
| 4517 | if (chat) { |
| 4518 | message.textWithTags.text += '@' + bot->username(); |
| 4519 | } |
| 4520 | sendMessage(std::move(message)); |
| 4521 | return; |
| 4522 | } |
| 4523 | const auto randomId = base::RandomValue<uint64>(); |
| 4524 | if (!chat) { |
| 4525 | info->startToken = QString(); |
| 4526 | } |
| 4527 | request(MTPmessages_StartBot( |
| 4528 | bot->inputUser(), |
| 4529 | chat ? chat->input() : MTP_inputPeerEmpty(), |
| 4530 | MTP_long(randomId), |
| 4531 | MTP_string(token) |
| 4532 | )).done([=](const MTPUpdates &result) { |
| 4533 | applyUpdates(result); |
| 4534 | }).fail([=](const MTP::Error &error) { |
| 4535 | if (chat) { |
| 4536 | const auto type = error.type(); |
| 4537 | ShowAddParticipantsError(show, type, chat, bot); |
| 4538 | } |
| 4539 | }).send(); |
| 4540 | } |
| 4541 | |
| 4542 | void ApiWrap::sendInlineResult( |
| 4543 | not_null<UserData*> bot, |
no test coverage detected