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

The IBot class Base interface for all chat-bots objcts. More...

#include <ibot.h>

Classes

struct  RequestData
 The RequestData class is simple wrapper of request object with path of responce. If Path of responce is empty then responce will saved in RAM. More...
 

Public Types

enum  FileType { Ram , Local }
 The FileType enum is is file types, deffine how we should download a file - as a local object in file system or into virtual memory. More...
 

Signals

void sigReceiveUpdate (const QSharedPointer< iUpdate > &)
 sigReceiveUpdate emit when but receive any updates from users.
 
void sigStopRequire ()
 sigStopRequire just custm event for stop bot if tou use services.
 

Public Member Functions

 IBot ()
 
 ~IBot ()
 
virtual bool login (const QByteArray &token)=0
 login This method get bae information of the bot from remote server.
 
virtual void logout ()
 login This method remove login token of bot.
 
virtual bool sendMessage (const QVariant &chatId, const QString &text, iRequest::RequestPriority priority=iRequest::NormalPriority)=0
 sendMessage This method sents text to the selected chat.
 
virtual bool deleteMessage (const QVariant &chatId, const QVariant &messageId)=0
 deleteMessage This is main method to delete messages.
 
virtual QFuture< QByteArraygetFile (const QString &fileId, FileType fileType=Ram)=0
 Get a file by its ID.
 
virtual bool sendFile (const QFileInfo &file, const QVariant &chatId)=0
 send file .
 
virtual bool sendFile (const QByteArray &file, const QString &fileName, const QVariant &chatId)=0
 sendFile This method setns a file that saved as a bytearray.
 
const QByteArraytoken () const
 token This is token value for authication on the remote server (bot)
 
const QStringname () const
 name This is name of the bot. usualy it fields will be received from the server after autication.
 
void setName (const QString &newName)
 setName This method sets new value for the IBot::name field.
 
QSharedPointer< iUpdatetakeNextUnreadUpdate ()
 takeNextUnreadUpdate This method take a unread update and mark them as read.
 
QSet< unsigned long longprocessed () const
 processed This method return list of processed mesages.
 
virtual void setProcessed (const QSet< unsigned long long > &newProcessed)
 setProcessed This method sets new list of processed mesages.
 
int reqestLimitPerSecond () const
 reqestLimitPerSecond this is request performence limitation. by default is 20 requests per second
 
void setReqestLimitPerSecond (int newReqestLimitPerSecond)
 setReqestLimitPerSecond this method sets new limitation of bot performance.
 
int parallelActiveNetworkThreads () const
 parallelActiveNetworkThreads
 
void setParallelActiveNetworkThreads (int newParallelActiveNetworkThreads)
 setParallelActiveNetworkThreads
 
unsigned long long totalSentRequests () const
 totalSentRequests This is total prepared requests count of bot from the start.
 
QDateTime startTime () const
 startTime this is time when bol wil started.
 

Protected Member Functions

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

Static Protected Member Functions

template<class MessageType , class ... Args>
static QSharedPointer< MessageType > makeMesasge (const QByteArray &data, Args &&...args)
 makeMesasge This is factory method tha can create a messages types.
 
template<class MessageType , class ... Args>
static QSharedPointer< MessageType > makeMesasge (const QJsonObject &data, Args &&...args)
 makeMesasge This is factory method tha can create a messages types.
 

Detailed Description

The IBot class Base interface for all chat-bots objcts.

Definition at line 34 of file ibot.h.

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

Member Enumeration Documentation

◆ FileType

The FileType enum is is file types, deffine how we should download a file - as a local object in file system or into virtual memory.

Enumerator
Ram 

The Ram is a Virtual type of download files will save all file data into QFuture bytes array.

Local 

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

Definition at line 44 of file ibot.h.

Constructor & Destructor Documentation

◆ IBot()

qTbot::IBot::IBot ( )

Definition at line 17 of file ibot.cpp.

◆ ~IBot()

qTbot::IBot::~IBot ( )

Definition at line 26 of file ibot.cpp.

Member Function Documentation

◆ defaultFileStorageLocation()

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

defaultFileStorageLocation This method return default file storage location.

Returns
default file storage.

Definition at line 170 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 main method to delete messages.

Parameters
chatIdThis is cahat id wher will be removed message.
messageIdThis is removed message id.
Returns
true if request was be prepared successful

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 emit the sigReceiveUpdate signal.

Note
you may override this method for filter the sigReceiveUpdate signal or for handling new updates.

Reimplemented in qTbot::ITelegramBot.

Definition at line 174 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 save incomed messages into store.

Definition at line 44 of file ibot.cpp.

Here is the call graph for this function:

◆ login()

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

login This method get bae information of the bot from remote server.

Parameters
tokenThis is token value for login
Returns
true if login request sent successful else false.

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

◆ logout()

void qTbot::IBot::logout ( )
virtual

login This method remove login token of bot.

Reimplemented in qTbot::TelegramRestBot.

Definition at line 30 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>
static QSharedPointer< MessageType > qTbot::IBot::makeMesasge ( const QByteArray &  data,
Args &&...  args 
)
inlinestaticprotected

makeMesasge This is factory method tha can create a messages types.

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

Definition at line 216 of file ibot.h.

Here is the caller graph for this function:

◆ makeMesasge() [2/2]

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

makeMesasge This is factory method tha can create a messages types.

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

Definition at line 230 of file ibot.h.

◆ makeUrl()

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

makeUrl This method prepare a prefix url for http requests.

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

Implemented in qTbot::ITelegramBot.

◆ markUpdateAsProcessed()

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

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

Parameters
messageThis is message that need to be processed.

Definition at line 158 of file ibot.cpp.

◆ markUpdateAsUnprocessed() [1/2]

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

markMessageAsUnprocessed This method add the message into a not processed messages store.

Parameters
messageThis is message that need to be unprocessed.
Note
this may be useful for the process edited old messages. Just call this method bofore IBot::incomeNewMessage.

Definition at line 162 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 add the message into a not processed messages store.

Parameters
messageThis is message that need to be unprocessed.
Note
this may be useful for the process edited old messages. Just call this method bofore IBot::incomeNewMessage.

Definition at line 166 of file ibot.cpp.

◆ name()

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

name This is name of the bot. usualy it fields will be received from the server after autication.

Returns
name if the bot.

Definition at line 295 of file ibot.cpp.

◆ parallelActiveNetworkThreads()

int qTbot::IBot::parallelActiveNetworkThreads ( ) const

parallelActiveNetworkThreads

Returns

Definition at line 109 of file ibot.cpp.

◆ processed()

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

processed This method return list of processed mesages.

Returns
list of processed messages.

Definition at line 287 of file ibot.cpp.

◆ reqestLimitPerSecond()

int qTbot::IBot::reqestLimitPerSecond ( ) const

reqestLimitPerSecond this is request performence limitation. by default is 20 requests per second

Returns

Definition at line 122 of file ibot.cpp.

◆ sendFile() [1/2]

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

sendFile This method setns a file that saved as a bytearray.

Parameters
fileThis is file source.
fileNameThis is name of file.
chatIdThis is chat of the receivers.
Returns
true if the file will sent successful.

Implemented in qTbot::ITelegramBot.

◆ sendFile() [2/2]

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

send file .

Parameters
fileThis is a file that you want to send.
chatIdid of the chat.
Returns
Returns true if the file sents successful.

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 sents text to the selected chat.

Parameters
chatIdThis is selected chat id
textThis is text that neet to sent.
Returns
true if data sents successful 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 sent custom requests to the server.

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

Definition at line 131 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 sent custom requests to the server.

Parameters
rquestThis is message that will be sent to server.
Returns
future pointer to the request replay.
Note
This is same as a default implementaion execpt save data location, this method will create new file that located pathToResult and save all received data to this location.

Definition at line 145 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 299 of file ibot.cpp.

◆ setParallelActiveNetworkThreads()

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

setParallelActiveNetworkThreads

Parameters
newParallelActiveNetworkThreads

Definition at line 113 of file ibot.cpp.

◆ setProcessed()

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

setProcessed This method sets new list of processed mesages.

Parameters
newProcessedlist of processed messagees.

Reimplemented in qTbot::TelegramRestBot.

Definition at line 291 of file ibot.cpp.

Here is the caller graph for this function:

◆ setReqestLimitPerSecond()

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

setReqestLimitPerSecond this method sets new limitation of bot performance.

Parameters
newReqestLimitPerSecondthis is a new value of performance.

Definition at line 126 of file ibot.cpp.

Here is the caller graph for this function:

◆ setToken()

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

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

Parameters
newTokenThis is new value of the token.

Definition at line 38 of file ibot.cpp.

Here is the caller graph for this function:

◆ sigReceiveUpdate

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

sigReceiveUpdate emit when but receive any updates from users.

Here is the caller graph for this function:

◆ sigStopRequire

void qTbot::IBot::sigStopRequire ( )
signal

sigStopRequire just custm event for stop bot if tou use services.

◆ startTime()

QDateTime qTbot::IBot::startTime ( ) const

startTime this is time when bol wil started.

Returns

Definition at line 101 of file ibot.cpp.

◆ takeNextUnreadUpdate()

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

takeNextUnreadUpdate This method take a unread update and mark them as read.

Returns
unread message object. If all messages is readed the return nullptr.

Definition at line 303 of file ibot.cpp.

Here is the caller graph for this function:

◆ token()

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

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

Returns
auth toke of the bot.

Definition at line 34 of file ibot.cpp.

Here is the caller graph for this function:

◆ totalSentRequests()

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

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

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

Definition at line 105 of file ibot.cpp.


The documentation for this class was generated from the following files: