qTbot 0.2.102.bb22a69
qTbot is base back end library for your c++ Qt projects.
itelegrambot.h
Go to the documentation of this file.
1//#
2//# Copyright (C) 2023-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
9
10#ifndef ITELEGRAMBOT_H
11#define ITELEGRAMBOT_H
12
13#include "ibot.h"
14#include "qTbot/telegramargs.h"
15#include <QObject>
16
17class QNetworkAccessManager;
18class QNetworkReply;
19
20namespace qTbot {
21
22class ITelegramMessage;
23class TelegramFile;
24class TelegramUpdateAnswer;
25class TelegramSendFile;
26class TelegramSingleRquest;
27
28typedef std::function<void(const QString& buttonKey, const QVariant& msgID)> ButtonCB;
29typedef QList<QHash<QString, ButtonCB >> KeyboardOnMessage;
30
35{
36 Q_OBJECT
37public:
40
41 bool login(const QByteArray &token) override;
42
43 bool sendMessage(const QVariant &chatId,
44 const QString& text,
45 iRequest::RequestPriority priority = iRequest::NormalPriority) override;
46
54 bool sendLocationRequest(const QVariant &chatId, const QString& text, const QString &buttonText, bool onetimeKeyboard);
55
63 bool sendSelfContactRequest(const QVariant &chatId, const QString& text, const QString &buttonText, bool onetimeKeyboard);
64
77 bool sendSpecificMessage(const TelegramArgs& args,
78 const qTbot::ExtraJsonObjects &extraObjects = {});
79
91 bool sendSpecificMessageWithKeyboard(const TelegramArgs& args,
92 const KeyboardOnMessage &keyboard);
93
109 bool sendSpecificMessageWithKeyboard(const TelegramArgs& args,
110 const QList<QList<QString> > &keyboard,
111 bool onTimeKeyboard = false,
112 bool autoResizeKeyboard = true);
113
114 bool deleteMessage(const QVariant& chatId, const QVariant& messageId) override;
115
131 bool editSpecificMessageWithKeyboard(const QVariant &messageId,
132 const TelegramArgs& args,
133 const QList<QList<QString> > &keyboard = {},
134 bool onTimeKeyboard = false,
135 bool autoResizeKeyboard = false);
136
137
152 bool editSpecificMessageWithKeyboard(const QVariant& messageId,
153 const TelegramArgs& args,
154 const KeyboardOnMessage &keyboard = {});
155
172 bool editMessageKeyboard(const QVariant& messageId,
173 const QVariant &chatId,
174 const KeyboardOnMessage &keyboard = {},
175 const QString &callBackQueryId = "");
176
189 bool editSpecificMessage(const QVariant &messageId,
190 const TelegramArgs& args);
191
198 QFuture<QByteArray> getFile(const QString& fileId, FileType fileType = FileType::Ram) override;
199
205 QFuture<QByteArray> getFileMeta(const QString& fileId);
206
207 bool sendFile( const QFileInfo& file, const QVariant& chatId) override;
208
209 bool sendFile( const QByteArray& file, const QString& fileName, const QVariant& chatId) override;
210
217 bool sendFileMessage( const TelegramArgs& args, const QFileInfo& file);
218
226 bool sendFileMessage( const TelegramArgs& args, const QByteArray& file, const QString& fileName);
227
236 bool sendPhoto(const TelegramArgs& args,
237 const QFileInfo& photo,
238 const KeyboardOnMessage &keyboard = {});
239
249 bool sendPhoto(const TelegramArgs &args,
250 const QByteArray& photo,
251 const QString& fileName,
252 const KeyboardOnMessage &keyboard = {});
253
260 bool sendFileById(const QString& fileID, const QVariant& chatId);
261
271 bool sendLocation(const TelegramArgs &args,
272 float latitude,
273 float longitude,
274 const KeyboardOnMessage &keyboard = {});
275
284 bool sendContact(const TelegramArgs &args,
285 const QString& phone,
286 const QString& firstName,
287 const QString& secondName = "");
288
289 // to do
290
291 // * forwardMessage implementations
292 // * copyMessage implementations
293 // * sendAudio implementations
294 // * sendVideo implementations
295 // * sendVoice implementations
296 // * sendContact implementations
297 // * sendPoll implementations
298 // * sendDice implementations
299 // * sendChatAction implementations
300 // * getUserProfilePhotos implementations
301 // * banChatMember implementations
302 // * unbanChatMember implementations
303 // * restrictChatMember implementations
304 // * setChatAdministratorCustomTitle implementations
305 // * banChatSenderChat implementations
306 // * unbanChatSenderChat implementations
307 // * exportChatInviteLink implementations
308 // * approveChatJoinRequest implementations
309 // * declineChatJoinRequest implementations
310 // * setChatTitle implementations
311 // * pinChatMessage implementations
312 // * unpinChatMessage implementations
313 // * unpinAllChatMessages implementations
314 // * leaveChat implementations
315 // * getChat implementations
316 // * getChatAdministrators implementations
317 // * getChatMemberCount implementations
318 // * getChatMember implementations
319 // * answerCallbackQuery implementations
320 // * getMyCommands implementations
321 // * deleteMyCommands implementations
322 // * getMyCommands implementations
323 // * editMessageText implementations
324 // * editMessageReplyMarkup implementations
325 // * stopPoll implementations
326 // * deleteMessage implementations
327 // * sendSticker implementations
328
329
334 unsigned long long id() const;
335
340 const QString& username() const;
341
347 int gelLastMessageId(unsigned long long &chatId) const;
348
349protected:
350
355 void setId(unsigned long long newId);
356
361 void setUsername(const QString &newUsername);
362
363 QString makeUrl(const QSharedPointer<iRequest>& request) const override;
364
370 int getFileSizeByUniqueId(const QString& id) const;
371
377 QSharedPointer<TelegramFile> getFileInfoByUniqueId(const QString& id) const;
378
383 virtual void onRequestError(const QSharedPointer<TelegramUpdateAnswer>& ansverWithError) const;
384
385 void handleIncomeNewUpdate(const QSharedPointer<iUpdate> &) override;
386
393 virtual bool sendMessageRequest(const QSharedPointer<iRequest> &rquest,
394 const std::function<void(int msgId)>& msgIdCB = {});
395
396private slots:
397 void handleLogin(const QByteArray &ansver);
398 void handleLoginErr(QNetworkReply::NetworkError err);
399 void handleFileHeader(const QByteArray &header);
400
401private:
402
403 QString findFileInlocatStorage(const QString& fileId) const;
404 QHash<QString, QSharedPointer<QJsonObject> >
405 prepareInlineKeyBoard(const KeyboardOnMessage &keyboard);
406 ExtraJsonObjects prepareKeyboard(bool autoResizeKeyboard,
407 bool onTimeKeyboard,
408 const QList<QList<QString> > &keyboard);
409
410 unsigned long long _id = 0;
411 QString _username;
412 QMap<QString, std::function<void(const QString&, const QVariant&)>> _handleButtons;
413
414 QHash<unsigned long long, int> _lastMessageId;
415
416 QHash<QString, QSharedPointer<TelegramFile>> _filesMetaInfo;
417
418
419};
420}
421#endif // ITELEGRAMBOT_H
The IBot class Base interface for all chat-bots objcts.
Definition ibot.h:35
FileType
The FileType enum is is file types, deffine how we should download a file - as a local object in file...
Definition ibot.h:44
The ITelegramBot class This is base implementation of the all telegramm bots.
RequestPriority
The RequestPriority enum.
Definition irequest.h:52
#define QTBOT_EXPORT
Definition global.h:18
std::function< void(const QString &buttonKey, const QVariant &msgID)> ButtonCB
QHash< QString, QSharedPointer< QJsonObject > > ExtraJsonObjects
ExtraJsonObjects hash map of the extra objects of the message.
Definition irequest.h:26
QList< QHash< QString, ButtonCB > > KeyboardOnMessage
The TelegramArgs class is base structure for the all tellegram message arguments.