4
1
mirror of https://github.com/QuasarApp/qTbot.git synced 2025-05-08 03:09:35 +00:00

added method to edit keyboard

This commit is contained in:
Andrei Yankovich 2023-11-14 22:58:49 +01:00
parent 91be0bc48c
commit 66aac2a5d4
15 changed files with 235 additions and 86 deletions

@ -10,23 +10,23 @@
namespace qTbot {
TelegramEditMessage::TelegramEditMessage(const QVariant &idEditedMessage,
const QVariant& chatId,
const QString& newText,
bool markdown,
bool disableWebPagePreview,
const QString& callBackQueryId,
const QMap<QString, QSharedPointer<QJsonObject>>& extraObjects):
const QVariant& chatId,
const QString& newText,
const QString& parseMode,
bool disableWebPagePreview,
const QString& callBackQueryId,
const QHash<QString, QSharedPointer<QJsonObject> > &extraObjects):
TelegramSendMsg(chatId,
newText,
extraObjects,
0,
markdown,
parseMode,
callBackQueryId,
disableWebPagePreview) {
setRequest("editMessageText");
addArg("message_id", idEditedMessage);
setRequest("editMessageText");
addArg("message_id", idEditedMessage);
}

@ -18,12 +18,12 @@ class TelegramEditMessage: public TelegramSendMsg
{
public:
TelegramEditMessage(const QVariant& idEditedMessage,
const QVariant& chatId,
const QString& newText,
bool markdown = true,
bool disableWebPagePreview = false,
const QString& callBackQueryId = "",
const QMap<QString, QSharedPointer<QJsonObject>>& extraObjects = {});
const QVariant& chatId,
const QString& newText,
const QString& parseMode = "",
bool disableWebPagePreview = false,
const QString& callBackQueryId = "",
const ExtraJsonObjects& extraObjects = {});
};
}
#endif // TELEGRAMEDITMESSAGE_H

@ -0,0 +1,20 @@
//#
//# Copyright (C) 2023-2023 QuasarApp.
//# Distributed under the GPLv3 software license, see the accompanying
//# Everyone is permitted to copy and distribute verbatim copies
//# of this license document, but changing it is not allowed.
//#
#include "telegrameditmessagereplymarkup.h"
namespace qTbot {
TelegramEditMessageReplyMarkup::TelegramEditMessageReplyMarkup(const QVariant &idEditedMessage,
const QVariant &chatId,
const QString &callBackQueryId,
const ExtraJsonObjects &extraObjects):
TelegramEditMessage(idEditedMessage, chatId, "", "", false, callBackQueryId, extraObjects)
{
setRequest("editMessageReplyMarkup");
}
}

@ -0,0 +1,27 @@
//#
//# Copyright (C) 2023-2023 QuasarApp.
//# Distributed under the GPLv3 software license, see the accompanying
//# Everyone is permitted to copy and distribute verbatim copies
//# of this license document, but changing it is not allowed.
//#
#ifndef TELEGRAMEDITMESSAGEREPLYMARKUP_H
#define TELEGRAMEDITMESSAGEREPLYMARKUP_H
#include "telegrameditmessage.h"
namespace qTbot {
/**
* @brief The TelegramEditMessageReplyMarkup class just edit alredy created Markups.
*/
class TelegramEditMessageReplyMarkup: public TelegramEditMessage
{
public:
TelegramEditMessageReplyMarkup(const QVariant& idEditedMessage,
const QVariant& chatId,
const QString& callBackQueryId = "",
const ExtraJsonObjects& extraObjects = {});
};
}
#endif // TELEGRAMEDITMESSAGEREPLYMARKUP_H

@ -11,12 +11,18 @@ namespace qTbot {
TelegramSendDocument::TelegramSendDocument(const QVariant &chatId,
const QString &text,
const QString& fileName,
const QByteArray &data):
TelegramSendFile("sendDocument", chatId, text, fileName, TELEGRAM_DOCUMENT, data) {}
const QByteArray &data,
const QString &parseMode,
unsigned long long replyToMessageId,
const ExtraJsonObjects &extraObjects):
TelegramSendFile("sendDocument", chatId, text, fileName, TELEGRAM_DOCUMENT, data, parseMode, replyToMessageId, extraObjects) {}
TelegramSendDocument::TelegramSendDocument(const QVariant &chatId,
const QString &text,
const QFileInfo &file):
TelegramSendFile("sendDocument", chatId, text, file) {}
const QFileInfo &file,
const QString &parseMode,
unsigned long long replyToMessageId,
const ExtraJsonObjects &extraObjects):
TelegramSendFile("sendDocument", chatId, text, file, parseMode, replyToMessageId, extraObjects) {}
}

@ -22,11 +22,17 @@ public:
TelegramSendDocument(const QVariant &chatId,
const QString &text,
const QString &fileName,
const QByteArray& data);
const QByteArray& data,
const QString& parseMode = "",
unsigned long long replyToMessageId = 0,
const ExtraJsonObjects& extraObjects = {});
TelegramSendDocument(const QVariant &chatId,
const QString &text,
const QFileInfo &file);
const QFileInfo &file,
const QString& parseMode = "",
unsigned long long replyToMessageId = 0,
const ExtraJsonObjects& extraObjects = {});
};
}

@ -17,8 +17,9 @@ qTbot::TelegramSendFile::TelegramSendFile(const QString &request,
const QString &fileName,
const QString &fileType,
const QByteArray &data,
const QString& parseMode,
unsigned long long replyToMessageId,
const QMap<QString, QSharedPointer<QJsonObject>>& extraObjects
const ExtraJsonObjects& extraObjects
):
TelegramSingleRquest(request) {
@ -30,6 +31,10 @@ qTbot::TelegramSendFile::TelegramSendFile(const QString &request,
addArg("reply_to_message_id", replyToMessageId);
}
if (parseMode.size()) {
addArg("parse_mode", parseMode);
}
for (auto it = extraObjects.begin(); it != extraObjects.end(); it = std::next(it)) {
addArg(it.key(), QJsonDocument(*it.value()).toJson(QJsonDocument::Compact));
}
@ -41,8 +46,9 @@ qTbot::TelegramSendFile::TelegramSendFile(const QString &request,
const QVariant &chatId,
const QString &text,
const QFileInfo &file,
const QString &parseMode,
unsigned long long replyToMessageId,
const QMap<QString, QSharedPointer<QJsonObject> > &extraObjects):
const QHash<QString, QSharedPointer<QJsonObject> > &extraObjects):
TelegramSingleRquest(request) {
addArg("chat_id", chatId);
@ -54,6 +60,10 @@ qTbot::TelegramSendFile::TelegramSendFile(const QString &request,
addArg("reply_to_message_id", replyToMessageId);
}
if (parseMode.size()) {
addArg("parse_mode", parseMode);
}
QFile readFile(file.absoluteFilePath());
if (!readFile.open(QIODevice::ReadOnly)) {
qWarning() << "Fail to open file" << file.absoluteFilePath();

@ -28,15 +28,18 @@ public:
const QString &fileName,
const QString &fileType,
const QByteArray& data,
const QString& parseMode = "",
unsigned long long replyToMessageId = 0,
const QMap<QString, QSharedPointer<QJsonObject> > &extraObjects = {});
const QHash<QString, QSharedPointer<QJsonObject> > &extraObjects = {});
TelegramSendFile(const QString &request,
const QVariant &chatId,
const QString &text,
const QFileInfo &file,
const QString& parseMode = "",
unsigned long long replyToMessageId = 0,
const QMap<QString, QSharedPointer<QJsonObject> > &extraObjects = {});
const QHash<QString, QSharedPointer<QJsonObject> > &extraObjects = {});
RequestMethod method() const override;

@ -13,9 +13,9 @@ namespace qTbot {
TelegramSendMsg::TelegramSendMsg(const QVariant &chatId,
const QString &text,
const QMap<QString, QSharedPointer<QJsonObject> > &extraObjects,
const QHash<QString, QSharedPointer<QJsonObject> > &extraObjects,
unsigned long long replyToMessageId,
bool markdown,
const QString& parseMode,
const QString &callBackQueryId,
bool disableWebPagePreview)
:
@ -32,8 +32,8 @@ TelegramSendMsg::TelegramSendMsg(const QVariant &chatId,
args["reply_to_message_id"] = replyToMessageId;
}
if (markdown) {
args["parse_mode"] = "Markdown";
if (parseMode.size()) {
args["parse_mode"] = parseMode;
}
if (disableWebPagePreview) {

@ -17,11 +17,21 @@ namespace qTbot {
class TelegramSendMsg: public TelegramSingleRquest
{
public:
/**
* @brief TelegramSendMsg
* @param chatId
* @param text
* @param extraObjects
* @param replyToMessageId
* @param parseMode This is mode of parsing. supported modes is markdown and html
* @param callBackQueryId
* @param disableWebPagePreview
*/
TelegramSendMsg(const QVariant& chatId,
const QString& text,
const QMap<QString, QSharedPointer<QJsonObject>>& extraObjects = {},
const ExtraJsonObjects& extraObjects = {},
unsigned long long replyToMessageId = 0,
bool markdown = true,
const QString& parseMode = "",
const QString& callBackQueryId = "",
bool disableWebPagePreview = false
);

@ -15,19 +15,21 @@ TelegramSendPhoto::TelegramSendPhoto(const QVariant &chatId,
const QString &text,
const QString &fileName,
const QByteArray &data,
const QString& parseMode,
unsigned long long replyToMessageId,
const QMap<QString, QSharedPointer<QJsonObject>>& extraObjects
const QHash<QString, QSharedPointer<QJsonObject> > &extraObjects
):
TelegramSendFile("sendPhoto", chatId, text, fileName, TELEGRAM_PHOTO, data, replyToMessageId, extraObjects) {
TelegramSendFile("sendPhoto", chatId, text, fileName, TELEGRAM_PHOTO, data, parseMode, replyToMessageId, extraObjects) {
}
TelegramSendPhoto::TelegramSendPhoto(const QVariant &chatId,
const QString &text,
const QFileInfo &file,
const QString& parseMode,
unsigned long long replyToMessageId,
const QMap<QString, QSharedPointer<QJsonObject> > &extraObjects):
TelegramSendFile("sendPhoto", chatId, text, file, replyToMessageId, extraObjects) {
const QHash<QString, QSharedPointer<QJsonObject> > &extraObjects):
TelegramSendFile("sendPhoto", chatId, text, file, parseMode, replyToMessageId, extraObjects) {
}

@ -23,15 +23,17 @@ public:
const QString &text,
const QString &fileName,
const QByteArray& data,
const QString& parseMode = "",
unsigned long long replyToMessageId = 0,
const QMap<QString, QSharedPointer<QJsonObject>>& extraObjects = {}
const ExtraJsonObjects& extraObjects = {}
);
TelegramSendPhoto(const QVariant &chatId,
const QString &text,
const QFileInfo &file,
const QString& parseMode = "",
unsigned long long replyToMessageId = 0,
const QMap<QString, QSharedPointer<QJsonObject>>& extraObjects = {}
const ExtraJsonObjects& extraObjects = {}
);
};

@ -20,6 +20,11 @@
namespace qTbot {
/**
* @brief ExtraJsonObjects hash map of the extra objects of the message.
*/
typedef QHash<QString, QSharedPointer<QJsonObject>> ExtraJsonObjects;
/**
* @brief The iRequest class Is main interface for all custom requests.
* @see IBot::sendRequest

@ -21,6 +21,7 @@
#include <requests/telegrameditmessage.h>
#include <requests/telegramsendlocation.h>
#include <requests/telegramsendphoto.h>
#include <requests/telegrameditmessagereplymarkup.h>
#include <QNetworkReply>
#include <QSharedPointer>
@ -70,10 +71,10 @@ bool ITelegramBot::sendMessage(const QVariant &chatId, const QString &text) {
bool ITelegramBot::sendSpecificMessage(const QVariant & chatId,
const QString &text,
const QMap<QString, QSharedPointer<QJsonObject>> &extraObjects,
const ExtraJsonObjects &extraObjects,
const QString &callBackQueryId,
unsigned long long replyToMessageId,
bool markdown,
const QString& parseMode,
bool disableWebPagePreview) {
if (!chatId.isValid() || chatId.isNull())
@ -87,7 +88,7 @@ bool ITelegramBot::sendSpecificMessage(const QVariant & chatId,
text,
extraObjects,
replyToMessageId,
markdown,
parseMode,
callBackQueryId,
disableWebPagePreview);
@ -101,7 +102,7 @@ bool ITelegramBot::sendSpecificMessageWithKeyboard(const QVariant &chatId,
bool onTimeKeyboard,
bool autoResizeKeyboard,
unsigned long long replyToMessageId,
bool markdown,
const QString &parseMode,
bool disableWebPagePreview) {
if (!chatId.isValid() || chatId.isNull())
@ -111,7 +112,7 @@ bool ITelegramBot::sendSpecificMessageWithKeyboard(const QVariant &chatId,
text,
prepareKeyboard(autoResizeKeyboard, onTimeKeyboard, keyboard),
replyToMessageId,
markdown,
parseMode,
callBackQueryId,
disableWebPagePreview);
@ -134,7 +135,7 @@ bool ITelegramBot::deleteMessage(const QVariant &chatId, const QVariant &message
bool ITelegramBot::editSpecificMessageWithKeyboard(const QVariant & messageId,
const QVariant &chatId,
const QString &newText,
bool markdown,
const QString &parseMode,
bool disableWebPagePreview,
const QList<QList<QString>> &keyboard,
const QString &callBackQueryId,
@ -150,7 +151,7 @@ bool ITelegramBot::editSpecificMessageWithKeyboard(const QVariant & messageId,
auto msg = QSharedPointer<TelegramEditMessage>::create(messageId,
chatId,
newText,
markdown,
parseMode,
disableWebPagePreview,
callBackQueryId,
prepareKeyboard(autoResizeKeyboard,
@ -160,10 +161,10 @@ bool ITelegramBot::editSpecificMessageWithKeyboard(const QVariant & messageId,
return bool(sendRequest(msg));
}
QMap<QString, QSharedPointer<QJsonObject>>
qTbot::ITelegramBot::prepareInlineKeyBoard(const QList<QMap<QString, std::function<void (const QString &, const QVariant &)> > > &keyboard)
ExtraJsonObjects
qTbot::ITelegramBot::prepareInlineKeyBoard(const KeyboardOnMessage &keyboard)
{
QMap<QString, QSharedPointer<QJsonObject>> extraObjects;
ExtraJsonObjects extraObjects;
auto&& keyboardJson = QSharedPointer<QJsonObject>::create();
QJsonArray keyboardArray;
@ -185,11 +186,11 @@ qTbot::ITelegramBot::prepareInlineKeyBoard(const QList<QMap<QString, std::functi
return extraObjects;
}
QMap<QString, QSharedPointer<QJsonObject>>
ExtraJsonObjects
qTbot::ITelegramBot::prepareKeyboard(bool autoResizeKeyboard,
bool onTimeKeyboard,
const QList<QList<QString>> &keyboard) {
QMap<QString, QSharedPointer<QJsonObject>> extraObjects;
ExtraJsonObjects extraObjects;
auto&& keyboardJson = QSharedPointer<QJsonObject>::create();
QJsonArray keyboardArray;
@ -216,7 +217,7 @@ qTbot::ITelegramBot::prepareKeyboard(bool autoResizeKeyboard,
bool ITelegramBot::editSpecificMessageWithKeyboard(const QVariant &messageId,
const QVariant &chatId,
const QString &text,
bool markdown,
const QString &parseMode,
bool disableWebPagePreview,
const KeyboardOnMessage &keyboard,
const QString &callBackQueryId) {
@ -230,7 +231,7 @@ bool ITelegramBot::editSpecificMessageWithKeyboard(const QVariant &messageId,
auto msg = QSharedPointer<TelegramEditMessage>::create(messageId,
chatId,
text,
markdown,
parseMode,
disableWebPagePreview,
callBackQueryId,
prepareInlineKeyBoard(keyboard));
@ -239,11 +240,30 @@ bool ITelegramBot::editSpecificMessageWithKeyboard(const QVariant &messageId,
return bool(sendRequest(msg));
}
bool ITelegramBot::editMessageKeyboard(const QVariant &messageId,
const QVariant &chatId,
const KeyboardOnMessage &keyboard,
const QString &callBackQueryId) {
if (!chatId.isValid() || chatId.isNull())
return false;
if (!messageId.isValid() || messageId.isNull())
return false;
auto msg = QSharedPointer<TelegramEditMessageReplyMarkup>::create(messageId,
chatId,
callBackQueryId,
prepareInlineKeyBoard(keyboard));
return bool(sendRequest(msg));
}
bool ITelegramBot::editSpecificMessage(const QVariant &messageId,
const QVariant &chatId,
const QString& newText,
const QString &callBackQueryId,
bool markdown,
const QString &parseMode,
bool disableWebPagePreview) {
if (!chatId.isValid() || chatId.isNull())
@ -258,7 +278,7 @@ bool ITelegramBot::editSpecificMessage(const QVariant &messageId,
auto msg = QSharedPointer<TelegramEditMessage>::create(messageId,
chatId,
newText,
markdown,
parseMode,
disableWebPagePreview,
callBackQueryId
);
@ -272,7 +292,7 @@ bool ITelegramBot::sendSpecificMessageWithKeyboard(const QVariant &chatId,
const KeyboardOnMessage &keyboard,
const QString &callBackQueryId,
unsigned long long replyToMessageId,
bool markdown,
const QString &parseMode,
bool disableWebPagePreview) {
if (!chatId.isValid() || chatId.isNull())
@ -286,7 +306,7 @@ bool ITelegramBot::sendSpecificMessageWithKeyboard(const QVariant &chatId,
text,
prepareInlineKeyBoard(keyboard),
replyToMessageId,
markdown,
parseMode,
callBackQueryId,
disableWebPagePreview);
@ -386,6 +406,7 @@ bool ITelegramBot::sendFile(const QByteArray &file, const QString &fileName, con
bool ITelegramBot::sendPhoto(const QFileInfo &photo,
const QVariant &chatId,
const QString &description,
const QString &parseMode,
unsigned long long replyToMessageId,
const KeyboardOnMessage &keyboard) {
if (!chatId.isValid() || chatId.isNull())
@ -395,14 +416,20 @@ bool ITelegramBot::sendPhoto(const QFileInfo &photo,
return false;
}
return sendFileWithPrivate(QSharedPointer<TelegramSendPhoto>::create(
chatId, description, photo, replyToMessageId, prepareInlineKeyBoard(keyboard)));
return sendFileWithPrivate(
QSharedPointer<TelegramSendPhoto>::create(chatId,
description,
photo,
parseMode,
replyToMessageId,
prepareInlineKeyBoard(keyboard)));
}
bool ITelegramBot::sendPhoto(const QByteArray &photo,
const QString &fileName,
const QVariant &chatId,
const QString &description,
const QString &parseMode,
unsigned long long replyToMessageId,
const KeyboardOnMessage &keyboard) {
@ -417,8 +444,14 @@ bool ITelegramBot::sendPhoto(const QByteArray &photo,
return false;
}
return sendFileWithPrivate(QSharedPointer<TelegramSendPhoto>::create(
chatId, description, fileName, photo, replyToMessageId, prepareInlineKeyBoard(keyboard)));
return sendFileWithPrivate(
QSharedPointer<TelegramSendPhoto>::create(chatId,
description,
fileName,
photo,
parseMode,
replyToMessageId,
prepareInlineKeyBoard(keyboard)));
}
bool ITelegramBot::sendFileWithDescription(const QByteArray &file,

@ -24,7 +24,7 @@ class TelegramUpdateAnswer;
class TelegramSendFile;
typedef std::function<void(const QString& buttonKey, const QVariant& msgID)> ButtonCB;
typedef QList<QMap<QString, ButtonCB >> KeyboardOnMessage;
typedef QList<QHash<QString, ButtonCB >> KeyboardOnMessage;
/**
* @brief The ITelegramBot class This is base implementation of the all telegramm bots.
@ -50,22 +50,21 @@ public:
* @param extraObjects A map containing additional objects associated with the message (optional).
* @param callBackQueryId The unique identifier for callback queries triggered by the message (optional).
* @param replyToMessageId The unique identifier of the message to reply to, if any (optional).
* @param markdown Set to true to enable Markdown formatting for the text (optional).
* @param parseMode Sets a text parsing mode. supports markdown and html, by default will be used html mode. If you want to disable parsing mode sets this option to empty string.
* @param disableWebPagePreview Set to true to disable web page previews for links in the message (optional).
*
* @return Returns true if the message was sent successfully, false otherwise.
*
* @note The extraObjects parameter is a map where each key represents the object's name, and the associated value is a shared pointer to a JSON object (optional).
* @note The callBackQueryId parameter is used to handle callback queries when applicable (optional).
* @note By default, the message will be sent with Markdown formatting enabled (optional).
* @note By default, web page previews for links in the message are not disabled (optional).
*/
bool sendSpecificMessage(const QVariant &chatId,
const QString& text,
const QMap<QString, QSharedPointer<QJsonObject> > &extraObjects = {},
const qTbot::ExtraJsonObjects &extraObjects = {},
const QString &callBackQueryId = {},
unsigned long long replyToMessageId = 0,
bool markdown = true,
const QString &parseMode = "html",
bool disableWebPagePreview = false);
/**
@ -78,14 +77,15 @@ public:
* @param keyboard A list of maps where each map represents a button with a callback function.
* @param callBackQueryId The unique identifier for callback queries triggered by the message (optional).
* @param replyToMessageId The unique identifier of the message to reply to, if any (optional).
* @param markdown Set to true to enable Markdown formatting for the text (optional).
* @param parseMode Sets a text parsing mode. supports markdown and html,
* by default will be used html mode. If you want to disable parsing mode sets this option to empty string.
* @param disableWebPagePreview Set to true to disable web page previews for links in the message (optional).
*
* @return Returns true if the message was sent successfully, false otherwise.
*
* @note The keyboard parameter should be a list of maps where each map represents a button. The button's label is the map key, and the associated callback function is the map value.
* @note The keyboard parameter should be a list of maps where each map represents a button.
* The button's label is the map key, and the associated callback function is the map value.
* @note The callBackQueryId parameter is used to handle callback queries when buttons are pressed (optional).
* @note By default, the message will be sent with Markdown formatting enabled (optional).
* @note By default, web page previews for links in the message are not disabled (optional).
*/
bool sendSpecificMessageWithKeyboard(const QVariant &chatId,
@ -93,13 +93,14 @@ public:
const KeyboardOnMessage &keyboard,
const QString &callBackQueryId = "",
unsigned long long replyToMessageId = 0,
bool markdown = true,
const QString &parseMode = "html",
bool disableWebPagePreview = false);
/**
* @brief Sends a specific message with a custom keyboard to a chat.
*
* This function sends a specific message to a chat with a custom keyboard. The message can contain text and additional settings to customize its behavior.
* This function sends a specific message to a chat with a custom keyboard.
* The message can contain text and additional settings to customize its behavior.
*
* @param chatId The unique identifier of the chat to send the message to.
* @param text The text content of the message to be sent.
@ -108,14 +109,14 @@ public:
* @param onTimeKeyboard Set to true to display the keyboard only once.
* @param autoResizeKeyboard Set to true to automatically resize the keyboard.
* @param replyToMessageId The unique identifier of the message to reply to, if any.
* @param markdown Set to true to enable Markdown formatting for the text.
* @param parseMode Sets a text parsing mode. supports markdown and html,
* by default will be used html mode. If you want to disable parsing mode sets this option to empty string.
* @param disableWebPagePreview Set to true to disable web page previews for links in the message.
*
* @return Returns true if the message was sent successfully, false otherwise.
*
* @note The keyboard parameter should be a list of lists of strings representing keyboard buttons.
* @note The callBackQueryId parameter is used to handle callback queries when buttons are pressed.
* @note By default, the message will be sent with Markdown formatting enabled.
* @note By default, web page previews for links in the message are not disabled.
*/
bool sendSpecificMessageWithKeyboard(const QVariant &chatId,
@ -125,7 +126,7 @@ public:
bool onTimeKeyboard = false,
bool autoResizeKeyboard = true,
unsigned long long replyToMessageId = 0,
bool markdown = true,
const QString &parseMode = "html",
bool disableWebPagePreview = false);
bool deleteMessage(const QVariant& chatId, const QVariant& messageId) override;
@ -138,7 +139,8 @@ public:
* @param messageId The unique identifier of the message to edit.
* @param chatId The unique identifier of the chat containing the message.
* @param newText The new text content for the message.
* @param markdown Set to true to enable Markdown formatting for the new text (optional).
* @param parseMode Sets a text parsing mode. supports markdown and html,
* by default will be used html mode. If you want to disable parsing mode sets this option to empty string.
* @param disableWebPagePreview Set to true to disable web page previews for links in the new text (optional).
* @param keyboard A list of lists containing the new keyboard buttons to display (optional).
* @param callBackQueryId The unique identifier for callback queries triggered by the edited message (optional).
@ -149,19 +151,19 @@ public:
*
* @note The keyboard parameter should be a list of lists of strings representing keyboard buttons (optional).
* @note The callBackQueryId parameter is used to handle callback queries when buttons are pressed (optional).
* @note By default, the new text will be displayed with Markdown formatting enabled (optional).
* @note By default, web page previews for links in the new text are not disabled (optional).
*/
bool editSpecificMessageWithKeyboard(const QVariant &messageId,
const QVariant &chatId,
const QString &newText,
bool markdown = true,
const QString &parseMode = "html",
bool disableWebPagePreview = false,
const QList<QList<QString> > &keyboard = {},
const QString &callBackQueryId = "",
bool onTimeKeyboard = false,
bool autoResizeKeyboard = false);
/**
* @brief Edits a specific message with a custom keyboard in a chat.
*
@ -170,7 +172,8 @@ public:
* @param messageId The unique identifier of the message to edit.
* @param chatId The unique identifier of the chat containing the message.
* @param text The new text content for the message.
* @param markdown Set to true to enable Markdown formatting for the new text (optional).
* @param parseMode Sets a text parsing mode. supports markdown and html,
* by default will be used html mode. If you want to disable parsing mode sets this option to empty string.
* @param disableWebPagePreview Set to true to disable web page previews for links in the new text (optional).
* @param keyboard A list of maps where each map represents a button with a callback function (optional).
* @param callBackQueryId The unique identifier for callback queries triggered by the edited message (optional).
@ -179,17 +182,37 @@ public:
*
* @note The keyboard parameter should be a list of maps where each map represents a button. The button's label is the map key, and the associated callback function is the map value (optional).
* @note The callBackQueryId parameter is used to handle callback queries when buttons are pressed (optional).
* @note By default, the new text will be displayed with Markdown formatting enabled (optional).
* @note By default, web page previews for links in the new text are not disabled (optional).
*/
bool editSpecificMessageWithKeyboard(const QVariant& messageId,
const QVariant &chatId,
const QString &text,
bool markdown = true,
const QString &parseMode = "html",
bool disableWebPagePreview = false,
const KeyboardOnMessage &keyboard = {},
const QString &callBackQueryId = "");
/**
* @brief Edits a keyboard of message in a chat.
*
* This function allows you to edit a keyboard of specific message.
*
* @param messageId The unique identifier of the message to edit.
* @param chatId The unique identifier of the chat containing the message.
* @param keyboard A list of maps where each map represents a button with a callback function (optional).
* @param callBackQueryId The unique identifier for callback queries triggered by the edited message (optional).
*
* @return Returns true if the message was successfully edited, false otherwise.
*
* @note The keyboard parameter should be a list of maps where each map represents a button. The button's label is the map key, and the associated callback function is the map value (optional).
* @note The callBackQueryId parameter is used to handle callback queries when buttons are pressed (optional).
* @note By default, web page previews for links in the new text are not disabled (optional).
*/
bool editMessageKeyboard(const QVariant& messageId,
const QVariant &chatId,
const KeyboardOnMessage &keyboard = {},
const QString &callBackQueryId = "");
/**
* @brief Edits a specific message in a chat.
*
@ -199,20 +222,20 @@ public:
* @param chatId The unique identifier of the chat containing the message.
* @param newText The new text content for the message.
* @param callBackQueryId The unique identifier for callback queries triggered by the edited message (optional).
* @param markdown Set to true to enable Markdown formatting for the new text (optional).
* @param parseMode Sets a text parsing mode. supports markdown and html,
* by default will be used html mode. If you want to disable parsing mode sets this option to empty string.
* @param disableWebPagePreview Set to true to disable web page previews for links in the new text (optional).
*
* @return Returns true if the message was successfully edited, false otherwise.
*
* @note The callBackQueryId parameter is used to handle callback queries when applicable (optional).
* @note By default, the new text will be displayed with Markdown formatting enabled (optional).
* @note By default, web page previews for links in the new text are not disabled (optional).
*/
bool editSpecificMessage(const QVariant &messageId,
const QVariant &chatId,
const QString &newText,
const QString &callBackQueryId = {},
bool markdown = true,
const QString &parseMode = "html",
bool disableWebPagePreview = false);
[[nodiscard("do not forget to save shared pointer of file handler, because it's will not save inner bot object.")]]
@ -242,6 +265,7 @@ public:
bool sendPhoto(const QFileInfo& photo,
const QVariant& chatId,
const QString &description,
const QString &parseMode = "html",
unsigned long long replyToMessageId = 0,
const KeyboardOnMessage &keyboard = {});
@ -257,7 +281,7 @@ public:
bool sendPhoto(const QByteArray& photo,
const QString& fileName,
const QVariant& chatId,
const QString &description,
const QString &description, const QString &parseMode,
unsigned long long replyToMessageId = 0,
const KeyboardOnMessage &keyboard = {});
@ -411,10 +435,11 @@ private:
bool sendFileWithPrivate(const QSharedPointer<TelegramSendFile>& file);
QString findFileInlocatStorage(const QString& fileId) const;
QMap<QString, QSharedPointer<QJsonObject>>
prepareInlineKeyBoard(const QList<QMap<QString, std::function<void (const QString &, const QVariant &)> > > &keyboard);
QMap<QString, QSharedPointer<QJsonObject>>
prepareKeyboard(bool autoResizeKeyboard, bool onTimeKeyboard, const QList<QList<QString> > &keyboard);
QHash<QString, QSharedPointer<QJsonObject> >
prepareInlineKeyBoard(const KeyboardOnMessage &keyboard);
ExtraJsonObjects prepareKeyboard(bool autoResizeKeyboard,
bool onTimeKeyboard,
const QList<QList<QString> > &keyboard);
unsigned long long _id = 0;