Slack: support for attachments message type
This commit is contained in:
parent
f823618439
commit
cf2ba10533
2 changed files with 37 additions and 0 deletions
|
@ -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;
|
||||
}
|
||||
|
||||
|
|
|
@ -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);
|
||||
|
|
Loading…
Add table
Reference in a new issue