Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions include.pri
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@

HEADERS += \
$$PWD/src/telegrambot.h \
$$PWD/modules/httpserver/httpserver.h \
$$PWD/vendor/qdelegate/include/qdelegate.h

INCLUDEPATH += $$PWD/src/
INCLUDEPATH += $$PWD/modules/sslserver/
INCLUDEPATH += $$PWD/modules/httpserver/
INCLUDEPATH += $$PWD/vendor/qdelegate/include/

7 changes: 4 additions & 3 deletions modules/httpserver/httpserver.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -46,14 +46,15 @@ void HttpServer::handleNewData()

// build response
QByteArray responseContent;
responseContent += (response->version.isEmpty() ? "HTTP/1.1" : response->version) + " "; // Version
responseContent += QByteArray::number((qint32)response->status) + " " + response->StatusNames.value((qint32)response->status, "") + "\r\n"; // Status
responseContent += (response->version.isEmpty() ? "HTTP/1.1" : response->version.toUtf8()) + " "; // Version
responseContent += QByteArray::number((qint32)response->status) + " "
+ response->StatusNames.value((qint32)response->status, "").toUtf8() + "\r\n"; // Status

// add headers
qint64 contentLength = 0;
for(auto itr = response->headers.begin(); itr != response->headers.end(); itr++) {
if(itr.key().toLower() == "content-length") contentLength = itr.value().toLongLong();
responseContent += itr.key() + ": " + itr.value() + "\r\n";
responseContent += itr.key().toUtf8() + ": " + itr.value().toUtf8() + "\r\n";
}

// add content length if not available
Expand Down
2 changes: 1 addition & 1 deletion src/jsonhelper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
QVariant JsonHelper::jsonPathGetImpl(QJsonValue data, QString path, bool showWarnings)
{
// json parse
QStringList splittedPath = path.split('.', QString::SkipEmptyParts);
QStringList splittedPath = path.split('.');
QStringList processed;
while(!splittedPath.isEmpty()) {
QString pathElement = splittedPath.takeFirst();
Expand Down
32 changes: 15 additions & 17 deletions src/telegrambot.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -207,7 +207,7 @@ void TelegramBot::sendMessage(QVariant chatId, QString text, int replyToMessageI
if(replyToMessageId) params.addQueryItem("reply_to_message_id", QString::number(replyToMessageId));

// handle reply markup
this->hanldeReplyMarkup(params, flags, keyboard);
this->handleReplyMarkup(params, flags, keyboard);

// call api
return this->callApiTemplate("sendMessage", params, response);
Expand All @@ -233,7 +233,7 @@ void TelegramBot::editMessageText(QVariant chatId, QVariant messageId, QString t

// only build inline keyboard
if(!(flags && TelegramFlags::ReplyKeyboardMarkup) && !(flags && TelegramFlags::ForceReply) && !(flags && TelegramFlags::ReplyKeyboardRemove)) {
this->hanldeReplyMarkup(params, flags, keyboard);
this->handleReplyMarkup(params, flags, keyboard);
}

// call api
Expand All @@ -251,7 +251,7 @@ void TelegramBot::editMessageCaption(QVariant chatId, QVariant messageId, QStrin
if(!caption.isNull()) params.addQueryItem("caption", caption);

// only build inline keyboard
this->hanldeReplyMarkup(params, TelegramFlags(), keyboard);
this->handleReplyMarkup(params, TelegramFlags(), keyboard);

// call api
this->callApiTemplate("editMessageCaption", params, response);
Expand All @@ -267,7 +267,7 @@ void TelegramBot::editMessageReplyMarkup(QVariant chatId, QVariant messageId, Te
params.addQueryItem(isInlineMessageId ? "inline_message_id" : "message_id", messageId.toString());

// only build inline keyboard
this->hanldeReplyMarkup(params, TelegramFlags(), keyboard);
this->handleReplyMarkup(params, TelegramFlags(), keyboard);

// call api
this->callApiTemplate("editMessageReplyMarkup", params, response);
Expand Down Expand Up @@ -305,7 +305,7 @@ void TelegramBot::sendPhoto(QVariant chatId, QVariant photo, QString caption, in
if(replyToMessageId) params.addQueryItem("reply_to_message_id", QString::number(replyToMessageId));

// handle reply markup
this->hanldeReplyMarkup(params, flags, keyboard);
this->handleReplyMarkup(params, flags, keyboard);

// handle file
QHttpMultiPart* multiPart = this->handleFile("photo", photo, params);
Expand All @@ -326,7 +326,7 @@ void TelegramBot::sendAudio(QVariant chatId, QVariant audio, QString caption, QS
if(replyToMessageId) params.addQueryItem("reply_to_message_id", QString::number(replyToMessageId));

// handle reply markup
this->hanldeReplyMarkup(params, flags, keyboard);
this->handleReplyMarkup(params, flags, keyboard);

// handle file
QHttpMultiPart* multiPart = this->handleFile("audio", audio, params);
Expand All @@ -344,7 +344,7 @@ void TelegramBot::sendDocument(QVariant chatId, QVariant document, QString capti
if(replyToMessageId) params.addQueryItem("reply_to_message_id", QString::number(replyToMessageId));

// handle reply markup
this->hanldeReplyMarkup(params, flags, keyboard);
this->handleReplyMarkup(params, flags, keyboard);

// handle file
QHttpMultiPart* multiPart = this->handleFile("document", document, params);
Expand All @@ -361,7 +361,7 @@ void TelegramBot::sendSticker(QVariant chatId, QVariant sticker, int replyToMess
if(replyToMessageId) params.addQueryItem("reply_to_message_id", QString::number(replyToMessageId));

// handle reply markup
this->hanldeReplyMarkup(params, flags, keyboard);
this->handleReplyMarkup(params, flags, keyboard);

// handle file
QHttpMultiPart* multiPart = this->handleFile("sticker", sticker, params);
Expand All @@ -382,7 +382,7 @@ void TelegramBot::sendVideo(QVariant chatId, QVariant video, QString caption, in
if(replyToMessageId) params.addQueryItem("reply_to_message_id", QString::number(replyToMessageId));

// handle reply markup
this->hanldeReplyMarkup(params, flags, keyboard);
this->handleReplyMarkup(params, flags, keyboard);

// handle file
QHttpMultiPart* multiPart = this->handleFile("video", video, params);
Expand All @@ -401,7 +401,7 @@ void TelegramBot::sendVoice(QVariant chatId, QVariant voice, QString caption, in
if(replyToMessageId) params.addQueryItem("reply_to_message_id", QString::number(replyToMessageId));

// handle reply markup
this->hanldeReplyMarkup(params, flags, keyboard);
this->handleReplyMarkup(params, flags, keyboard);

// handle file
QHttpMultiPart* multiPart = this->handleFile("voice", voice, params);
Expand All @@ -420,7 +420,7 @@ void TelegramBot::sendVideoNote(QVariant chatId, QVariant videoNote, int length,
if(replyToMessageId) params.addQueryItem("reply_to_message_id", QString::number(replyToMessageId));

// handle reply markup
this->hanldeReplyMarkup(params, flags, keyboard);
this->handleReplyMarkup(params, flags, keyboard);

// handle file
QHttpMultiPart* multiPart = this->handleFile("video_note", videoNote, params);
Expand All @@ -439,7 +439,7 @@ void TelegramBot::sendLocation(QVariant chatId, double latitude, double longitud
if(replyToMessageId) params.addQueryItem("reply_to_message_id", QString::number(replyToMessageId));

// handle reply markup
this->hanldeReplyMarkup(params, flags, keyboard);
this->handleReplyMarkup(params, flags, keyboard);

// call api
this->callApiTemplate("sendLocation", params, response);
Expand All @@ -458,7 +458,7 @@ void TelegramBot::sendVenue(QVariant chatId, double latitude, double longitude,
if(replyToMessageId) params.addQueryItem("reply_to_message_id", QString::number(replyToMessageId));

// handle reply markup
this->hanldeReplyMarkup(params, flags, keyboard);
this->handleReplyMarkup(params, flags, keyboard);

// call api
this->callApiTemplate("sendVenue", params, response);
Expand All @@ -475,7 +475,7 @@ void TelegramBot::sendContact(QVariant chatId, QString phoneNumber, QString firs
if(replyToMessageId) params.addQueryItem("reply_to_message_id", QString::number(replyToMessageId));

// handle reply markup
this->hanldeReplyMarkup(params, flags, keyboard);
this->handleReplyMarkup(params, flags, keyboard);

// call api
this->callApiTemplate("sendContact", params, response);
Expand Down Expand Up @@ -754,8 +754,6 @@ QNetworkReply* TelegramBot::callApi(QString method, QUrlQuery params, bool delet
QUrl url(QString("https://api.telegram.org/bot%1/%2").arg(this->apiKey, method));
url.setQuery(params);

qDebug() << url;

// execute
QNetworkRequest request(url);
QNetworkReply* reply = multiPart ? this->aManager.post(request, multiPart) : this->aManager.get(request);
Expand Down Expand Up @@ -793,7 +791,7 @@ QHttpMultiPart* TelegramBot::createUploadFile(QString name, QString fileName, QB
return multiPart;
}

void TelegramBot::hanldeReplyMarkup(QUrlQuery& params, TelegramFlags flags, TelegramKeyboardRequest &keyboard)
void TelegramBot::handleReplyMarkup(QUrlQuery& params, TelegramFlags flags, TelegramKeyboardRequest &keyboard)
{
// handle types
QString replyMarkup;
Expand Down
2 changes: 1 addition & 1 deletion src/telegrambot.h
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,7 @@ class TelegramBot : public QObject

// helpers
QHttpMultiPart* createUploadFile(QString name, QString fileName, QByteArray& content, bool detectMimeType = false, QHttpMultiPart* multiPart = 0);
void hanldeReplyMarkup(QUrlQuery& params, TelegramFlags flags, TelegramKeyboardRequest& keyboard);
void handleReplyMarkup(QUrlQuery& params, TelegramFlags flags, TelegramKeyboardRequest& keyboard);
QHttpMultiPart* handleFile(QString fieldName, QVariant file, QUrlQuery& params, QHttpMultiPart* multiPart = 0);

// global data
Expand Down
8 changes: 4 additions & 4 deletions src/telegramdatastructs.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@
QString switchInlineQueryCurrentChat; \
\
/* normal keyboard */ \
bool requestContact; \
bool requestLocation;
bool requestContact = false; \
bool requestLocation = false;

struct TelegramBotKeyboardButtonRequest
{
Expand Down Expand Up @@ -234,7 +234,7 @@ typedef QList<QList<TelegramBotKeyboardButton>> TelegramKeyboard;

// TelegramBotChat - This object represents a chat.
struct TelegramBotChat : public TelegramBotObject {
qint32 id; // Unique identifier for this chat. This number may be greater than 32 bits and some programming languages may have difficulty/silent defects in interpreting it. But it is smaller than 52 bits, so a signed 64 bit integer or double-precision float type are safe for storing this identifier.
qint64 id; // Unique identifier for this chat. This number from now can be signed 64 bit integer or double-precision float type are safe for storing this identifier.
QString type; // Type of chat, can be either “private”, “group”, “supergroup” or “channel”
QString title; // Optional. Title, for supergroups, channels and group chats
QString username; // Optional. Username, for private chats, supergroups and channels if available
Expand All @@ -247,7 +247,7 @@ struct TelegramBotChat : public TelegramBotObject {

// parse logic
virtual void fromJson(QJsonObject& object) {
JsonHelperT<qint32>::jsonPathGet(object, "id", this->id);
JsonHelperT<qint64>::jsonPathGet(object, "id", this->id);
JsonHelperT<QString>::jsonPathGet(object, "type", this->type);
JsonHelperT<QString>::jsonPathGet(object, "title", this->title, false);
JsonHelperT<QString>::jsonPathGet(object, "username", this->username, false);
Expand Down