Skip to content

Commit

Permalink
Added manual tests for Inline Query
Browse files Browse the repository at this point in the history
  • Loading branch information
baderouaich committed Dec 30, 2023
1 parent 6615e89 commit 49b1b4b
Showing 1 changed file with 21 additions and 1 deletion.
22 changes: 21 additions & 1 deletion tests/manual_tests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
#include "tgbotxx/objects/WebhookInfo.hpp"
#include <csignal>
#include <cstdlib>
#include <exception>
#include <iostream>
#include <tgbotxx/tgbotxx.hpp>

Expand Down Expand Up @@ -338,9 +339,28 @@ class MyBot : public Bot {
void onEditedMessage(const Ptr<Message>& editedMessage) override {
std::cout << __func__ << ": " << editedMessage->text << std::endl;
}
/// Called when a new incoming inline query is received
/// Called when a new incoming inline query is received (when user writes in the chat text box: @botname QUERY)
void onInlineQuery(const Ptr<InlineQuery>& inlineQuery) override {
std::cout << __func__ << ": " << inlineQuery->query << std::endl;
std::string query = inlineQuery->query;

if(query.starts_with("photo")) {
std::vector<Ptr<InlineQueryResult>> inlineQueryResults;
for (const std::string_view photoURL: {"https://images.alphacoders.com/129/1299740.jpg",
"https://images2.alphacoders.com/112/1128233.jpg",
"https://images2.alphacoders.com/131/1311487.jpg"}) {
auto photoPtr = makePtr<InlineQueryResultPhoto>();
photoPtr->id = StringUtils::random(16);
photoPtr->photoUrl = photoURL;
photoPtr->thumbnailUrl = photoURL;
inlineQueryResults.push_back(std::move(photoPtr));
}
try {
api()->answerInlineQuery(inlineQuery->id, inlineQueryResults, 300, "");
} catch(const std::exception& e) {
std::cerr << e.what() << std::endl;
}
}
}
/// Called when the result of an inline query that was chosen by a user and sent to their chat partner.
void onChosenInlineResult(const Ptr<ChosenInlineResult>& chosenInlineResult) override {
Expand Down

0 comments on commit 49b1b4b

Please sign in to comment.