Changeset - f823618439d9
[Not reviewed]
0 2 0
Jan Kaluza - 10 years ago 2015-12-08 17:58:56
jkaluza@redhat.com
Slack: Support me_message and bot_message
2 files changed with 40 insertions and 2 deletions:
0 comments (0 inline, 0 general)
spectrum/src/frontends/slack/SlackAPI.cpp
Show inline comments
 
@@ -58,6 +58,18 @@ DEFINE_LOGGER(logger, "SlackAPI");
 
	} \
 
	bool NAME = NAME##_tmp.GetBool();
 

	
 
#define GET_OBJECT(FROM, NAME) rapidjson::Value &NAME = FROM[#NAME]; \
 
	if (!NAME.IsObject()) { \
 
		LOG4CXX_ERROR(logger, "No '" << #NAME << "' object in the reply."); \
 
		return; \
 
	}
 

	
 
#define STORE_STRING_OPTIONAL(FROM, NAME) rapidjson::Value &NAME##_tmp = FROM[#NAME]; \
 
	std::string NAME; \
 
	if (NAME##_tmp.IsString()) {  \
 
		 NAME = NAME##_tmp.GetString(); \
 
	}
 

	
 
SlackAPI::SlackAPI(Component *component, const std::string &token) : HTTPRequestQueue(component) {
 
	m_component = component;
 
	m_token = token;
 
@@ -272,6 +284,13 @@ void SlackAPI::getSlackUserInfo(HTTPRequest *req, bool ok, rapidjson::Document &
 

	
 
		ret[info.id] = info;
 
		LOG4CXX_INFO(logger, info.id << " " << info.name);
 

	
 
		GET_OBJECT(users[i], profile);
 
		STORE_STRING_OPTIONAL(profile, bot_id);
 
		if (!bot_id.empty()) {
 
			ret[bot_id] = info;
 
			LOG4CXX_INFO(logger, bot_id << " " << info.name);
 
		}
 
	}
 

	
 
	return;
spectrum/src/frontends/slack/SlackRTM.cpp
Show inline comments
 
@@ -75,6 +75,12 @@ SlackRTM::~SlackRTM() {
 
	} \
 
	std::string NAME = NAME##_tmp.GetString();
 

	
 
#define STORE_STRING_OPTIONAL(FROM, NAME) rapidjson::Value &NAME##_tmp = FROM[#NAME]; \
 
	std::string NAME; \
 
	if (NAME##_tmp.IsString()) {  \
 
		 NAME = NAME##_tmp.GetString(); \
 
	}
 

	
 
void SlackRTM::handlePayloadReceived(const std::string &payload) {
 
	rapidjson::Document d;
 
	if (d.Parse<0>(payload.c_str()).HasParseError()) {
 
@@ -87,10 +93,23 @@ void SlackRTM::handlePayloadReceived(const std::string &payload) {
 

	
 
	if (type == "message") {
 
		STORE_STRING(d, channel);
 
		STORE_STRING(d, user);
 
		STORE_STRING(d, text);
 
		STORE_STRING(d, ts);
 
		onMessageReceived(channel, user, text, ts);
 
		STORE_STRING_OPTIONAL(d, subtype);
 

	
 
		if (subtype == "bot_message") {
 
			STORE_STRING(d, bot_id);
 
			onMessageReceived(channel, bot_id, text, ts);
 
		}
 
		else if (subtype == "me_message") {
 
			text = "/me " + text;
 
			STORE_STRING(d, user);
 
			onMessageReceived(channel, user, text, ts);
 
		}
 
		else {
 
			STORE_STRING(d, user);
 
			onMessageReceived(channel, user, text, ts);
 
		}
 
	}
 
}
 

	
0 comments (0 inline, 0 general)