qTbot 0.2.123.6f57966
qTbot is base back end library for your c++ Qt projects.
qTbot::IBot Class Referenceabstract

The IBot class Base interface for all chat-bot objects. More...

#include <ibot.h>

Inheritance diagram for qTbot::IBot:
Inheritance graph
Collaboration diagram for qTbot::IBot:
Collaboration graph

Classes

struct  RequestData
 The RequestData class is a simple wrapper of a request object with the path of the response. If the path of the response is empty, then the response will be saved in RAM. More...

Public Types

enum  FileType { Ram , Local }
 The FileType enum is a list of file types. It defines how a file should be downloaded - as a local object in the file system or into virtual memory. More...

Signals

void sigReceiveUpdate (const QSharedPointer< qTbot::iUpdate > &)
 sigReceiveUpdate emitted when the bot receives any updates from users.
void sigStopRequire ()
 sigStopRequire just a custom event to stop the bot if you use services.

Public Member Functions

 IBot ()
 IBot default constructor. Initializes the network access manager and the request executor.
 ~IBot ()
 ~IBot destructor. Cancels pending requests and frees all network resources.
virtual bool login (const QByteArray &token)=0
 login This method gets basic information of the bot from the remote server.
virtual void logout ()
 logout This method removes the login token of the bot.
virtual bool sendMessage (const QVariant &chatId, const QString &text, iRequest::RequestPriority priority=iRequest::NormalPriority)=0
 sendMessage This method sends text to the selected chat.
virtual bool deleteMessage (const QVariant &chatId, const QVariant &messageId)=0
 deleteMessage This is the main method to delete messages.
virtual QFuture< QByteArray > getFile (const QString &fileId, FileType fileType=Ram)=0
 Get a file by its ID.
virtual bool sendFile (const QFileInfo &file, const QVariant &chatId)=0
 sendFile This method sends the selected file to the chat.
virtual bool sendFile (const QByteArray &file, const QString &fileName, const QVariant &chatId)=0
 sendFile This method sends a file that is saved as a byte array.
const QByteArray & token () const
 token This is the token value for authentication on the remote server (bot).
const QString & name () const
 name This is the name of the bot. Usually this field is received from the server after authentication.
void setName (const QString &newName)
 setName This method sets new value for the IBot::name field.
QSharedPointer< iUpdate > takeNextUnreadUpdate ()
 takeNextUnreadUpdate This method takes an unread update and marks it as read.
QSet< unsigned long long > processed () const
 processed This method returns the list of processed messages.
virtual void setProcessed (const QSet< unsigned long long > &newProcessed)
 setProcessed This method sets a new list of processed messages.
int reqestLimitPerSecond () const
 reqestLimitPerSecond This is the request performance limitation. By default it is 20 requests per second.
void setReqestLimitPerSecond (int newReqestLimitPerSecond)
 setReqestLimitPerSecond This method sets a new limitation of the bot performance.
int parallelActiveNetworkThreads () const
 parallelActiveNetworkThreads This method returns the number of parallel active network threads.
void setParallelActiveNetworkThreads (int newParallelActiveNetworkThreads)
 setParallelActiveNetworkThreads This method sets the number of parallel active network threads.
unsigned long long totalSentRequests () const
 totalSentRequests This is the total count of prepared requests of the bot from the start.
QDateTime startTime () const
 startTime This is the time when the bot was started.

Protected Member Functions

virtual QString makeUrl (const QSharedPointer< iRequest > &request) const =0
 makeUrl This method prepares a prefix url for http requests.
QFuture< QByteArray > sendRequest (const QSharedPointer< iRequest > &rquest)
 sendRequest This method sends a custom request to the server.
QFuture< QByteArray > sendRequest (const QSharedPointer< iRequest > &rquest, const QString &pathToResult)
 sendRequest This method sends a custom request to the server.
void setToken (const QByteArray &newToken)
 setToken This is the setter of the IBot::token value.
void incomeNewUpdate (const QSharedPointer< iUpdate > &message)
 incomeNewUpdate This method saves incoming messages into the store.
void markUpdateAsProcessed (const QSharedPointer< iUpdate > &message)
 markMessageAsProcessed This method removes the message from the not processed messages store.
void markUpdateAsUnprocessed (const QSharedPointer< iUpdate > &message)
 markMessageAsUnprocessed This method adds the message into the not processed messages store.
void markUpdateAsUnprocessed (unsigned long long messageID)
 markMessageAsUnprocessed This method adds the message into the not processed messages store.
virtual QString defaultFileStorageLocation () const
 defaultFileStorageLocation This method returns the default file storage location.
virtual void handleIncomeNewUpdate (const QSharedPointer< iUpdate > &)
 handleIncomeNewUpdate This method just emits the sigReceiveUpdate signal.

Static Protected Member Functions

template<class MessageType, class ... Args>
static QSharedPointer< MessageType > makeMesasge (const QByteArray &data, Args &&...args)
 makeMesasge This is a factory method that can create a message type from raw byte data.
template<class MessageType, class ... Args>
static QSharedPointer< MessageType > makeMesasge (const QJsonObject &data, Args &&...args)
 makeMesasge This is a factory method that can create a message type from raw json data.

Detailed Description

The IBot class Base interface for all chat-bot objects.

Definition at line 34 of file ibot.h.

Member Enumeration Documentation

◆ FileType

The FileType enum is a list of file types. It defines how a file should be downloaded - as a local object in the file system or into virtual memory.

Enumerator
Ram 

Ram virtual file type. All file data will be saved into a QFuture bytes array.

Local 

Local file type. The file will be saved in the internal file storage. This file type can use the file system as a cache and will download a file with the same id only one time.

Definition at line 51 of file ibot.h.

Constructor & Destructor Documentation

◆ IBot()

qTbot::IBot::IBot ( )

IBot default constructor. Initializes the network access manager and the request executor.

Definition at line 17 of file ibot.cpp.

◆ ~IBot()

qTbot::IBot::~IBot ( )

~IBot destructor. Cancels pending requests and frees all network resources.

Definition at line 28 of file ibot.cpp.

Member Function Documentation

◆ defaultFileStorageLocation()

QString qTbot::IBot::defaultFileStorageLocation ( ) const
protectedvirtual

defaultFileStorageLocation This method returns the default file storage location.

Returns
default file storage.

Definition at line 203 of file ibot.cpp.

Here is the caller graph for this function:

◆ deleteMessage()

virtual bool qTbot::IBot::deleteMessage ( const QVariant & chatId,
const QVariant & messageId )
pure virtual

deleteMessage This is the main method to delete messages.

Parameters
chatIdThis is the chat id where the message will be removed.
messageIdThis is the removed message id.
Returns
true if the request was prepared successfully

Implemented in qTbot::ITelegramBot.

◆ getFile()

virtual QFuture< QByteArray > qTbot::IBot::getFile ( const QString & fileId,
FileType fileType = Ram )
pure virtual

Get a file by its ID.

This function allows you to retrieve a file by its ID.

Parameters
fileIdThe ID of the file to retrieve.
fileTypeThis is a saving way, by Default will be used a FileType::Ram
Returns
Returns true if the file retrieval operation was successfully initiated and false in case of an error.

Implemented in qTbot::ITelegramBot.

◆ handleIncomeNewUpdate()

void qTbot::IBot::handleIncomeNewUpdate ( const QSharedPointer< iUpdate > & message)
protectedvirtual

handleIncomeNewUpdate This method just emits the sigReceiveUpdate signal.

Note
you may override this method to filter the sigReceiveUpdate signal or to handle new updates.

Reimplemented in qTbot::ITelegramBot.

Definition at line 207 of file ibot.cpp.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ incomeNewUpdate()

void qTbot::IBot::incomeNewUpdate ( const QSharedPointer< iUpdate > & message)
protected

incomeNewUpdate This method saves incoming messages into the store.

Parameters
messageThis is the new incoming update.

Definition at line 46 of file ibot.cpp.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ login()

virtual bool qTbot::IBot::login ( const QByteArray & token)
pure virtual

login This method gets basic information of the bot from the remote server.

Parameters
tokenThis is the token value for login
Returns
true if the login request was sent successfully else false.

Implemented in qTbot::ITelegramBot, and qTbot::TelegramRestBot.

Here is the call graph for this function:

◆ logout()

void qTbot::IBot::logout ( )
virtual

logout This method removes the login token of the bot.

Reimplemented in qTbot::TelegramRestBot.

Definition at line 32 of file ibot.cpp.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ makeMesasge() [1/2]

template<class MessageType, class ... Args>
QSharedPointer< MessageType > qTbot::IBot::makeMesasge ( const QByteArray & data,
Args &&... args )
inlinestaticprotected

makeMesasge This is a factory method that can create a message type from raw byte data.

Parameters
dataThis is a raw data of the answer.
argsThis is the list of arguments of the message.
Returns
message object.

Definition at line 228 of file ibot.h.

◆ makeMesasge() [2/2]

template<class MessageType, class ... Args>
QSharedPointer< MessageType > qTbot::IBot::makeMesasge ( const QJsonObject & data,
Args &&... args )
inlinestaticprotected

makeMesasge This is a factory method that can create a message type from raw json data.

Parameters
dataThis is a raw json data of the answer.
argsThis is the list of arguments of the message.
Returns
message object.

Definition at line 242 of file ibot.h.

◆ makeUrl()

virtual QString qTbot::IBot::makeUrl ( const QSharedPointer< iRequest > & request) const
protectedpure virtual

makeUrl This method prepares a prefix url for http requests.

Parameters
request- This is the request object for which the url will be prepared.
Returns
http request prefix

Implemented in qTbot::ITelegramBot.

Here is the call graph for this function:

◆ markUpdateAsProcessed()

void qTbot::IBot::markUpdateAsProcessed ( const QSharedPointer< iUpdate > & message)
protected

markMessageAsProcessed This method removes the message from the not processed messages store.

Parameters
messageThis is the message that needs to be processed.

Definition at line 191 of file ibot.cpp.

Here is the caller graph for this function:

◆ markUpdateAsUnprocessed() [1/2]

void qTbot::IBot::markUpdateAsUnprocessed ( const QSharedPointer< iUpdate > & message)
protected

markMessageAsUnprocessed This method adds the message into the not processed messages store.

Parameters
messageThis is the message that needs to be unprocessed.
Note
this may be useful for processing edited old messages. Just call this method before IBot::incomeNewUpdate.

Definition at line 195 of file ibot.cpp.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ markUpdateAsUnprocessed() [2/2]

void qTbot::IBot::markUpdateAsUnprocessed ( unsigned long long messageID)
protected

markMessageAsUnprocessed This method adds the message into the not processed messages store.

Parameters
messageIDThis is the id of the message that needs to be unprocessed.
Note
this may be useful for processing edited old messages. Just call this method before IBot::incomeNewUpdate.

Definition at line 199 of file ibot.cpp.

◆ name()

const QString & qTbot::IBot::name ( ) const

name This is the name of the bot. Usually this field is received from the server after authentication.

Returns
name of the bot.

Definition at line 339 of file ibot.cpp.

Here is the caller graph for this function:

◆ parallelActiveNetworkThreads()

int qTbot::IBot::parallelActiveNetworkThreads ( ) const

parallelActiveNetworkThreads This method returns the number of parallel active network threads.

Returns
the number of parallel active network threads.

Definition at line 111 of file ibot.cpp.

Here is the caller graph for this function:

◆ processed()

QSet< unsigned long long > qTbot::IBot::processed ( ) const

processed This method returns the list of processed messages.

Returns
list of processed messages.

Definition at line 331 of file ibot.cpp.

Here is the caller graph for this function:

◆ reqestLimitPerSecond()

int qTbot::IBot::reqestLimitPerSecond ( ) const

reqestLimitPerSecond This is the request performance limitation. By default it is 20 requests per second.

Returns
the maximum number of requests per second.

Definition at line 140 of file ibot.cpp.

Here is the caller graph for this function:

◆ sendFile() [1/2]

virtual bool qTbot::IBot::sendFile ( const QByteArray & file,
const QString & fileName,
const QVariant & chatId )
pure virtual

sendFile This method sends a file that is saved as a byte array.

Parameters
fileThis is the file source data.
fileNameThis is the name of the file.
chatIdThis is the chat of the receiver.
Returns
true if the file is sent successfully.

Implemented in qTbot::ITelegramBot.

Here is the call graph for this function:

◆ sendFile() [2/2]

virtual bool qTbot::IBot::sendFile ( const QFileInfo & file,
const QVariant & chatId )
pure virtual

sendFile This method sends the selected file to the chat.

Parameters
fileThis is a file that you want to send.
chatIdid of the chat.
Returns
Returns true if the file was sent successfully.

Implemented in qTbot::ITelegramBot.

◆ sendMessage()

virtual bool qTbot::IBot::sendMessage ( const QVariant & chatId,
const QString & text,
iRequest::RequestPriority priority = iRequest::NormalPriority )
pure virtual

sendMessage This method sends text to the selected chat.

Parameters
chatIdThis is the selected chat id
textThis is the text that needs to be sent.
priorityThis is the priority of the request in the send queue.
Returns
true if the data was sent successfully else false.
Note
the specific implementations of this interface can have a different method for sending.

Implemented in qTbot::ITelegramBot.

◆ sendRequest() [1/2]

QFuture< QByteArray > qTbot::IBot::sendRequest ( const QSharedPointer< iRequest > & rquest)
protected

sendRequest This method sends a custom request to the server.

Parameters
rquestThis is the message that will be sent to the server.
Returns
future pointer to the request replay.

Definition at line 149 of file ibot.cpp.

Here is the caller graph for this function:

◆ sendRequest() [2/2]

QFuture< QByteArray > qTbot::IBot::sendRequest ( const QSharedPointer< iRequest > & rquest,
const QString & pathToResult )
protected

sendRequest This method sends a custom request to the server.

Parameters
rquestThis is the message that will be sent to the server.
pathToResultThis is the path to the file where the received data will be saved.
Returns
future pointer to the request replay.
Note
This is the same as the default implementation except for the save data location, this method will create a new file located at pathToResult and save all received data to this location.

Definition at line 169 of file ibot.cpp.

◆ setName()

void qTbot::IBot::setName ( const QString & newName)

setName This method sets new value for the IBot::name field.

Parameters
newNameThis is new value of the IBot::name property

Definition at line 343 of file ibot.cpp.

Here is the caller graph for this function:

◆ setParallelActiveNetworkThreads()

void qTbot::IBot::setParallelActiveNetworkThreads ( int newParallelActiveNetworkThreads)

setParallelActiveNetworkThreads This method sets the number of parallel active network threads.

Parameters
newParallelActiveNetworkThreadsThis is the new number of parallel active network threads.

Definition at line 115 of file ibot.cpp.

Here is the caller graph for this function:

◆ setProcessed()

void qTbot::IBot::setProcessed ( const QSet< unsigned long long > & newProcessed)
virtual

setProcessed This method sets a new list of processed messages.

Parameters
newProcessedlist of processed messages.

Reimplemented in qTbot::TelegramRestBot.

Definition at line 335 of file ibot.cpp.

Here is the caller graph for this function:

◆ setReqestLimitPerSecond()

void qTbot::IBot::setReqestLimitPerSecond ( int newReqestLimitPerSecond)

setReqestLimitPerSecond This method sets a new limitation of the bot performance.

Parameters
newReqestLimitPerSecondThis is the new value of the performance limitation.

Definition at line 144 of file ibot.cpp.

Here is the caller graph for this function:

◆ setToken()

void qTbot::IBot::setToken ( const QByteArray & newToken)
protected

setToken This is the setter of the IBot::token value.

Parameters
newTokenThis is the new value of the token.

Definition at line 40 of file ibot.cpp.

Here is the caller graph for this function:

◆ sigReceiveUpdate

void qTbot::IBot::sigReceiveUpdate ( const QSharedPointer< qTbot::iUpdate > & )
signal

sigReceiveUpdate emitted when the bot receives any updates from users.

Here is the caller graph for this function:

◆ sigStopRequire

void qTbot::IBot::sigStopRequire ( )
signal

sigStopRequire just a custom event to stop the bot if you use services.

◆ startTime()

QDateTime qTbot::IBot::startTime ( ) const

startTime This is the time when the bot was started.

Returns
the start date time of the bot.

Definition at line 103 of file ibot.cpp.

Here is the caller graph for this function:

◆ takeNextUnreadUpdate()

QSharedPointer< iUpdate > qTbot::IBot::takeNextUnreadUpdate ( )

takeNextUnreadUpdate This method takes an unread update and marks it as read.

Returns
unread update object. If all updates are read the return nullptr.

Definition at line 347 of file ibot.cpp.

Here is the caller graph for this function:

◆ token()

const QByteArray & qTbot::IBot::token ( ) const

token This is the token value for authentication on the remote server (bot).

Returns
auth token of the bot.

Definition at line 36 of file ibot.cpp.

Here is the caller graph for this function:

◆ totalSentRequests()

unsigned long long qTbot::IBot::totalSentRequests ( ) const

totalSentRequests This is the total count of prepared requests of the bot from the start.

See also
startTime method to get the start date time.
Returns
requests count.

Definition at line 107 of file ibot.cpp.

Here is the caller graph for this function:

The documentation for this class was generated from the following files:
  • src/qTbot/src/public/qTbot/ibot.h
  • src/qTbot/src/public/qTbot/ibot.cpp