4
1
mirror of https://github.com/QuasarApp/qTbot.git synced 2025-05-07 18:59:37 +00:00

first echo version

This commit is contained in:
Andrei Yankovich 2023-09-16 21:02:02 +02:00
parent d1b646f909
commit 017fc82695
19 changed files with 2042 additions and 25 deletions

@ -21,7 +21,7 @@
],
"extraLib": "crypto",
"targetDir": "/media/D/builds/qTbot/Distro",
"deployVersion": "0.16.1cb429e",
"deployVersion": "0.17.d1b646f",
}

@ -5,6 +5,7 @@
//# of this license document, but changing it is not allowed.
//#
#include "qvariant.h"
#include <qTbot/telegramrestbot.h>
#include <QCoreApplication>
@ -16,6 +17,12 @@ int main(int argc, char *argv[]) {
qTbot::TelegramRestBot bot;
QObject::connect(&bot, &qTbot::TelegramRestBot::sigReceiveMessage, [&bot](auto){
while(auto msg = bot.takeNextUnreadMessage()) {
bot.sendSpecificMessage(msg->chatId(), "I see it - я вижу это", msg->messageId());
}
});
bot.login("6349356184:AAFotw9EC46sgAQrkGQ_jeHPyv3EAapZXcM");
return app.exec();
}

@ -10,7 +10,7 @@
#include <QtCore/qglobal.h>
#define QTBOT_VERSION "0.16.1cb429e"
#define QTBOT_VERSION "0.17.d1b646f"
#if defined(QTBOT_LIBRARY)
# define QTBOT_EXPORT Q_DECL_EXPORT

@ -23,6 +23,9 @@ void IBot::setToken(const QByteArray &newToken) {
}
void IBot::incomeNewMessage(const QSharedPointer<iMessage> &message) {
if (!message->isValid())
return;
auto id = message->messageId();
if (!_processed.contains(id)) {
@ -38,6 +41,14 @@ void IBot::markMessageAsProcessed(const QSharedPointer<iMessage> &message) {
_notProcessedMessages.remove(message->messageId());
}
QSet<unsigned long long> IBot::processed() const {
return _processed;
}
void IBot::setProcessed(const QSet<unsigned long long> &newProcessed) {
_processed = newProcessed;
}
const QString &IBot::name() const {
return _name;
}

@ -48,11 +48,14 @@ public:
virtual bool login(const QByteArray& token) = 0;
/**
* @brief sendMessage This method should be send message to the server.
* @param message This is data for sending.
* @return true if the message sent successful else false.
*/
virtual bool sendMessage(const QSharedPointer<iMessage>& message) = 0;
* @brief sendMessage This method sents text to the selected chat.
* @param chatId This is selected chat id
* @param text This is text that neet to sent.
* @return true if data sents successful else false.
*
* @note the specific implementations of this interface can have a different method for sending.
*/
virtual bool sendMessage(const QVariant& chatId, const QString& text) = 0;
/**
* @brief token This is token value for authication on the remote server (bot)
@ -78,6 +81,18 @@ public:
*/
QSharedPointer<iMessage> takeNextUnreadMessage();
/**
* @brief processed This method return list of processed mesages.
* @return list of processed messages.
*/
QSet<unsigned long long> processed() const;
/**
* @brief setProcessed This method sets new list of processed mesages.
* @param newProcessed list of processed messagees.
*/
void setProcessed(const QSet<unsigned long long> &newProcessed);
protected:
/**

@ -55,6 +55,12 @@ public:
*/
virtual QString from() const = 0;
/**
* @brief from This virtual function should return name of the chat when sent this message to bot.
* @return id of the sender.
*/
virtual QVariant chatId() const = 0;
/**
* @brief messageId This method returns numeric id of the message.
* @return numeric id of the message.

File diff suppressed because it is too large Load Diff

@ -31,7 +31,543 @@ public:
~ITelegramBot();
bool login(const QByteArray &token) override;
bool sendMessage(const QSharedPointer<iMessage> &message) override;
bool sendMessage(const QVariant &chatId, const QString& text) override;
/**
* @brief Sends a message to a chat or channel.
*
* The `sendMessage` method is used to send a message to a chat. This method allows
* sending text messages to chats and channels. You can also specify additional
* parameters such as text formatting, a reply to a specific message, and disabling
* web page preview.
*
* @param chatId The identifier of the chat or channel to which the message will be sent.
* It can be a string, number, or another valid data type containing the chat identifier.
* @param text The text of the message to be sent.
* @param replyToMessageId The identifier of the message to which you want to reply. If you want to send
* a regular message without a reply, leave this field as 0.
* @param markdown A flag indicating whether the message text should be formatted using Markdown.
* If `true`, the text will be formatted using Markdown syntax. If `false`, the text will be
* sent as plain text.
* @param disableWebPagePreview A flag indicating whether to disable web page preview in the message.
* If `true`, web page preview will be disabled.
* @param cb A callback function to handle the server response after sending the message. This parameter
* can be left empty if no callback is required.
*
* @return `true` if the message was successfully sent, and `false` otherwise.
*
* Usage examples:
* @code
* // Send a plain text message
* bool result = sendMessage(chatId, "Hello, world!");
*
* // Send a formatted text message as a reply to another message
* bool result = sendMessage(chatId, "This is a reply to your message.", messageId);
*
* // Send a message with disabled web page preview
* bool result = sendMessage(chatId, "Check out this website: [OpenAI](https://www.openai.com/)", 0, true, true);
* @endcode
*/
bool sendSpecificMessage(const QVariant &chatId,
const QString& text,
unsigned long long replyToMessageId = 0,
bool markdown = true,
bool disableWebPagePreview = false,
const Responce& cb = {});
// /*
// **********************************************************************************************************************
// *
// * forwardMessage implementations
// *
// */
// Message::Id Bot::forwardMessage(const QVariant& chatId, const QVariant& fromChatId, Message::Id messageId);
// Message::Id Bot::forwardMessage(const ParameterList& params);
// /*
// **********************************************************************************************************************
// *
// * copyMessage implementations
// *
// */
// Message::Id Bot::copyMessage(const QVariant& chatId, const QVariant& fromChatId, Message::Id messageId);
// Message::Id Bot::copyMessage(const ParameterList& params);
// /*
// **********************************************************************************************************************
// *
// * sendPhoto implementations
// *
// */
// Message::Id Bot::sendPhoto(const QVariant& chatId, QFile *file, const QString& caption, Message::Id replyToMessageId);
// Message::Id Bot::sendPhoto(const QVariant& chatId, const QString& fileId, const QString& caption, Message::Id replyToMessageId);
// Message::Id Bot::sendPhoto(const QVariant& chatId, const QByteArray& fileData, const QString& caption, Message::Id replyToMessageId);
// Message::Id Bot::sendPhoto(const ParameterList& params);
// /*
// **********************************************************************************************************************
// *
// * sendAudio implementations
// *
// */
// Message::Id Bot::sendAudio(const QVariant& chatId, QFile *file, qint64 duration, const QString& performer, const QString& title, Message::Id replyToMessageId);
// Message::Id Bot::sendAudio(const QVariant& chatId, const QString& fileId, qint64 duration, const QString& performer, const QString& title, Message::Id replyToMessageId);
// Message::Id Bot::sendAudio(const ParameterList& params);
// /*
// **********************************************************************************************************************
// *
// * sendDocument implementations
// *
// */
// Message::Id Bot::sendDocument(const QVariant& chatId, QFile *file, Message::Id replyToMessageId);
// Message::Id Bot::sendDocument(const QVariant& chatId, const QByteArray& fileData, Message::Id replyToMessageId);
// Message::Id Bot::sendDocument(const QVariant& chatId, const QString& fileId, Message::Id replyToMessageId);
// Message::Id Bot::sendDocument(const ParameterList& params);
// /*
// **********************************************************************************************************************
// *
// * sendVideo implementations
// *
// */
// Message::Id Bot::sendVideo(const QVariant& chatId, QFile *file, qint64 duration, const QString& caption, Message::Id replyToMessageId);
// Message::Id Bot::sendVideo(const QVariant& chatId, const QString& fileId, qint64 duration, const QString& caption, Message::Id replyToMessageId);
// Message::Id Bot::sendVideo(const ParameterList& params);
// /*
// **********************************************************************************************************************
// *
// * sendVoice implementations
// *
// */
// Message::Id Bot::sendVoice(const QVariant& chatId, QFile *file, qint64 duration, Message::Id replyToMessageId);
// Message::Id Bot::sendVoice(const QVariant& chatId, const QString& fileId, qint64 duration, Message::Id replyToMessageId);
// Message::Id Bot::sendVoice(const ParameterList& params);
// /*
// **********************************************************************************************************************
// *
// * sendLocation implementations
// *
// */
// Message::Id Bot::sendLocation(const QVariant& chatId, float latitude, float longitude, Message::Id replyToMessageId);
// Message::Id Bot::sendLocation(const ParameterList& params);
// /*
// **********************************************************************************************************************
// *
// * sendContact implementations
// *
// */
// Message::Id Bot::sendContact(const QVariant& chatId, const QString& phoneNumber, const QString& firstName);
// Message::Id Bot::sendContact(const ParameterList& params);
// /*
// **********************************************************************************************************************
// *
// * sendPoll implementations
// *
// */
// Message::Id Bot::sendPoll(const QVariant& chatId, const QString& question, const QStringList& options);
// Message::Id Bot::sendPoll(const QVariant& chatId, const QString& question, const QStringList& options, bool isAnonymous);
// Message::Id Bot::sendPoll(const ParameterList& params);
// /*
// **********************************************************************************************************************
// *
// * sendDice implementations
// *
// */
// Message::Id Bot::sendDice(const QVariant& chatId, Message::Id replyToMessageId);
// Message::Id Bot::sendDice(const ParameterList& params);
// /*
// **********************************************************************************************************************
// *
// * sendChatAction implementations
// *
// */
// bool Bot::sendChatAction(const QVariant& chatId, Bot::ChatAction action);
// bool Bot::sendChatAction(const ParameterList& params);
// /*
// **********************************************************************************************************************
// *
// * getUserProfilePhotos implementations
// *
// */
// UserProfilePhotos Bot::getUserProfilePhotos(User::Id userId, qint16 offset, qint8 limit);
// UserProfilePhotos Bot::getUserProfilePhotos(ParameterList& params);
// /*
// **********************************************************************************************************************
// *
// * getFile implementations
// *
// */
// File Bot::getFile(const QString& fileId);
// File Bot::getFile(const ParameterList& params);
// /*
// **********************************************************************************************************************
// *
// * banChatMember implementations
// *
// */
// bool Bot::banChatMember(const QVariant& chatId, User::Id userId);
// bool Bot::banChatMember(const ParameterList& params);
// /*
// **********************************************************************************************************************
// *
// * unbanChatMember implementations
// *
// */
// bool Bot::unbanChatMember(const QVariant& chatId, User::Id userId);
// bool Bot::unbanChatMember(const ParameterList& params);
// /*
// **********************************************************************************************************************
// *
// * restrictChatMember implementations
// *
// */
// bool Bot::restrictChatMember(const QVariant& chatId, const QVariant& userId, qint32 untilDate, bool canSendMessages, bool can_send_media_messages,bool can_send_other_messages,bool can_add_web_page_previews);
// bool Bot::restrictChatMember(const ParameterList& params);
// /*
// **********************************************************************************************************************
// *
// * setChatAdministratorCustomTitle implementations
// *
// */
// bool Bot::setChatAdministratorCustomTitle(const QVariant& chatId, User::Id userId,const QString& customTitle);
// bool Bot::setChatAdministratorCustomTitle(const ParameterList& params);
// /*
// **********************************************************************************************************************
// *
// * banChatSenderChat implementations
// *
// */
// bool Bot::banChatSenderChat(const QVariant& chatId,const QVariant& senderChatId);
// bool Bot::banChatSenderChat(const ParameterList& params);
// /*
// **********************************************************************************************************************
// *
// * unbanChatSenderChat implementations
// *
// */
// bool Bot::unbanChatSenderChat(const QVariant& chatId,const QVariant& senderChatId);
// bool Bot::unbanChatSenderChat(const ParameterList& params);
// /*
// **********************************************************************************************************************
// *
// * exportChatInviteLink implementations
// *
// */
// QString Bot::exportChatInviteLink(const QVariant& chatId);
// QString Bot::exportChatInviteLink(const ParameterList& params);
// /*
// **********************************************************************************************************************
// *
// * approveChatJoinRequest implementations
// *
// */
// bool Bot::approveChatJoinRequest(const QVariant& chatId, User::Id userId);
// bool Bot::approveChatJoinRequest(const ParameterList& params);
// /*
// **********************************************************************************************************************
// *
// * declineChatJoinRequest implementations
// *
// */
// bool Bot::declineChatJoinRequest(const QVariant& chatId, User::Id userId);
// bool Bot::declineChatJoinRequest(const ParameterList& params);
// /*
// **********************************************************************************************************************
// *
// * setChatTitle implementations
// *
// */
// bool Bot::setChatTitle(const QVariant& chatId, const QString& title);
// bool Bot::setChatTitle(const ParameterList& params);
// /*
// **********************************************************************************************************************
// *
// * pinChatMessage implementations
// *
// */
// bool Bot::pinChatMessage(const QVariant& chatId,Message::Id messageId);
// bool Bot::pinChatMessage(const ParameterList& params);
// /*
// **********************************************************************************************************************
// *
// * unpinChatMessage implementations
// *
// */
// bool Bot::unpinChatMessage(const QVariant& chatId,Message::Id messageId);
// bool Bot::unpinChatMessage(const ParameterList& params);
// /*
// **********************************************************************************************************************
// *
// * unpinAllChatMessages implementations
// *
// */
// bool Bot::unpinAllChatMessages(const QVariant& chatId);
// bool Bot::unpinAllChatMessages(const ParameterList& params);
// /*
// **********************************************************************************************************************
// *
// * leaveChat implementations
// *
// */
// bool Bot::leaveChat(const QVariant& chatId);
// bool Bot::leaveChat(const ParameterList& params);
// /*
// **********************************************************************************************************************
// *
// * getChat implementations
// *
// */
// Chat Bot::getChat(const QVariant& chatId);
// Chat Bot::getChat(const ParameterList& params);
// /*
// **********************************************************************************************************************
// *
// * getChatAdministrators implementations
// *
// */
// QList<ChatMember> Bot::getChatAdministrators(const QVariant& chatId);
// QList<ChatMember> Bot::getChatAdministrators(const ParameterList& params);
// /*
// **********************************************************************************************************************
// *
// * getChatMemberCount implementations
// *
// */
// int Bot::getChatMemberCount(const QVariant& chatId);
// int Bot::getChatMemberCount(const ParameterList& params);
// /*
// **********************************************************************************************************************
// *
// * getChatMember implementations
// *
// */
// ChatMember Bot::getChatMember(const QVariant& chatId,User::Id userId);
// ChatMember Bot::getChatMember(const ParameterList& params);
// /*
// **********************************************************************************************************************
// *
// * answerCallbackQuery implementations
// *
// */
// bool Bot::answerCallbackQuery(const QString& callbackQueryId,const QString& text,bool showAlert, const QString& url,qint32 cahceTime);
// bool Bot::answerCallbackQuery(const ParameterList& params);
// /*
// **********************************************************************************************************************
// *
// * getMyCommands implementations
// *
// */
// bool Bot::setMyCommands(const BotCommandList& commands);
// bool Bot::setMyCommands(const BotCommandList& commands,const GenericScope& commandScope);
// bool Bot::setMyCommands(const ParameterList& params);
// /*
// **********************************************************************************************************************
// *
// * deleteMyCommands implementations
// *
// */
// bool Bot::deleteMyCommands();
// bool Bot::deleteMyCommands(const GenericScope& commandScope);
// bool Bot::deleteMyCommands(const ParameterList& params);
// /*
// **********************************************************************************************************************
// *
// * getMyCommands implementations
// *
// */
// BotCommandList Bot::getMyCommands();
// BotCommandList Bot::getMyCommands(const GenericScope& commandScope);
// BotCommandList Bot::getMyCommands(const ParameterList& params);
// /*
// **********************************************************************************************************************
// *
// * editMessageText implementations
// *
// */
// bool Bot::editMessageText(const QVariant& chatId,Message::Id messageId,const QString& text);
// bool Bot::editMessageText(const QVariant& chatId,Message::Id messageId,const QString& text, const GenericReply &replyMarkup);
// bool Bot::editMessageText(const ParameterList& params);
// /*
// **********************************************************************************************************************
// *
// * editMessageReplyMarkup implementations
// *
// */
// bool Bot::editMessageReplyMarkup(const QVariant& chatId, Message::Id messageId, const GenericReply& replyMarkup);
// bool Bot::editMessageReplyMarkup(const QString& inlineMessageId, const GenericReply& replyMarkup);
// bool Bot::editMessageReplyMarkup(const ParameterList& params);
// /*
// **********************************************************************************************************************
// *
// * stopPoll implementations
// *
// */
// bool Bot::stopPoll(const QVariant& chatId, Message::Id messageId);
// bool Bot::stopPoll(const QVariant& chatId,int messageId,const GenericReply& replyMarkup);
// bool Bot::stopPoll(const ParameterList& params);
// /*
// **********************************************************************************************************************
// *
// * deleteMessage implementations
// *
// */
// bool Bot::deleteMessage(const QVariant& chatId,Message::Id messageId);
// bool Bot::deleteMessage(const ParameterList& params);
// /*
// **********************************************************************************************************************
// *
// * sendSticker implementations
// *
// */
// Message::Id Bot::sendSticker(const QVariant& chatId, const QString& sticker);
// Message::Id Bot::sendSticker(const ParameterList& params);
// /*
// **********************************************************************************************************************
// *
// * Internal methods
// *
// */
// QJsonObject Bot::sendFilePayload(ParameterList params, QFile *filePayload, const QString& payloadType, const QString& endpoint);
// QJsonObject Bot::sendFilePayload(ParameterList params, const QByteArray& fileData, const QString& payloadType, const QString& endpoint);
/**
* @brief id This method return bots id number.

@ -15,6 +15,10 @@ TelegramMsg::TelegramMsg()
}
TelegramMsg::TelegramMsg(const QJsonObject &obj) {
TelegramMsg::setRawJson(obj);
}
unsigned long long TelegramMsg::messageId() const {
return rawJson()["message_id"].toInteger();
}
@ -43,8 +47,12 @@ QString TelegramMsg::languageCode() const {
return rawJson()["from"]["language_code"].toString();
}
int TelegramMsg::chatId() const {
return rawJson()["chat"]["id"].toInt();
QVariant TelegramMsg::chatId() const {
return rawJson()["chat"]["id"].toVariant();
}
bool TelegramMsg::isValid() const {
return rawJson().contains("message_id");
}
QString TelegramMsg::from() const {
@ -68,7 +76,7 @@ QString TelegramMsg::chatType() const {
}
qint64 TelegramMsg::date() const {
return rawJson()["date"].toVariant().toLongLong();
return rawJson()["date"].toInteger();
}
QString TelegramMsg::text() const {

@ -67,6 +67,8 @@ public:
TelegramMsg();
TelegramMsg(const QJsonObject& obj);
/**
* @brief messageId returns the message ID.
* @return The message ID.
@ -113,7 +115,9 @@ public:
* @brief chatId returns the chat ID.
* @return The chat ID.
*/
int chatId() const;
QVariant chatId() const override;
bool isValid() const override;
QString from() const override;

@ -0,0 +1,94 @@
//#
//# 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 "telegramupdate.h"
namespace qTbot {
TelegramUpdate::TelegramUpdate() {
}
bool TelegramUpdate::contains(const Type &type) {
return rawJson().contains(type);
}
QJsonObject TelegramUpdate::message() const {
return rawJson().value(MessageUpdate).toObject();
}
QJsonObject TelegramUpdate::editedMessage() const {
return rawJson().value(EditedMessageUpdate).toObject();
}
QJsonObject TelegramUpdate::channelPost() const {
return rawJson().value(ChannelPostUpdate).toObject();
}
QJsonObject TelegramUpdate::editedChannelPost() const {
return rawJson().value(EditedChannelPostUpdate).toObject();
}
QJsonObject TelegramUpdate::inlineQueryUpdate() const {
return rawJson().value(InlineQueryUpdate).toObject();
}
QJsonObject TelegramUpdate::chosenInlineResult() const {
return rawJson().value(ChosenInlineResultUpdate).toObject();
}
QJsonObject TelegramUpdate::callbackQueryUpdate() const {
return rawJson().value(CallbackQueryUpdate).toObject();
}
QJsonObject TelegramUpdate::shippingQueryUpdate() const {
return rawJson().value(ShippingQueryUpdate).toObject();
}
QJsonObject TelegramUpdate::preCheckuptAueryUpdate() const {
return rawJson().value(PreCheckuptAueryUpdate).toObject();
}
QJsonObject TelegramUpdate::pollUpdate() const {
return rawJson().value(PollUpdate).toObject();
}
QJsonObject TelegramUpdate::pollAnswerUpdate() const {
return rawJson().value(PollAnswerUpdate).toObject();
}
QJsonObject TelegramUpdate::myChatMemberUpdate() const {
return rawJson().value(MyChatMemberUpdate).toObject();
}
QJsonObject TelegramUpdate::chatMemberUpdate() const {
return rawJson().value(ChatMemberUpdate).toObject();
}
QJsonObject TelegramUpdate::chatJoinRequestUpdate() const {
return rawJson().value(ChatJoinRequestUpdate).toObject();
}
unsigned long long TelegramUpdate::updateId() const {
return rawJson().value("update_id").toInteger();
}
bool TelegramUpdate::isValid() const {
return rawJson().contains("update_id");
}
QString TelegramUpdate::from() const {
return "";
}
QVariant TelegramUpdate::chatId() const {
return "";
}
unsigned long long TelegramUpdate::messageId() const {
return 0;
}
}

@ -0,0 +1,146 @@
//#
//# 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 TELEGRAMUPDATE_H
#define TELEGRAMUPDATE_H
#include "qTbot/messages/itelegrammessage.h"
namespace qTbot {
/**
* @brief The TelegramUpdate class contains base information about updates from telegram
*/
class QTBOT_EXPORT TelegramUpdate: public ITelegramMessage
{
public:
TelegramUpdate();
/**
* @brief Type just string value of the telegram messages types.
*/
using Type = QString;
const Type MessageUpdate = "message";
const Type EditedMessageUpdate = "edited_message";
const Type ChannelPostUpdate = "channel_post";
const Type EditedChannelPostUpdate = "edited_channel_post";
const Type InlineQueryUpdate = "inline_query";
const Type ChosenInlineResultUpdate = "chosen_inline_result";
const Type CallbackQueryUpdate = "callback_query";
const Type ShippingQueryUpdate = "shipping_query";
const Type PreCheckuptAueryUpdate = "pre_checkout_query";
const Type PollUpdate = "poll";
const Type PollAnswerUpdate = "poll_answer";
const Type MyChatMemberUpdate = "my_chat_member";
const Type ChatMemberUpdate = "chat_member";
const Type ChatJoinRequestUpdate = "chat_join_request";
/**
* @brief contains This method returns true if the message contains choosed data type.
* @param type This is name of the type
* @return true if the choosed type is available in this message.
*/
bool contains(const Type& type);
/**
* @brief message returns the array of the updates messages.
* @return list of updates.
*/
QJsonObject message() const;
/**
* @brief editedMessage returns the edited message update.
* @return QJsonObject containing the edited message update.
*/
QJsonObject editedMessage() const;
/**
* @brief channelPost returns the channel post update.
* @return QJsonObject containing the channel post update.
*/
QJsonObject channelPost() const;
/**
* @brief editedChannelPost returns the edited channel post update.
* @return QJsonObject containing the edited channel post update.
*/
QJsonObject editedChannelPost() const;
/**
* @brief inlineQueryUpdate returns the inline query update.
* @return QJsonObject containing the inline query update.
*/
QJsonObject inlineQueryUpdate() const;
/**
* @brief chosenInlineResult returns the chosen inline result update.
* @return QJsonObject containing the chosen inline result update.
*/
QJsonObject chosenInlineResult() const;
/**
* @brief callbackQueryUpdate returns the callback query update.
* @return QJsonObject containing the callback query update.
*/
QJsonObject callbackQueryUpdate() const;
/**
* @brief shippingQueryUpdate returns the shipping query update.
* @return QJsonObject containing the shipping query update.
*/
QJsonObject shippingQueryUpdate() const;
/**
* @brief preCheckuptAueryUpdate returns the pre-checkout query update.
* @return QJsonObject containing the pre-checkout query update.
*/
QJsonObject preCheckuptAueryUpdate() const;
/**
* @brief pollUpdate returns the poll update.
* @return QJsonObject containing the poll update.
*/
QJsonObject pollUpdate() const;
/**
* @brief pollAnswerUpdate returns the poll answer update.
* @return QJsonObject containing the poll answer update.
*/
QJsonObject pollAnswerUpdate() const;
/**
* @brief myChatMemberUpdate returns the my chat member update.
* @return QJsonObject containing the my chat member update.
*/
QJsonObject myChatMemberUpdate() const;
/**
* @brief chatMemberUpdate returns the chat member update.
* @return QJsonObject containing the chat member update.
*/
QJsonObject chatMemberUpdate() const;
/**
* @brief chatJoinRequestUpdate returns the chat join request update.
* @return QJsonObject containing the chat join request update.
*/
QJsonObject chatJoinRequestUpdate() const;
/**
* @brief updateId returns the update ID.
* @return The update ID.
*/
unsigned long long updateId() const;
// iMessage interface
public:
bool isValid() const override;
QString from() const override;
QVariant chatId() const override;
unsigned long long messageId() const override;
};
}
#endif // TELEGRAMUPDATE_H

@ -22,6 +22,10 @@ QString TelegramUpdateAnsver::from() const {
return "";
}
QVariant TelegramUpdateAnsver::chatId() const {
return {};
}
unsigned long long TelegramUpdateAnsver::messageId() const {
return 0;
}

@ -31,6 +31,8 @@ public:
QJsonValue result() const;
QString from() const override;
QVariant chatId() const override;
unsigned long long messageId() const override;
};

@ -1,6 +1,36 @@
#include "telegramsendmsg.h"
//#
//# 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.
//#
TelegramSendMsg::TelegramSendMsg()
#include "telegramsendmsg.h"
namespace qTbot {
TelegramSendMsg::TelegramSendMsg(const QVariant &chatId,
const QString &text,
unsigned long long replyToMessageId,
bool markdown,
bool disableWebPagePreview):
TelegramSingleRquest("sendMessage")
{
QMap<QString, QVariant> args {{"chat_id", chatId}, {"text", text}};
if (replyToMessageId) {
args["reply_to_message_id"] = replyToMessageId;
}
if (markdown) {
args["parse_mode"] = "Markdown";
}
if (disableWebPagePreview) {
args["disable_web_page_preview"] = disableWebPagePreview;
}
setArgs(args);
}
}

@ -1,11 +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 TELEGRAMSENDMSG_H
#define TELEGRAMSENDMSG_H
#include "telegramsinglerquest.h"
namespace qTbot {
class TelegramSendMsg
/**
* @brief The TelegramSendMsg class This method send a message to the server.
*/
class QTBOT_EXPORT TelegramSendMsg: public TelegramSingleRquest
{
public:
TelegramSendMsg();
TelegramSendMsg(const QVariant& chatId,
const QString& text,
unsigned long long replyToMessageId = 0,
bool markdown = true,
bool disableWebPagePreview = false);
};
}
#endif // TELEGRAMSENDMSG_H

@ -35,9 +35,9 @@ QByteArray TelegramSingleRquest::makeUpload() const {
auto it = _args.constBegin();
while (it != _args.constEnd()) {
if (args.isEmpty()) {
args.append(QString("%1=%2").arg((it.key(), it->toString())).toUtf8());
args.append(QString("%0=%1").arg(it.key(), it->toString()).toUtf8());
} else {
args.append(QString("&%1=%2").arg((it.key(), it->toString())).toUtf8());
args.append(QString("&%0=%1").arg(it.key(), it->toString()).toUtf8());
}
++it;
}
@ -46,4 +46,12 @@ QByteArray TelegramSingleRquest::makeUpload() const {
}
const QMap<QString, QVariant>& TelegramSingleRquest::args() const {
return _args;
}
void TelegramSingleRquest::setArgs(const QMap<QString, QVariant> &newArgs) {
_args = newArgs;
}
}

@ -51,6 +51,20 @@ public:
QByteArray makeUpload() const override final;
protected:
/**
* @brief args This method returns a current list of arguments
* @return current list of arguments
*/
const QMap<QString, QVariant> &args() const;
/**
* @brief setArgs For the some requests list of arguments posible to build only after constructor.
* @param newArgs This is new list of arguments.
*/
void setArgs(const QMap<QString, QVariant> &newArgs);
private:
QByteArray _request;
QMap<QString, QVariant> _args;

@ -6,6 +6,7 @@
//#
#include "telegramrestbot.h"
#include "qTbot/messages/telegramupdate.h"
#include "qTbot/messages/telegramupdateansver.h"
#include "qTbot/requests/telegramgetupdate.h"
@ -47,9 +48,10 @@ void TelegramRestBot::startUpdates() {
if (telegramMsg->isValid()) {
auto && resultArray = telegramMsg->result().toArray();
for (const auto& ref: resultArray) {
auto message = IBot::makeMesasge<TelegramMsg>();
message->setRawJson(ref.toObject());
incomeNewMessage(message);
auto update = IBot::makeMesasge<TelegramUpdate>();
update->setRawJson(ref.toObject());
incomeNewMessage(IBot::makeMesasge<TelegramMsg>(update->message()));
}
}
};