Changeset - cf2ba1053384
[Not reviewed]
0 2 0
Jan Kaluza - 10 years ago 2015-12-08 18:33:50
jkaluza@redhat.com
Slack: support for attachments message type
2 files changed with 37 insertions and 0 deletions:
0 comments (0 inline, 0 general)
spectrum/src/frontends/slack/SlackAPI.cpp
Show inline comments
 
@@ -293,6 +293,27 @@ void SlackAPI::getSlackUserInfo(HTTPRequest *req, bool ok, rapidjson::Document &
 
		}
 
	}
 

	
 
	GET_ARRAY(resp, bots);
 

	
 
	for (int i = 0; i < bots.Size(); i++) {
 
		if (!bots[i].IsObject()) {
 
			continue;
 
		}
 

	
 
		SlackUserInfo info;
 

	
 
		STORE_STRING(users[i], id);
 
		info.id = id;
 

	
 
		STORE_STRING(users[i], name);
 
		info.name = name;
 

	
 
		info.isPrimaryOwner = 0;
 

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

	
 
	return;
 
}
 

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

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

	
 
void SlackRTM::handlePayloadReceived(const std::string &payload) {
 
	rapidjson::Document d;
 
	if (d.Parse<0>(payload.c_str()).HasParseError()) {
 
@@ -97,6 +103,16 @@ void SlackRTM::handlePayloadReceived(const std::string &payload) {
 
		STORE_STRING(d, ts);
 
		STORE_STRING_OPTIONAL(d, subtype);
 

	
 
		rapidjson::Value &attachments = d["attachments"];
 
		if (attachments.IsArray()) {
 
			for (int i = 0; i < attachments.Size(); i++) {
 
				STORE_STRING_OPTIONAL(attachments[i], fallback);
 
				if (!fallback.empty()) {
 
					text += fallback;
 
				}
 
			}
 
		}
 

	
 
		if (subtype == "bot_message") {
 
			STORE_STRING(d, bot_id);
 
			onMessageReceived(channel, bot_id, text, ts);
0 comments (0 inline, 0 general)