10#include "qjsonarray.h"
24 return rawJson()[
"message_id"].toInteger();
28 return rawJson()[
"from"][
"id"].toInteger();
32 return rawJson()[
"from"][
"is_bot"].toBool();
36 return rawJson()[
"from"][
"first_name"].toString();
40 return rawJson()[
"from"][
"last_name"].toString();
44 return rawJson()[
"from"][
"username"].toString();
48 return rawJson()[
"from"][
"language_code"].toString();
52 return rawJson()[
"chat"][
"id"].toVariant();
56 return rawJson().contains(
"message_id");
64 return rawJson()[
"chat"][
"first_name"].toString();
68 return rawJson()[
"chat"][
"last_name"].toString();
72 return rawJson()[
"chat"][
"username"].toString();
76 return rawJson()[
"chat"][
"type"].toString();
80 return rawJson()[
"date"].toInteger();
84 return rawJson()[
"text"].toString();
88 return rawJson()[
"text"].toString() +
rawJson()[
"caption"].toString();
92 return rawJson()[
"caption"].toString();
96 return rawJson().contains(type);
100 const QJsonArray&& array =
rawJson()[
"photo"].toArray();
101 QList<QSharedPointer<TelegramImage>> result;
103 for (
const auto& photo: array) {
104 result.push_back(QSharedPointer<TelegramImage>::create(photo.toObject()));
111 const QJsonArray&& array =
rawJson()[
"photo"].toArray();
112 auto&& result = QSharedPointer<TelegramImage>::create();
117 int oldBestMath = std::numeric_limits<
decltype(oldBestMath)>::max();
118 auto it = array.cbegin();
120 result->setRawJson(it->toObject());
123 while (it != array.end() && std::abs(result->fileSize() - size) < oldBestMath) {
124 oldBestMath = std::abs(result->fileSize() - size);
125 result->setRawJson(it->toObject());
132 for (
const auto& photo: array) {
134 if (photoObj.fileSize() < size) {
145 result->setRawJson(std::prev(array.end())->toObject());
153 result->setRawJson(array.begin()->toObject());
168 return QSharedPointer<TelegramDocument>::create(
rawJson()[
Document].toObject());
172 return QSharedPointer<TelegramAudio>::create(
rawJson()[
Audio].toObject());
176 return QSharedPointer<TelegramContact>::create(
rawJson()[
Contact].toObject());
180 return QSharedPointer<TelegramLocation>::create(
rawJson()[
Location].toObject());
const QJsonObject & rawJson() const
rawJson Telegram use rest api with json objects. So all received messages will be parsed in to jsobje...
virtual void setRawJson(const QJsonObject &newRawJson)
setRawJson this method convert jsobject into telegram message.
The TelegramImage class This is implementation of the photos of telegram.
bool isBot() const
isBot checks if the sender is a bot.
QString from() const override
from This virtual function should return name of the user that sent this message to bot.
QString languageCode() const
languageCode returns the sender's language code.
QString fullText() const
fullText return text + caption value
unsigned long long fromId() const
fromId returns the sender's ID.
const Type Document
Document This is type of the files.
const Type Contact
Contact This is type of the files.
QSharedPointer< TelegramLocation > location() const
location returns location object of message.
const Type Location
Location This is type of location data.
QString username() const
username returns the sender's username.
const Type Audio
Audio This is type of Audio files.
QString Type
Type just string value of the telegram messages types.
unsigned long long messageId() const override
messageId returns the message ID.
QString firstName() const
firstName returns the sender's first name.
QString caption() const
caption return only caption value
qint64 date() const
date returns date of the snet message.
unsigned long long updateId() const override
updateId This method returns numeric id of the update.
bool isValid() const override
isValid return true if the message is valid else false.
QSharedPointer< TelegramImage > image(QualitySelector behavior=AroundSize, int size=100000) const
Retrieve an image from the Telegram service with specified quality and size parameters.
QString chatFirstName() const
chatFirstName returns the first participant's first name in the chat.
QSharedPointer< TelegramContact > contact() const
contact return contact
QString chatUsername() const
chatUsername returns the first participant's username in the chat.
QSharedPointer< TelegramDocument > documents() const
documents This method returns contained document data.
QualitySelector
The QualitySelector enum This is behavior of image and video selection.
@ Fast
This selection returns faster iamge of available. (minimum size)
@ Best
This selection returns best iamge of available.
QString text() const
text returns text that contains this message object.
QList< QSharedPointer< TelegramImage > > images() const
images This function returns array of available images qualites
QString chatLastName() const
chatLastName returns the first participant's last name in the chat.
QSharedPointer< TelegramAudio > audio() const
audio This method returns contained audio data.
QVariant chatId() const override
chatId returns the chat ID.
QString lastName() const
lastName returns the sender's last name.
QString chatType() const
chatType returns the chat type.
bool contains(const Type &type)
contains This method returns true if the message contains choosed data type.