Create main slack channel after registering to Slack
This commit is contained in:
parent
9d2692c5d2
commit
384d4bfcd0
4 changed files with 47 additions and 9 deletions
|
@ -123,7 +123,7 @@ std::string SlackFrontend::getOAuth2URL(const std::vector<std::string> &args) {
|
|||
}
|
||||
|
||||
std::string SlackFrontend::getRegistrationFields() {
|
||||
return "Slack team name\n3rd-party network username\n3rd-party network password";
|
||||
return "Main Slack channel\n3rd-party network username\n3rd-party network password";
|
||||
}
|
||||
|
||||
bool SlackFrontend::handleAdminMessage(Swift::Message::ref message) {
|
||||
|
|
|
@ -215,6 +215,40 @@ void SlackSession::handleJoinMessage(const std::string &message, std::vector<std
|
|||
m_api->channelsList(boost::bind(&SlackSession::handleJoinRoomList, this, _1, _2, _3, _4, args));
|
||||
}
|
||||
|
||||
void SlackSession::handleSlackChannelCreate(HTTPRequest *req, bool ok, rapidjson::Document &resp, const std::string &data) {
|
||||
std::string channelId = m_api->getChannelId(req, ok, resp, data);
|
||||
if (channelId.empty()) {
|
||||
LOG4CXX_INFO(logger,"Error creating channel " << m_slackChannel << ".");
|
||||
return;
|
||||
}
|
||||
|
||||
m_slackChannel = channelId;
|
||||
Swift::Presence::ref presence = Swift::Presence::create();
|
||||
presence->setFrom(Swift::JID("", m_uinfo.jid, "default"));
|
||||
presence->setTo(m_component->getJID());
|
||||
presence->setType(Swift::Presence::Available);
|
||||
presence->addPayload(boost::shared_ptr<Swift::Payload>(new Swift::MUCPayload()));
|
||||
m_component->getFrontend()->onPresenceReceived(presence);
|
||||
}
|
||||
|
||||
void SlackSession::handleSlackChannelList(HTTPRequest *req, bool ok, rapidjson::Document &resp, const std::string &data) {
|
||||
std::map<std::string, SlackChannelInfo> channels;
|
||||
SlackAPI::getSlackChannelInfo(req, ok, resp, data, channels);
|
||||
|
||||
if (channels.find(m_slackChannel) != channels.end()) {
|
||||
m_slackChannel = channels[m_slackChannel].id;
|
||||
Swift::Presence::ref presence = Swift::Presence::create();
|
||||
presence->setFrom(Swift::JID("", m_uinfo.jid, "default"));
|
||||
presence->setTo(m_component->getJID());
|
||||
presence->setType(Swift::Presence::Available);
|
||||
presence->addPayload(boost::shared_ptr<Swift::Payload>(new Swift::MUCPayload()));
|
||||
m_component->getFrontend()->onPresenceReceived(presence);
|
||||
}
|
||||
else {
|
||||
m_api->channelsCreate(m_slackChannel, boost::bind(&SlackSession::handleSlackChannelCreate, this, _1, _2, _3, _4));
|
||||
}
|
||||
}
|
||||
|
||||
void SlackSession::handleLeaveMessage(const std::string &message, std::vector<std::string> &args, bool quiet) {
|
||||
// .spectrum2 leave.room channel
|
||||
std::string slackChannel = SlackAPI::SlackObjectToPlainText(args[2], true);
|
||||
|
@ -452,12 +486,7 @@ void SlackSession::handleImOpen(HTTPRequest *req, bool ok, rapidjson::Document &
|
|||
else {
|
||||
m_storageBackend->getUserSetting(m_uinfo.id, "slack_channel", type, m_slackChannel);
|
||||
if (!m_slackChannel.empty()) {
|
||||
Swift::Presence::ref presence = Swift::Presence::create();
|
||||
presence->setFrom(Swift::JID("", m_uinfo.jid, "default"));
|
||||
presence->setTo(m_component->getJID());
|
||||
presence->setType(Swift::Presence::Available);
|
||||
presence->addPayload(boost::shared_ptr<Swift::Payload>(new Swift::MUCPayload()));
|
||||
m_component->getFrontend()->onPresenceReceived(presence);
|
||||
m_api->channelsList(boost::bind(&SlackSession::handleSlackChannelList, this, _1, _2, _3, _4));
|
||||
}
|
||||
else {
|
||||
std::string msg;
|
||||
|
|
|
@ -73,6 +73,9 @@ class SlackSession {
|
|||
void handleJoinRoomCreate(HTTPRequest *req, bool ok, rapidjson::Document &resp, const std::string &data, std::vector<std::string> args);
|
||||
void handleJoinRoomList(HTTPRequest *req, bool ok, rapidjson::Document &resp, const std::string &data, std::vector<std::string> args);
|
||||
|
||||
void handleSlackChannelCreate(HTTPRequest *req, bool ok, rapidjson::Document &resp, const std::string &data);
|
||||
void handleSlackChannelList(HTTPRequest *req, bool ok, rapidjson::Document &resp, const std::string &data);
|
||||
|
||||
void sendOnlineBuddies();
|
||||
|
||||
private:
|
||||
|
|
|
@ -112,6 +112,8 @@ std::string SlackUserRegistration::handleOAuth2Code(const std::string &code, con
|
|||
std::string token;
|
||||
std::string access_token;
|
||||
std::vector<std::string> data;
|
||||
std::string value;
|
||||
int type = (int) TYPE_STRING;
|
||||
|
||||
if (state == "use_bot_token") {
|
||||
token = code;
|
||||
|
@ -148,6 +150,7 @@ std::string SlackUserRegistration::handleOAuth2Code(const std::string &code, con
|
|||
user.id = 0;
|
||||
m_storageBackend->getUser(domain, user);
|
||||
|
||||
value = user.jid;
|
||||
user.jid = domain;
|
||||
user.language = "en";
|
||||
user.encoding = "";
|
||||
|
@ -157,8 +160,11 @@ std::string SlackUserRegistration::handleOAuth2Code(const std::string &code, con
|
|||
|
||||
m_storageBackend->getUser(user.jid, user);
|
||||
|
||||
std::string value = token;
|
||||
int type = (int) TYPE_STRING;
|
||||
if (!value.empty()) {
|
||||
m_storageBackend->getUserSetting(user.id, "slack_channel", type, value);
|
||||
}
|
||||
|
||||
value = token;
|
||||
m_storageBackend->getUserSetting(user.id, "bot_token", type, value);
|
||||
|
||||
value = access_token;
|
||||
|
|
Loading…
Add table
Reference in a new issue