qTbot 0.87.9547b0c
qTbot is base back end library for your c++ Qt projects.
main.cpp
Go to the documentation of this file.
1//#
2//# Copyright (C) 2021-2024 QuasarApp.
3//# Distributed under the GPLv3 software license, see the accompanying
4//# Everyone is permitted to copy and distribute verbatim copies
5//# of this license document, but changing it is not allowed.
6//#
7
8#include "qvariant.h"
10
11#include <QCoreApplication>
14
15// link to test bot
16// @quasarapp_test_bot (https://t.me/quasarapp_test_bot)
17int main(int argc, char *argv[]) {
18
19 QCoreApplication::setOrganizationName("QuasarApp");
20 QCoreApplication::setOrganizationDomain("https://github.com/QuasarApp");
21 QCoreApplication::setApplicationName("qTbotExample");
22
23 QCoreApplication app(argc, argv);
24
26
27 srand(time(0));
28
29 QList<QSharedPointer<qTbot::iFile> > filesStack;
30 QObject::connect(&bot, &qTbot::TelegramRestBot::sigReceiveUpdate, [&bot, &filesStack](auto){
31 while(auto&& update = bot.takeNextUnreadUpdate()) {
32
33 if (auto&& tupdate = update.dynamicCast<qTbot::TelegramUpdate>()) {
34
35 if (tupdate->contains(tupdate->MessageUpdate)) {
36
37 if (auto&& tmsg = tupdate->message()) {
38 if (tmsg->contains(tmsg->Document)) {
39 filesStack.push_back(bot.getFile(tmsg->documents()->fileId(), qTbot::iFile::Local));
40 }
41
42 if (tmsg->contains(tmsg->Image)) {
43 filesStack.push_back(bot.getFile(tmsg->image()->fileId(), qTbot::iFile::Local));
44 }
45
46 if (tmsg->contains(tmsg->Audio)) {
47 filesStack.push_back(bot.getFile(tmsg->audio()->fileId(), qTbot::iFile::Local));
48 }
49
50 bot.sendSpecificMessageWithKeyboard(qTbot::TelegramArgs{tmsg->chatId(), "I see it", tmsg->messageId()},
51 {{{"test_button", [tmsg, &bot](const QString& queryId, const QVariant& msgId){
52 static int index = 0;
53
54 auto&& args = qTbot::TelegramArgs{tmsg->chatId(),
55 "I see it. Presed count: " + QString::number(index++),
56 tmsg->messageId(),
57 "",
58 false,
59 queryId};
60
61 auto&& keyboard = qTbot::KeyboardOnMessage{
62 {{"test_button", [](auto , auto ){}},
63 {"test_button 2", [](auto , auto ){}}}};
64
65 bot.editSpecificMessageWithKeyboard(msgId,
66 args,
67 keyboard
68 );
69 }}}});
70
71 bot.sendSpecificMessageWithKeyboard(qTbot::TelegramArgs{tmsg->chatId(), "I see it", tmsg->messageId()},
72 {{{"test_button"},
73 {"test_button"},}}, true, true);
74 }
75
76 }
77 }
78 }
79 });
80
81 bot.login("6349356184:AAFotw9EC46sgAQrkGQ_jeHPyv3EAapZXcM");
82 return app.exec();
83}
void sigReceiveUpdate(const QSharedPointer< iUpdate > &)
sigReceiveUpdate emit when but receive any updates from users.
QSharedPointer< iUpdate > takeNextUnreadUpdate()
takeNextUnreadUpdate This method take a unread update and mark them as read.
Definition ibot.cpp:166
The TelegramRestBot class Is Rest implementation base on the Update API telegram method.
int main(int argc, char *argv[])
Definition main.cpp:17