forked from moritzsternemann/QtTelegramBot
Initial commit
This commit is contained in:
commit
3663fd38ce
41 files changed
+2095
No files matched your search
@@ -0,0 +1,13 @@
|
||||
#include "audio.h"
|
||||
|
||||
using namespace Telegram;
|
||||
|
||||
Audio::Audio(QJsonObject audio)
|
||||
{
|
||||
fileId = audio.value("file_id").toString();
|
||||
duration = audio.value("duration").toInt();
|
||||
performer = audio.value("performer").toString();
|
||||
title = audio.value("title").toString();
|
||||
mimeType = audio.value("mime_type").toString();
|
||||
fileSize = audio.value("file_size").toInt();
|
||||
}
|
||||
@@ -0,0 +1,39 @@
|
||||
#ifndef AUDIO_H
|
||||
#define AUDIO_H
|
||||
|
||||
#include <QDebug>
|
||||
#include <QString>
|
||||
#include <QJsonObject>
|
||||
|
||||
namespace Telegram {
|
||||
|
||||
class Audio
|
||||
{
|
||||
public:
|
||||
Audio() {}
|
||||
Audio(QJsonObject audio);
|
||||
|
||||
QString fileId;
|
||||
quint64 duration;
|
||||
QString performer;
|
||||
QString title;
|
||||
QString mimeType;
|
||||
quint64 fileSize;
|
||||
};
|
||||
|
||||
inline QDebug operator<< (QDebug dbg, const Audio &audio)
|
||||
{
|
||||
dbg.nospace() << qUtf8Printable(QString("Telegram::Audio(fileId=%1; duration=%2; performer=%3; title=%4; mimeType=%5; fileSize=%6)")
|
||||
.arg(audio.fileId)
|
||||
.arg(audio.duration)
|
||||
.arg(audio.performer)
|
||||
.arg(audio.title)
|
||||
.arg(audio.mimeType)
|
||||
.arg(audio.fileSize));
|
||||
|
||||
return dbg.maybeSpace();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
#endif // AUDIO_H
|
||||
@@ -0,0 +1,15 @@
|
||||
#include "chat.h"
|
||||
|
||||
using namespace Telegram;
|
||||
|
||||
Chat::Chat(QJsonObject chat)
|
||||
{
|
||||
id = chat.value("id").toInt();
|
||||
QString chatType = chat.value("type").toString();
|
||||
if (chatType == "private") type = Private;
|
||||
else if (chatType == "group") type = Group;
|
||||
else if (chatType == "channel") type = Channel;
|
||||
username = chat.value("username").toString();
|
||||
firstname = chat.value("first_name").toString();
|
||||
lastname = chat.value("last_name").toString();
|
||||
}
|
||||
@@ -0,0 +1,43 @@
|
||||
#ifndef CHAT_H
|
||||
#define CHAT_H
|
||||
|
||||
#include <QDebug>
|
||||
#include <QString>
|
||||
#include <QJsonObject>
|
||||
|
||||
namespace Telegram {
|
||||
|
||||
class Chat
|
||||
{
|
||||
public:
|
||||
Chat() {}
|
||||
Chat(QJsonObject chat);
|
||||
|
||||
enum ChatType {
|
||||
Private, Group, Channel
|
||||
};
|
||||
|
||||
quint32 id;
|
||||
ChatType type;
|
||||
QString title;
|
||||
QString username;
|
||||
QString firstname;
|
||||
QString lastname;
|
||||
};
|
||||
|
||||
inline QDebug operator<< (QDebug dbg, const Chat &chat)
|
||||
{
|
||||
dbg.nospace() << qUtf8Printable(QString("Telegram::Chat(id=%1; type=%2; title=%3; username=%4; firstname=%5; lastname=%6)")
|
||||
.arg(chat.id)
|
||||
.arg(chat.type)
|
||||
.arg(chat.title)
|
||||
.arg(chat.username)
|
||||
.arg(chat.firstname)
|
||||
.arg(chat.lastname));
|
||||
|
||||
return dbg.maybeSpace();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
#endif // CHAT_H
|
||||
@@ -0,0 +1,11 @@
|
||||
#include "contact.h"
|
||||
|
||||
using namespace Telegram;
|
||||
|
||||
Contact::Contact(QJsonObject contact)
|
||||
{
|
||||
phoneNumber = contact.value("phone_number").toString();
|
||||
firstname = contact.value("first_name").toString();
|
||||
lastname = contact.value("last_name").toString();
|
||||
userId = contact.value("user_id").toInt();
|
||||
}
|
||||
@@ -0,0 +1,35 @@
|
||||
#ifndef CONTACT_H
|
||||
#define CONTACT_H
|
||||
|
||||
#include <QDebug>
|
||||
#include <QString>
|
||||
#include <QJsonObject>
|
||||
|
||||
namespace Telegram {
|
||||
|
||||
class Contact
|
||||
{
|
||||
public:
|
||||
Contact() {}
|
||||
Contact(QJsonObject contact);
|
||||
|
||||
QString phoneNumber;
|
||||
QString firstname;
|
||||
QString lastname;
|
||||
quint32 userId;
|
||||
};
|
||||
|
||||
inline QDebug operator<< (QDebug dbg, const Contact &contact)
|
||||
{
|
||||
dbg.nospace() << qUtf8Printable(QString("Telegram::Contact(phoneNumber=%1; firstname=%2; lastname=%3; userId=%4)")
|
||||
.arg(contact.phoneNumber)
|
||||
.arg(contact.firstname)
|
||||
.arg(contact.lastname)
|
||||
.arg(contact.userId));
|
||||
|
||||
return dbg.maybeSpace();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
#endif // CONTACT_H
|
||||
@@ -0,0 +1,12 @@
|
||||
#include "document.h"
|
||||
|
||||
using namespace Telegram;
|
||||
|
||||
Document::Document(QJsonObject document)
|
||||
{
|
||||
fileId = document.value("file_id").toString();
|
||||
thumb = PhotoSize(document.value("thumb").toObject());
|
||||
fileName = document.value("file_name").toString();
|
||||
mimeType = document.value("mime_type").toString();
|
||||
fileSize = document.value("file_size").toInt();
|
||||
}
|
||||
@@ -0,0 +1,38 @@
|
||||
#ifndef DOCUMENT_H
|
||||
#define DOCUMENT_H
|
||||
|
||||
#include <QDebug>
|
||||
#include <QString>
|
||||
#include <QJsonObject>
|
||||
#include "photosize.h"
|
||||
|
||||
namespace Telegram {
|
||||
|
||||
class Document
|
||||
{
|
||||
public:
|
||||
Document() {}
|
||||
Document(QJsonObject document);
|
||||
|
||||
QString fileId;
|
||||
PhotoSize thumb;
|
||||
QString fileName;
|
||||
QString mimeType;
|
||||
quint64 fileSize;
|
||||
};
|
||||
|
||||
inline QDebug operator<< (QDebug dbg, const Document &document)
|
||||
{
|
||||
dbg.nospace() << qUtf8Printable(QString("Telegram::Document(fileId=%1; thumb=%2; fileName=%3; mimeType=%4; fileSize=%5)")
|
||||
.arg(document.fileId)
|
||||
.arg("PhotoSize(" + document.thumb.fileId + ")")
|
||||
.arg(document.fileName)
|
||||
.arg(document.mimeType)
|
||||
.arg(document.fileSize));
|
||||
|
||||
return dbg.maybeSpace();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
#endif // DOCUMENT_H
|
||||
@@ -0,0 +1,32 @@
|
||||
#ifndef FILE_H
|
||||
#define FILE_H
|
||||
|
||||
#include <QDebug>
|
||||
#include <QString>
|
||||
|
||||
namespace Telegram {
|
||||
|
||||
class File
|
||||
{
|
||||
public:
|
||||
File(QString fileId, qint64 fileSize = -1, QString filePath = QString()) :
|
||||
fileId(fileId), fileSize(fileSize), filePath(filePath) {}
|
||||
|
||||
QString fileId;
|
||||
qint64 fileSize;
|
||||
QString filePath;
|
||||
};
|
||||
|
||||
inline QDebug operator<< (QDebug dbg, const File &file)
|
||||
{
|
||||
dbg.nospace() << qUtf8Printable(QString("Telegram::File(fileId=%1; fileSize=%2; filePath=%3)")
|
||||
.arg(file.fileId)
|
||||
.arg(file.fileSize)
|
||||
.arg(file.filePath));
|
||||
|
||||
return dbg.maybeSpace();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
#endif // FILE_H
|
||||
@@ -0,0 +1,9 @@
|
||||
#include "location.h"
|
||||
|
||||
using namespace Telegram;
|
||||
|
||||
Location::Location(QJsonObject location)
|
||||
{
|
||||
longitude = location.value("longitude").toDouble();
|
||||
latitude = location.value("latitude").toDouble();
|
||||
}
|
||||
@@ -0,0 +1,31 @@
|
||||
#ifndef LOCATION_H
|
||||
#define LOCATION_H
|
||||
|
||||
#include <QDebug>
|
||||
#include <QString>
|
||||
#include <QJsonObject>
|
||||
|
||||
namespace Telegram {
|
||||
|
||||
class Location
|
||||
{
|
||||
public:
|
||||
Location() {}
|
||||
Location(QJsonObject location);
|
||||
|
||||
float longitude;
|
||||
float latitude;
|
||||
};
|
||||
|
||||
inline QDebug operator<< (QDebug dbg, const Location &location)
|
||||
{
|
||||
dbg.nospace() << qUtf8Printable(QString("Telegram::Location(longitude=%1; latitude=%2)")
|
||||
.arg(location.longitude)
|
||||
.arg(location.latitude));
|
||||
|
||||
return dbg.maybeSpace();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
#endif // LOCATION_H
|
||||
@@ -0,0 +1,116 @@
|
||||
#include "message.h"
|
||||
|
||||
using namespace Telegram;
|
||||
|
||||
Message::Message(QJsonObject message)
|
||||
{
|
||||
id = message.value("message_id").toInt();
|
||||
date = QDateTime::fromMSecsSinceEpoch(message.value("date").toInt());
|
||||
chat = Chat(message.value("chat").toObject());
|
||||
|
||||
/**
|
||||
x audio Audio Optional. Message is an audio file, information about the file
|
||||
document Document Optional. Message is a general file, information about the file
|
||||
photo Array of PhotoSize Optional. Message is a photo, available sizes of the photo
|
||||
sticker Sticker Optional. Message is a sticker, information about the sticker
|
||||
video Video Optional. Message is a video, information about the video
|
||||
voice Voice Optional. Message is a voice message, information about the file
|
||||
caption String Optional. Caption for the photo or video
|
||||
contact Contact Optional. Message is a shared contact, information about the contact
|
||||
location Location Optional. Message is a shared location, information about the location
|
||||
new_chat_participant User Optional. A new member was added to the group, information about them (this member may be bot itself)
|
||||
left_chat_participant User Optional. A member was removed from the group, information about them (this member may be bot itself)
|
||||
new_chat_photo Array of PhotoSize Optional. A chat photo was change to this value
|
||||
delete_chat_photo True Optional. Informs that the chat photo was deleted
|
||||
group_chat_created True Optional. Informs that the group has been created
|
||||
*/
|
||||
|
||||
if (message.contains("from")) {
|
||||
from = User(message.value("from").toObject());
|
||||
}
|
||||
if (message.contains("forward_from")) {
|
||||
forwardFrom = User(message.value("forward_from").toObject());
|
||||
}
|
||||
if (message.contains("forward_date")) {
|
||||
forwardDate = QDateTime::fromMSecsSinceEpoch(message.value("forward_date").toInt());
|
||||
}
|
||||
if (message.contains("reply_to_message")) {
|
||||
replyToMessage = new Message(message.value("reply_to_message").toObject());
|
||||
}
|
||||
|
||||
// Parse payload
|
||||
QJsonObject obj;
|
||||
if (message.contains("text")) {
|
||||
string = message.value("text").toString();
|
||||
type = Message::TextType;
|
||||
}
|
||||
if (message.contains("audio")) {
|
||||
obj = message.value("audio").toObject();
|
||||
audio = Audio(obj);
|
||||
type = Message::AudioType;
|
||||
}
|
||||
if (message.contains("document")) {
|
||||
obj = message.value("document").toObject();
|
||||
document = Document(obj);
|
||||
type = Message::DocumentType;
|
||||
}
|
||||
if (message.contains("photo")) {
|
||||
foreach (QJsonValue val, message.value("photo").toArray()) {
|
||||
photo.append(PhotoSize(val.toObject()));
|
||||
}
|
||||
type = Message::PhotoType;
|
||||
}
|
||||
if (message.contains("sticker")) {
|
||||
obj = message.value("sticker").toObject();
|
||||
sticker = Sticker(obj);
|
||||
type = Message::StickerType;
|
||||
}
|
||||
if (message.contains("video")) {
|
||||
obj = message.value("video").toObject();
|
||||
video = Video(obj);
|
||||
type = Message::VideoType;
|
||||
}
|
||||
if (message.contains("voice")) {
|
||||
obj = message.value("voice").toObject();
|
||||
voice = Voice(obj);
|
||||
type = Message::VoiceType;
|
||||
}
|
||||
if (message.contains("contact")) {
|
||||
obj = message.value("contact").toObject();
|
||||
contact = Contact(obj);
|
||||
type = Message::ContactType;
|
||||
}
|
||||
if (message.contains("location")) {
|
||||
obj = message.value("location").toObject();
|
||||
location = Location(obj);
|
||||
type = Message::LocationType;
|
||||
}
|
||||
if (message.contains("new_chat_participant")) {
|
||||
obj = message.value("new_chat_participant").toObject();
|
||||
user = User(obj);
|
||||
type = Message::NewChatParticipantType;
|
||||
}
|
||||
if (message.contains("left_chat_participant")) {
|
||||
obj = message.value("left_chat_participant").toObject();
|
||||
user = User(obj);
|
||||
type = Message::LeftChatParticipantType;
|
||||
}
|
||||
if (message.contains("new_chat_title")) {
|
||||
string = message.value("new_chat_title").toString();
|
||||
type = Message::NewChatTitleType;
|
||||
}
|
||||
if (message.contains("new_chat_photo")) {
|
||||
foreach (QJsonValue val, message.value("new_chat_photo").toArray()) {
|
||||
photo.append(PhotoSize(val.toObject()));
|
||||
}
|
||||
type = Message::NewChatPhotoType;
|
||||
}
|
||||
if (message.contains("delete_chat_photo")) {
|
||||
boolean = true;
|
||||
type = Message::DeleteChatPhotoType;
|
||||
}
|
||||
if (message.contains("group_chat_created")) {
|
||||
boolean = true;
|
||||
type = Message::GroupChatCreatedType;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,79 @@
|
||||
#ifndef MESSAGE_H
|
||||
#define MESSAGE_H
|
||||
|
||||
#include <QDebug>
|
||||
|
||||
#include <QString>
|
||||
#include <QDateTime>
|
||||
#include <QJsonObject>
|
||||
#include <QJsonArray>
|
||||
|
||||
#include "audio.h"
|
||||
#include "document.h"
|
||||
#include "photosize.h"
|
||||
#include "sticker.h"
|
||||
#include "video.h"
|
||||
#include "voice.h"
|
||||
#include "contact.h"
|
||||
#include "location.h"
|
||||
#include "chat.h"
|
||||
#include "user.h"
|
||||
|
||||
namespace Telegram {
|
||||
|
||||
class Message
|
||||
{
|
||||
public:
|
||||
Message() {}
|
||||
Message(QJsonObject message);
|
||||
|
||||
/**
|
||||
* @brief Telegram message events
|
||||
*/
|
||||
enum MessageType {
|
||||
TextType, AudioType, DocumentType, PhotoType, StickerType, VideoType, VoiceType, ContactType,
|
||||
LocationType, NewChatParticipantType, LeftChatParticipantType, NewChatTitleType,
|
||||
NewChatPhotoType, DeleteChatPhotoType, GroupChatCreatedType
|
||||
};
|
||||
|
||||
// required
|
||||
quint32 id;
|
||||
QDateTime date;
|
||||
Chat chat;
|
||||
|
||||
// optional
|
||||
User from;
|
||||
User forwardFrom;
|
||||
QDateTime forwardDate;
|
||||
Message *replyToMessage;
|
||||
|
||||
MessageType type;
|
||||
|
||||
// payload
|
||||
QString string;
|
||||
User user;
|
||||
Audio audio;
|
||||
Document document;
|
||||
QList<PhotoSize> photo;
|
||||
Sticker sticker;
|
||||
Video video;
|
||||
Voice voice;
|
||||
Contact contact;
|
||||
Location location;
|
||||
bool boolean;
|
||||
};
|
||||
|
||||
inline QDebug operator<< (QDebug dbg, const Message &message)
|
||||
{
|
||||
dbg.nospace() << qUtf8Printable(QString("Telegram::Message(id=%1; date=%2; chat=%3; type=%4)")
|
||||
.arg(message.id)
|
||||
.arg(message.date.toString("dd.MM.yyyy hh:mm:ss"))
|
||||
.arg("Chat(" + QString::number(message.chat.id) + ")")
|
||||
.arg(message.type));
|
||||
|
||||
return dbg.maybeSpace();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
#endif // MESSAGE_H
|
||||
@@ -0,0 +1,11 @@
|
||||
#include "photosize.h"
|
||||
|
||||
using namespace Telegram;
|
||||
|
||||
PhotoSize::PhotoSize(QJsonObject photoSize)
|
||||
{
|
||||
fileId = photoSize.value("file_id").toString();
|
||||
width = photoSize.value("width").toInt();
|
||||
height = photoSize.value("height").toInt();
|
||||
fileSize = photoSize.value("file_size").toInt();
|
||||
}
|
||||
@@ -0,0 +1,35 @@
|
||||
#ifndef PHOTOSIZE_H
|
||||
#define PHOTOSIZE_H
|
||||
|
||||
#include <QDebug>
|
||||
#include <QString>
|
||||
#include <QJsonObject>
|
||||
|
||||
namespace Telegram {
|
||||
|
||||
class PhotoSize
|
||||
{
|
||||
public:
|
||||
PhotoSize() {}
|
||||
PhotoSize(QJsonObject photoSize);
|
||||
|
||||
QString fileId;
|
||||
quint16 width;
|
||||
quint16 height;
|
||||
quint64 fileSize;
|
||||
};
|
||||
|
||||
inline QDebug operator<< (QDebug dbg, const PhotoSize &photoSize)
|
||||
{
|
||||
dbg.nospace() << qUtf8Printable(QString("Telegram::PhotoSize(fileId=%1; width=%2; height=%3; fileSize=%4)")
|
||||
.arg(photoSize.fileId)
|
||||
.arg(photoSize.width)
|
||||
.arg(photoSize.height)
|
||||
.arg(photoSize.fileSize));
|
||||
|
||||
return dbg.maybeSpace();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
#endif // PHOTOSIZE_H
|
||||
@@ -0,0 +1,31 @@
|
||||
#ifndef FORCEREPLY
|
||||
#define FORCEREPLY
|
||||
|
||||
#include "genericreply.h"
|
||||
|
||||
namespace Telegram {
|
||||
|
||||
class ForceReply : public GenericReply
|
||||
{
|
||||
public:
|
||||
ForceReply(bool selective = false)
|
||||
: GenericReply(selective),
|
||||
forceReply(true) {}
|
||||
|
||||
/**
|
||||
* Shows reply interface to the user, as if they manually selected the bot‘s message and tapped ’Reply'
|
||||
*/
|
||||
const bool forceReply;
|
||||
|
||||
virtual QString serialize() const {
|
||||
QJsonObject o = QJsonObject();
|
||||
o.insert("force_reply", forceReply);
|
||||
o.insert("selective", selective);
|
||||
return serializeJson(o);
|
||||
}
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
#endif // FORCEREPLY
|
||||
|
||||
@@ -0,0 +1,44 @@
|
||||
#ifndef GENERICREPLY_H
|
||||
#define GENERICREPLY_H
|
||||
|
||||
#include <QString>
|
||||
#include <QJsonDocument>
|
||||
#include <QJsonObject>
|
||||
#include <QJsonArray>
|
||||
|
||||
namespace Telegram {
|
||||
|
||||
class GenericReply
|
||||
{
|
||||
public:
|
||||
GenericReply() : valid(false) {}
|
||||
GenericReply(bool selective) : selective(selective), valid(true) {}
|
||||
|
||||
/**
|
||||
* Optional. Use this parameter if you want to show the keyboard to specific users only.
|
||||
* Targets: 1) users that are @mentioned in the text of the Message object;
|
||||
* 2) if the bot's message is a reply (has reply_to_message_id), sender of the original message.
|
||||
*/
|
||||
bool selective;
|
||||
|
||||
virtual QString serialize() const {
|
||||
return QString();
|
||||
}
|
||||
|
||||
bool isValid() const {
|
||||
return valid;
|
||||
}
|
||||
|
||||
private:
|
||||
bool valid;
|
||||
|
||||
protected:
|
||||
QByteArray serializeJson(QJsonObject o) const {
|
||||
QJsonDocument d = QJsonDocument(o);
|
||||
return d.toJson(QJsonDocument::Compact);
|
||||
}
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
#endif // GENERICREPLY_H
|
||||
@@ -0,0 +1,30 @@
|
||||
#ifndef REPLYKEYBOARDHIDE
|
||||
#define REPLYKEYBOARDHIDE
|
||||
|
||||
#include "genericreply.h"
|
||||
|
||||
namespace Telegram {
|
||||
|
||||
class ReplyKeyboardHide : public GenericReply
|
||||
{
|
||||
public:
|
||||
ReplyKeyboardHide(bool selective = false)
|
||||
: GenericReply(selective),
|
||||
hideKeyboard(true) {}
|
||||
|
||||
/**
|
||||
* Requests clients to hide the custom keyboard
|
||||
*/
|
||||
const bool hideKeyboard;
|
||||
|
||||
virtual QString serialize() const {
|
||||
QJsonObject o = QJsonObject();
|
||||
o.insert("hide_keyboard", hideKeyboard);
|
||||
o.insert("selective", selective);
|
||||
return serializeJson(o);
|
||||
}
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
#endif // REPLYKEYBOARDHIDE
|
||||
@@ -0,0 +1,54 @@
|
||||
#ifndef REPLYKEYBOARDMARKUP_H
|
||||
#define REPLYKEYBOARDMARKUP_H
|
||||
|
||||
#include <QString>
|
||||
|
||||
#include "genericreply.h"
|
||||
|
||||
namespace Telegram {
|
||||
|
||||
typedef QList<QStringList> KeyboardMarkup;
|
||||
|
||||
class ReplyKeyboardMarkup : public GenericReply
|
||||
{
|
||||
public:
|
||||
ReplyKeyboardMarkup(KeyboardMarkup keyboard, bool resizeKeyboard = false, bool oneTimeKeyboard = false, bool selective = false)
|
||||
: GenericReply(selective),
|
||||
keyboard(keyboard),
|
||||
resizeKeyboard(resizeKeyboard),
|
||||
oneTimeKeyboard(oneTimeKeyboard) {}
|
||||
|
||||
/**
|
||||
* Array of button rows, each represented by an Array of Strings
|
||||
*/
|
||||
KeyboardMarkup keyboard;
|
||||
|
||||
/**
|
||||
* Optional. Requests clients to resize the keyboard vertically for optimal fit (e.g., make the keyboard smaller if there are just two rows of buttons).
|
||||
* Defaults to false, in which case the custom keyboard is always of the same height as the app's standard keyboard.
|
||||
*/
|
||||
bool resizeKeyboard;
|
||||
|
||||
/**
|
||||
* Optional. Requests clients to hide the keyboard as soon as it's been used.
|
||||
* Defaults to false.
|
||||
*/
|
||||
bool oneTimeKeyboard;
|
||||
|
||||
virtual QString serialize() const {
|
||||
QJsonObject o = QJsonObject();
|
||||
QJsonArray keyboardMarkup = QJsonArray();
|
||||
foreach (QStringList list, keyboard) {
|
||||
keyboardMarkup.append(QJsonArray::fromStringList(list));
|
||||
}
|
||||
o.insert("keyboard", keyboardMarkup);
|
||||
o.insert("resize_keyboard", resizeKeyboard);
|
||||
o.insert("one_time_keyboard", oneTimeKeyboard);
|
||||
o.insert("selective", selective);
|
||||
return serializeJson(o);
|
||||
}
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
#endif // REPLYKEYBOARDMARKUP_H
|
||||
@@ -0,0 +1,12 @@
|
||||
#include "sticker.h"
|
||||
|
||||
using namespace Telegram;
|
||||
|
||||
Sticker::Sticker(QJsonObject sticker)
|
||||
{
|
||||
fileId = sticker.value("file_id").toString();
|
||||
width = sticker.value("width").toInt();
|
||||
height = sticker.value("height").toInt();
|
||||
thumb = PhotoSize(sticker.value("thumb").toObject());
|
||||
fileSize = sticker.value("file_size").toInt();
|
||||
}
|
||||
@@ -0,0 +1,38 @@
|
||||
#ifndef STICKER_H
|
||||
#define STICKER_H
|
||||
|
||||
#include <QDebug>
|
||||
#include <QString>
|
||||
#include <QJsonObject>
|
||||
#include "photosize.h"
|
||||
|
||||
namespace Telegram {
|
||||
|
||||
class Sticker
|
||||
{
|
||||
public:
|
||||
Sticker() {}
|
||||
Sticker(QJsonObject sticker);
|
||||
|
||||
QString fileId;
|
||||
quint16 width;
|
||||
quint16 height;
|
||||
PhotoSize thumb;
|
||||
quint64 fileSize;
|
||||
};
|
||||
|
||||
inline QDebug operator<< (QDebug dbg, const Sticker &sticker)
|
||||
{
|
||||
dbg.nospace() << qUtf8Printable(QString("Telegram::Sticker(fileId=%1; width=%2; height=%3; thumb=%4; fileSize=%5)")
|
||||
.arg(sticker.fileId)
|
||||
.arg(sticker.width)
|
||||
.arg(sticker.height)
|
||||
.arg("PhotoSize(" + sticker.thumb.fileId + ")")
|
||||
.arg(sticker.fileSize));
|
||||
|
||||
return dbg.maybeSpace();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
#endif // STICKER_H
|
||||
@@ -0,0 +1,9 @@
|
||||
#include "update.h"
|
||||
|
||||
using namespace Telegram;
|
||||
|
||||
Update::Update(QJsonObject update)
|
||||
{
|
||||
id = update.value("update_id").toInt();
|
||||
message = Message(update.value("message").toObject());
|
||||
}
|
||||
@@ -0,0 +1,31 @@
|
||||
#ifndef UPDATE_H
|
||||
#define UPDATE_H
|
||||
|
||||
#include <QDebug>
|
||||
#include <QJsonObject>
|
||||
#include "message.h"
|
||||
|
||||
namespace Telegram {
|
||||
|
||||
class Update
|
||||
{
|
||||
public:
|
||||
Update() {}
|
||||
Update(QJsonObject update);
|
||||
|
||||
quint32 id;
|
||||
Message message;
|
||||
};
|
||||
|
||||
inline QDebug operator<< (QDebug dbg, const Update &update)
|
||||
{
|
||||
dbg.nospace() << qUtf8Printable(QString("Telegram::Update(id=%1; message=%2)")
|
||||
.arg(update.id)
|
||||
.arg("Message(" + QString::number(update.message.id) + ")"));
|
||||
|
||||
return dbg.maybeSpace();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
#endif // UPDATE_H
|
||||
@@ -0,0 +1,11 @@
|
||||
#include "user.h"
|
||||
|
||||
using namespace Telegram;
|
||||
|
||||
Telegram::User::User(QJsonObject user)
|
||||
{
|
||||
id = user.value("id").toInt();
|
||||
firstname = user.value("first_name").toString();
|
||||
lastname = user.value("last_name").toString();
|
||||
username = user.value("username").toString();
|
||||
}
|
||||
@@ -0,0 +1,35 @@
|
||||
#ifndef USER_H
|
||||
#define USER_H
|
||||
|
||||
#include <QDebug>
|
||||
#include <QString>
|
||||
#include <QJsonObject>
|
||||
|
||||
namespace Telegram {
|
||||
|
||||
class User
|
||||
{
|
||||
public:
|
||||
User() : id(0), firstname(QString()), lastname(QString()), username(QString()) {}
|
||||
User(QJsonObject user);
|
||||
|
||||
quint32 id;
|
||||
QString firstname;
|
||||
QString lastname;
|
||||
QString username;
|
||||
};
|
||||
|
||||
inline QDebug operator<< (QDebug dbg, const User &user)
|
||||
{
|
||||
dbg.nospace() << qUtf8Printable(QString("Telegram::User(id=%1; firstname=%2; lastname=%3; username=%4)")
|
||||
.arg(user.id)
|
||||
.arg(user.firstname)
|
||||
.arg(user.lastname)
|
||||
.arg(user.username));
|
||||
|
||||
return dbg.maybeSpace();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
#endif // USER_H
|
||||
@@ -0,0 +1,14 @@
|
||||
#include "video.h"
|
||||
|
||||
using namespace Telegram;
|
||||
|
||||
Video::Video(QJsonObject video)
|
||||
{
|
||||
fileId = video.value("file_id").toString();
|
||||
width = video.value("width").toInt();
|
||||
height = video.value("height").toInt();
|
||||
duration = video.value("duration").toInt();
|
||||
thumb = PhotoSize(video.value("thumb").toObject());
|
||||
mimeType = video.value("mime_type").toString();
|
||||
fileSize = video.value("file_size").toInt();
|
||||
}
|
||||
@@ -0,0 +1,41 @@
|
||||
#ifndef VIDEO_H
|
||||
#define VIDEO_H
|
||||
|
||||
#include <QString>
|
||||
#include <QJsonObject>
|
||||
#include "photosize.h"
|
||||
|
||||
namespace Telegram {
|
||||
|
||||
class Video
|
||||
{
|
||||
public:
|
||||
Video() {}
|
||||
Video(QJsonObject video);
|
||||
|
||||
QString fileId;
|
||||
quint16 width;
|
||||
quint16 height;
|
||||
quint64 duration;
|
||||
PhotoSize thumb;
|
||||
QString mimeType;
|
||||
QString fileSize;
|
||||
};
|
||||
|
||||
inline QDebug operator<< (QDebug dbg, const Video &video)
|
||||
{
|
||||
dbg.nospace() << qUtf8Printable(QString("Telegram::Video(fileId=%1; width=%2; height=%3; duration=%4; thumb=%5; mimeType=%6; fileSize=%7)")
|
||||
.arg(video.fileId)
|
||||
.arg(video.width)
|
||||
.arg(video.height)
|
||||
.arg(video.duration)
|
||||
.arg("PhotoSize(" + video.thumb.fileId + ")")
|
||||
.arg(video.mimeType)
|
||||
.arg(video.fileSize));
|
||||
|
||||
return dbg.maybeSpace();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
#endif // VIDEO_H
|
||||
@@ -0,0 +1,11 @@
|
||||
#include "voice.h"
|
||||
|
||||
using namespace Telegram;
|
||||
|
||||
Voice::Voice(QJsonObject voice)
|
||||
{
|
||||
fileId = voice.value("file_id").toString();
|
||||
duration = voice.value("duration").toInt();
|
||||
mimeType = voice.value("mime_type").toString();
|
||||
fileSize = voice.value("file_size").toInt();
|
||||
}
|
||||
@@ -0,0 +1,35 @@
|
||||
#ifndef VOICE_H
|
||||
#define VOICE_H
|
||||
|
||||
#include <QDebug>
|
||||
#include <QString>
|
||||
#include <QJsonObject>
|
||||
|
||||
namespace Telegram {
|
||||
|
||||
class Voice
|
||||
{
|
||||
public:
|
||||
Voice() {}
|
||||
Voice(QJsonObject voice);
|
||||
|
||||
QString fileId;
|
||||
quint64 duration;
|
||||
QString mimeType;
|
||||
quint64 fileSize;
|
||||
};
|
||||
|
||||
inline QDebug operator<< (QDebug dbg, const Voice &voice)
|
||||
{
|
||||
dbg.nospace() << qUtf8Printable(QString("Telegram::Voice(fileId=%1; duration=%2; mimeType=%3; fileSize=%4)")
|
||||
.arg(voice.fileId)
|
||||
.arg(voice.duration)
|
||||
.arg(voice.mimeType)
|
||||
.arg(voice.fileSize));
|
||||
|
||||
return dbg.maybeSpace();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
#endif // VOICE_H
|
||||
Reference in new issue
Block a user