qTbot 0.2.106.03782ba
qTbot is base back end library for your c++ Qt projects.
telegramsendfile.cpp
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#include "telegramsendfile.h"
8
9#include <QJsonDocument>
10
11namespace qTbot {
12
13
15 const QString &fileName,
16 const QString &fileType,
17 const QByteArray& data,
18 const TelegramArgs &args,
19 const ExtraJsonObjects& extraObjects
20 ):
21 TelegramSingleRquest(request, args.toMap(true)) {
22 setPriority(args.requestPriority);
23
24
25 for (auto it = extraObjects.begin(); it != extraObjects.end(); it = std::next(it)) {
26 addArg(it.key(), QJsonDocument(*it.value()).toJson(QJsonDocument::Compact));
27 }
28
29 addArg(QString("%0:%1:%2").arg(REQUEST_UPLOAD_FILE_KEY, fileName, fileType), data);
30}
31
33 const QFileInfo &file,
34 const TelegramArgs &args,
35 const QHash<QString, QSharedPointer<QJsonObject> > &extraObjects):
36 TelegramSingleRquest(request, args.toMap(true)) {
37 setPriority(args.requestPriority);
38
39 QFile readFile(file.absoluteFilePath());
40 if (!readFile.open(QIODevice::ReadOnly)) {
41 qWarning() << "Fail to open file" << file.absoluteFilePath();
42 }
43
44 for (auto it = extraObjects.begin(); it != extraObjects.end(); it = std::next(it)) {
45 addArg(it.key(), QJsonDocument(*it.value()).toJson(QJsonDocument::Compact));
46 }
47
48 auto&& sufix = file.suffix();
49 if (sufix.contains("png") || sufix.contains("jpg") || sufix.contains("jepg") || sufix.contains("gif")) {
50 addArg(QString("%0:%1:%2").arg(REQUEST_UPLOAD_FILE_KEY, file.fileName(), TELEGRAM_PHOTO), readFile.readAll());
51
52 } else {
53 addArg(QString("%0:%1:%2").arg(REQUEST_UPLOAD_FILE_KEY, file.fileName(), TELEGRAM_DOCUMENT), readFile.readAll());
54
55 }
56
57 readFile.close();
58}
59
63
64QString TelegramSendFile::type() const {
66}
67}
RequestMethod method() const override
method returns method of the request.
TelegramSendFile(const QString &request, const QString &fileName, const QString &fileType, const QByteArray &data, const TelegramArgs &args, const QHash< QString, QSharedPointer< QJsonObject > > &extraObjects={})
virtual QString type() const
type return type file. By Default it is REQUEST_UPLOAD_FILE_KEY
The TelegramSingleRquest class Is base class for all single requests commands with arguments.
RequestMethod
RequestMethod Tgis islist of supported requests types of the requests.
Definition irequest.h:40
@ Upload
this is post request to upload a big data to telegram
Definition irequest.h:46
const QMap< QString, QVariant > & args() const
args This method returns a current list of arguments
Definition irequest.cpp:30
void addArg(const QString &key, const QVariant &val)
addArg This method push new arg, to arguments list
Definition irequest.cpp:34
void setPriority(RequestPriority newPriority)
Definition irequest.cpp:98
#define REQUEST_UPLOAD_FILE_KEY
Definition irequest.h:19
QHash< QString, QSharedPointer< QJsonObject > > ExtraJsonObjects
ExtraJsonObjects hash map of the extra objects of the message.
Definition irequest.h:26
The TelegramArgs class is base structure for the all tellegram message arguments.
#define TELEGRAM_DOCUMENT
#define TELEGRAM_PHOTO