Returning message obj where it is needed
This commit is contained in:
		
							parent
							
								
									c674248623
								
							
						
					
					
						commit
						8f0edd25dd
					
				@ -38,8 +38,8 @@ namespace Telegram {
 | 
				
			|||||||
    void addCommand(TCommand);
 | 
					    void addCommand(TCommand);
 | 
				
			||||||
    void setWebhook(std::string);
 | 
					    void setWebhook(std::string);
 | 
				
			||||||
    void processMessage(std::string);
 | 
					    void processMessage(std::string);
 | 
				
			||||||
    void sendMessage(std::string, Json::Int64);
 | 
					    Telegram::Message* sendMessage(std::string, Json::Int64);
 | 
				
			||||||
    void sendMessage(std::string, std::string);
 | 
					    Telegram::Message* sendMessage(std::string, std::string);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    Telegram::Message *sendPhoto(std::string, Json::Int64);
 | 
					    Telegram::Message *sendPhoto(std::string, Json::Int64);
 | 
				
			||||||
    Telegram::Message *sendPhoto(std::string, std::string);
 | 
					    Telegram::Message *sendPhoto(std::string, std::string);
 | 
				
			||||||
@ -55,7 +55,7 @@ namespace Telegram {
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
    void init();
 | 
					    void init();
 | 
				
			||||||
    void apiRequest(std::string, std::map<std::string, std::string>);
 | 
					    void apiRequest(std::string, std::map<std::string, std::string>);
 | 
				
			||||||
    Telegram::Message *apiRequestJson(std::string, std::map<std::string, std::string>);
 | 
					    Json::Value apiRequestJson(std::string, std::map<std::string, std::string>);
 | 
				
			||||||
    std::string processCommand(std::string);
 | 
					    std::string processCommand(std::string);
 | 
				
			||||||
  };
 | 
					  };
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
				
			|||||||
@ -87,21 +87,25 @@ void Telegram::TelegramBot::processMessage(std::string message) {
 | 
				
			|||||||
/**
 | 
					/**
 | 
				
			||||||
 * Send a text message to a user
 | 
					 * Send a text message to a user
 | 
				
			||||||
 */
 | 
					 */
 | 
				
			||||||
void Telegram::TelegramBot::sendMessage(std::string message, Json::Int64 chat_id) {
 | 
					Telegram::Message *Telegram::TelegramBot::sendMessage(std::string message, Json::Int64 chat_id) {
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  this->sendMessage(message, SSTR(chat_id));
 | 
					  return(this->sendMessage(message, SSTR(chat_id)));
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
/**
 | 
					/**
 | 
				
			||||||
 * sendMessage sends a simple text message to a given chat (might be a user or a group)
 | 
					 * sendMessage sends a simple text message to a given chat (might be a user or a group)
 | 
				
			||||||
 */
 | 
					 */
 | 
				
			||||||
void Telegram::TelegramBot::sendMessage(std::string message, std::string chat_id) {
 | 
					Telegram::Message* Telegram::TelegramBot::sendMessage(std::string message, std::string chat_id) {
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  std::map<std::string, std::string> params;
 | 
						std::map<std::string, std::string> params;
 | 
				
			||||||
  params["chat_id"] = chat_id;
 | 
						Json::Value obj;
 | 
				
			||||||
  params["text"] = message;
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
  this->apiRequestJson("sendMessage", params);
 | 
						params["chat_id"] = chat_id;
 | 
				
			||||||
 | 
						params["text"] = message;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						obj = this->apiRequestJson("sendMessage", params);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						return(new Telegram::Message(obj["result"]));
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
/**
 | 
					/**
 | 
				
			||||||
@ -117,12 +121,16 @@ Telegram::Message* Telegram::TelegramBot::sendPhoto(std::string URL, Json::Int64
 | 
				
			|||||||
 */
 | 
					 */
 | 
				
			||||||
Telegram::Message* Telegram::TelegramBot::sendPhoto(std::string URL, std::string chat_id) {
 | 
					Telegram::Message* Telegram::TelegramBot::sendPhoto(std::string URL, std::string chat_id) {
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						Json::Value obj;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	std::map<std::string, std::string> params;
 | 
						std::map<std::string, std::string> params;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	params["chat_id"] = chat_id;
 | 
						params["chat_id"] = chat_id;
 | 
				
			||||||
	params["photo"] = URL;
 | 
						params["photo"] = URL;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	return(this->apiRequestJson("sendPhoto", params));
 | 
						obj = this->apiRequestJson("sendPhoto", params);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						return(new Telegram::Message(obj["result"]));
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
Telegram::Message *Telegram::TelegramBot::getMessage() {
 | 
					Telegram::Message *Telegram::TelegramBot::getMessage() {
 | 
				
			||||||
@ -181,7 +189,7 @@ void Telegram::TelegramBot::apiRequest(std::string method, std::map<std::string,
 | 
				
			|||||||
/**
 | 
					/**
 | 
				
			||||||
 * An API request, posting JSON data
 | 
					 * An API request, posting JSON data
 | 
				
			||||||
 */
 | 
					 */
 | 
				
			||||||
Telegram::Message* Telegram::TelegramBot::apiRequestJson(std::string method, std::map<std::string, std::string> parameters) {
 | 
					Json::Value Telegram::TelegramBot::apiRequestJson(std::string method, std::map<std::string, std::string> parameters) {
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	std::stringstream result; // Stores the result of the api call
 | 
						std::stringstream result; // Stores the result of the api call
 | 
				
			||||||
	parameters["method"] = method;
 | 
						parameters["method"] = method;
 | 
				
			||||||
@ -214,7 +222,7 @@ Telegram::Message* Telegram::TelegramBot::apiRequestJson(std::string method, std
 | 
				
			|||||||
	Json::Value obj;
 | 
						Json::Value obj;
 | 
				
			||||||
	jreader.parse(result.str(), obj);
 | 
						jreader.parse(result.str(), obj);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	return (new Telegram::Message(obj["result"]));
 | 
						return (obj);
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
std::string Telegram::TelegramBot::processCommand(std::string cmd) {
 | 
					std::string Telegram::TelegramBot::processCommand(std::string cmd) {
 | 
				
			||||||
 | 
				
			|||||||
		Loading…
	
		Reference in New Issue
	
	Block a user