qTbot 0.89.ee6949a
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
23
24 for (auto it = extraObjects.begin(); it != extraObjects.end(); it = std::next(it)) {
25 addArg(it.key(), QJsonDocument(*it.value()).toJson(QJsonDocument::Compact));
26 }
27
28 addArg(QString("%0:%1:%2").arg(REQUEST_UPLOAD_FILE_KEY, fileName, fileType), data);
29}
30
32 const QFileInfo &file,
33 const TelegramArgs &args,
34 const QHash<QString, QSharedPointer<QJsonObject> > &extraObjects):
35 TelegramSingleRquest(request, args.toMap(true)) {
36
37 QFile readFile(file.absoluteFilePath());
38 if (!readFile.open(QIODevice::ReadOnly)) {
39 qWarning() << "Fail to open file" << file.absoluteFilePath();
40 }
41
42 for (auto it = extraObjects.begin(); it != extraObjects.end(); it = std::next(it)) {
43 addArg(it.key(), QJsonDocument(*it.value()).toJson(QJsonDocument::Compact));
44 }
45
46 auto&& sufix = file.suffix();
47 if (sufix.contains("png") || sufix.contains("jpg") || sufix.contains("jepg") || sufix.contains("gif")) {
48 addArg(QString("%0:%1:%2").arg(REQUEST_UPLOAD_FILE_KEY, file.fileName(), TELEGRAM_PHOTO), readFile.readAll());
49
50 } else {
51 addArg(QString("%0:%1:%2").arg(REQUEST_UPLOAD_FILE_KEY, file.fileName(), TELEGRAM_DOCUMENT), readFile.readAll());
52
53 }
54
55 readFile.close();
56}
57
61
62QString TelegramSendFile::type() const {
64}
65}
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
void addArg(const QString &key, const QVariant &val)
addArg This method push new arg, to arguments list
Definition irequest.cpp:34
#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