LibTgBotPP
 All Classes Namespaces Files Functions Variables Typedefs Macros
Telegram::TelegramBot Class Reference

#include <TelegramBot.h>

Public Member Functions

 TelegramBot ()
 
 TelegramBot (std::string)
 
void addCommand (TCommand)
 
void setWebhook (std::string)
 
void processMessage (std::string)
 
Telegram::UsergetMe (void)
 
Telegram::MessagesendMessage (std::string, Json::Int64)
 
Telegram::MessagesendMessage (std::string, std::string)
 
Telegram::MessagesendPhoto (std::string, Json::Int64)
 
Telegram::MessagesendPhoto (std::string, std::string)
 
Telegram::MessagegetMessage ()
 
std::map< std::string, TCommandgetCommandMap ()
 

Private Member Functions

void init ()
 
void apiRequest (std::string, std::map< std::string, std::string >)
 
Json::Value apiRequestJson (std::string, std::map< std::string, std::string >)
 
Json::Value apiRequestFile (std::string, std::string, std::string)
 
std::string processCommand (std::string)
 

Private Attributes

std::string api_url
 
Telegram::Messagemsg
 
TCommandMap command_map
 
Json::Int64 chat_id
 

Detailed Description

Definition at line 33 of file TelegramBot.h.

Constructor & Destructor Documentation

Telegram::TelegramBot::TelegramBot ( )

Constructor of Bot

Calls init

Definition at line 24 of file TelegramBot.cc.

Telegram::TelegramBot::TelegramBot ( std::string  token)

Constructor of bot

Sets the API URL and calls init

Parameters
tokena std::string storing the bot token

Definition at line 38 of file TelegramBot.cc.

Member Function Documentation

void Telegram::TelegramBot::addCommand ( TCommand  cmd)

Adds a callback to the command list of the bot

Parameters
cmda structure of type TCommand

Definition at line 49 of file TelegramBot.cc.

void Telegram::TelegramBot::apiRequest ( std::string  method,
std::map< std::string, std::string >  parameters 
)
private

A generic API request

Might be removed in future!

Parameters
methodmight be sendPhoto, sendMessage or any command defined by Telegram's API
parametersa map of further parameters, needed by the API call

Definition at line 216 of file TelegramBot.cc.

Json::Value Telegram::TelegramBot::apiRequestFile ( std::string  filename,
std::string  type,
std::string  chat_id 
)
private

Sending a file by InputFile object

Parameters
filenamea valid file name
typemay be photo, document, video
chat_ida valid chat id (might be a user or a group chat)
Returns
result Json::Value

Definition at line 305 of file TelegramBot.cc.

Json::Value Telegram::TelegramBot::apiRequestJson ( std::string  method,
std::map< std::string, std::string >  parameters 
)
private

An API request, posting JSON data

Parameters
methodmight be "sendPhoto", "sendMessage" or anything else, defined by the Telegram API
parametersfurther parameters to the API call (e.g. the text of a message)
Returns
the JSON structure, sent back by Telegram's API

Definition at line 258 of file TelegramBot.cc.

Telegram::TCommandMap Telegram::TelegramBot::getCommandMap ( )

getCommandMap return the complete command list of the bot

Returns
Map of the commands

Definition at line 192 of file TelegramBot.cc.

Telegram::User * Telegram::TelegramBot::getMe ( void  )

A simple command to the API to get some information about the bot.

Returns
Telegram::User* a pointer of an object of type Telegram::User

Definition at line 97 of file TelegramBot.cc.

Telegram::Message * Telegram::TelegramBot::getMessage ( )

Definition at line 182 of file TelegramBot.cc.

void Telegram::TelegramBot::init ( void  )
private

inits the bot. That is only sending a content-type to stdout in case one uses the bot by an CGI script

Definition at line 203 of file TelegramBot.cc.

std::string Telegram::TelegramBot::processCommand ( std::string  cmd)
private

processCommand gets a command by the user (e.g. /start) and processes the command. The command should be added to the command list by addCommand before, otherwise "Unknwon command" is returned

Parameters
cmdthe command, defined in the command list (e.g. /start)
Returns
the output of the command

Definition at line 352 of file TelegramBot.cc.

void Telegram::TelegramBot::processMessage ( std::string  message)

Process incoming message

Parameters
messagea std::string storing the message sent by the Telegram system

Definition at line 79 of file TelegramBot.cc.

Telegram::Message * Telegram::TelegramBot::sendMessage ( std::string  message,
Json::Int64  chat_id 
)

Send a text message to a user or group

Parameters
messageThe text of the message
chat_idthe chat id
Returns
A pointer to a Telegram message object

Definition at line 115 of file TelegramBot.cc.

Telegram::Message * Telegram::TelegramBot::sendMessage ( std::string  message,
std::string  chat_id 
)

sendMessage sends a simple text message to a given chat (might be a user or a group)

Parameters
messageThe text of the message
chat_idthe chat id
Returns
A pointer to a Telegram message object

Definition at line 128 of file TelegramBot.cc.

Telegram::Message * Telegram::TelegramBot::sendPhoto ( std::string  URL,
Json::Int64  chat_id 
)

Sends a picture from the internet to a chat

Parameters
URLThe URL of the picture
chat_idthe chat id
Returns
A pointer to a Telegram message object

Definition at line 149 of file TelegramBot.cc.

Telegram::Message * Telegram::TelegramBot::sendPhoto ( std::string  URL,
std::string  chat_id 
)

Sends a picture from the internet to a chat

Parameters
URLThe URL of the picture
chat_idthe chat id
Returns
A pointer to a Telegram message object

Definition at line 162 of file TelegramBot.cc.

void Telegram::TelegramBot::setWebhook ( std::string  url)

Set the webhook The web hook URL is like https://<your domain>="">/cgi-bin/mybot.cgi A web hook must be set before you can get any messages from the Telegram network!

Parameters
urla std::string with the URL of the hook

Definition at line 65 of file TelegramBot.cc.

Member Data Documentation

std::string Telegram::TelegramBot::api_url
private

Definition at line 55 of file TelegramBot.h.

Json::Int64 Telegram::TelegramBot::chat_id
private

Definition at line 58 of file TelegramBot.h.

TCommandMap Telegram::TelegramBot::command_map
private

Definition at line 57 of file TelegramBot.h.

Telegram::Message* Telegram::TelegramBot::msg
private

Definition at line 56 of file TelegramBot.h.


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