23#include <QNetworkReply>
25#include <QSharedPointer>
46 virtual bool login(
const QByteArray& token) = 0;
51 virtual void logout();
61 virtual bool sendMessage(
const QVariant& chatId,
const QString& text) = 0;
69 virtual bool deleteMessage(
const QVariant& chatId,
const QVariant& messageId) = 0;
80 virtual QSharedPointer<iFile>
getFile(
const QString& fileId,
iFile::Type fileType = iFile::Type::Ram) = 0;
89 virtual bool sendFile(
const QFileInfo& file,
const QVariant& chatId) = 0;
98 virtual bool sendFile(
const QByteArray& file,
const QString& fileName,
const QVariant& chatId) = 0;
104 const QByteArray &token()
const;
110 const QString& name()
const;
116 void setName(
const QString &newName);
122 QSharedPointer<iUpdate> takeNextUnreadUpdate();
128 QSet<unsigned long long> processed()
const;
134 virtual void setProcessed(
const QSet<unsigned long long> &newProcessed);
144 template<
class MessageType,
class ... Args>
145 static QSharedPointer<MessageType>
makeMesasge(
const QByteArray& data, Args&& ...args) {
146 auto&& ptr = QSharedPointer<MessageType>(
new MessageType(std::forward<Args>(args)...));
147 ptr->setRawData(data);
158 template<
class MessageType,
class ... Args>
159 static QSharedPointer<MessageType>
makeMesasge(
const QJsonObject& data, Args&& ...args) {
160 auto&& ptr = QSharedPointer<MessageType>(
new MessageType(std::forward<Args>(args)...));
161 ptr->setRawJson(data);
172 virtual QString
makeUrl(
const QSharedPointer<iRequest>& request)
const = 0;
180 QSharedPointer<QNetworkReply>
181 sendRequest(
const QSharedPointer<iRequest>& rquest);
187 void setToken(
const QByteArray &newToken);
192 void incomeNewUpdate(
const QSharedPointer<iUpdate>& message);
198 void markUpdateAsProcessed(
const QSharedPointer<iUpdate>& message);
205 void markUpdateAsUnprocessed(
const QSharedPointer<iUpdate>& message);
212 void markUpdateAsUnprocessed(
unsigned long long messageID);
218 virtual QString defaultFileStorageLocation()
const;
224 virtual void handleIncomeNewUpdate(
const QSharedPointer<iUpdate>& );
237 void doRemoveFinishedRequests();
241 QMap<unsigned long long, QSharedPointer<iUpdate>> _notProcessedUpdates;
242 QSet<unsigned long long> _processed;
243 QNetworkAccessManager *_manager =
nullptr;
245 QMap<size_t,QSharedPointer<QNetworkReply>> _replayStorage;
246 QList<size_t> _toRemove;
The IBot class Base interface for all chat-bots objcts.
virtual QString makeUrl(const QSharedPointer< iRequest > &request) const =0
makeUrl This method prepare a prefix url for http requests.
static QSharedPointer< MessageType > makeMesasge(const QByteArray &data, Args &&...args)
makeMesasge This is factory method tha can create a messages types.
void sigStopRequire()
sigStopRequire just custm event for stop bot if tou use services.
virtual bool sendFile(const QByteArray &file, const QString &fileName, const QVariant &chatId)=0
sendFile This method setns a file that saved as a bytearray.
virtual bool sendFile(const QFileInfo &file, const QVariant &chatId)=0
send file .
virtual bool deleteMessage(const QVariant &chatId, const QVariant &messageId)=0
deleteMessage This is main method to delete messages.
virtual bool login(const QByteArray &token)=0
login This method get bae information of the bot from remote server.
virtual QSharedPointer< iFile > getFile(const QString &fileId, iFile::Type fileType=iFile::Type::Ram)=0
Get a file by its ID.
void sigReceiveUpdate(const QSharedPointer< iUpdate > &)
sigReceiveUpdate emit when but receive any updates from users.
virtual bool sendMessage(const QVariant &chatId, const QString &text)=0
sendMessage This method sents text to the selected chat.
static QSharedPointer< MessageType > makeMesasge(const QJsonObject &data, Args &&...args)
makeMesasge This is factory method tha can create a messages types.
Type
The Type enum is type of the file object.