Rename DiscourseChat to DiscourseChatIntegration (#82)

This commit is contained in:
Mark VanLandingham
2021-07-13 14:36:16 -05:00
committed by GitHub
parent c0bd802f78
commit a73f5da114
64 changed files with 482 additions and 482 deletions
+23 -23
View File
@@ -1,14 +1,14 @@
# frozen_string_literal: true
class DiscourseChat::ChatController < ApplicationController
requires_plugin DiscourseChat::PLUGIN_NAME
class DiscourseChatIntegration::ChatController < ApplicationController
requires_plugin DiscourseChatIntegration::PLUGIN_NAME
def respond
render
end
def list_providers
providers = ::DiscourseChat::Provider.enabled_providers.map do |x|
providers = ::DiscourseChatIntegration::Provider.enabled_providers.map do |x|
{
name: x::PROVIDER_NAME,
id: x::PROVIDER_NAME,
@@ -24,11 +24,11 @@ class DiscourseChat::ChatController < ApplicationController
channel_id = params[:channel_id].to_i
topic_id = params[:topic_id].to_i
channel = DiscourseChat::Channel.find(channel_id)
channel = DiscourseChatIntegration::Channel.find(channel_id)
provider = ::DiscourseChat::Provider.get_by_name(channel.provider)
provider = ::DiscourseChatIntegration::Provider.get_by_name(channel.provider)
if !DiscourseChat::Provider.is_enabled(provider)
if !DiscourseChatIntegration::Provider.is_enabled(provider)
raise Discourse::NotFound
end
@@ -39,7 +39,7 @@ class DiscourseChat::ChatController < ApplicationController
render json: success_json
rescue Discourse::InvalidParameters, ActiveRecord::RecordNotFound => e
render json: { errors: [e.message] }, status: 422
rescue DiscourseChat::ProviderError => e
rescue DiscourseChatIntegration::ProviderError => e
Rails.logger.error("Test provider failed #{e.info}")
if e.info.key?(:error_key) && !e.info[:error_key].nil?
render json: { error_key: e.info[:error_key] }, status: 422
@@ -50,18 +50,18 @@ class DiscourseChat::ChatController < ApplicationController
end
def list_channels
providers = ::DiscourseChat::Provider.enabled_provider_names
providers = ::DiscourseChatIntegration::Provider.enabled_provider_names
requested_provider = params[:provider]
raise Discourse::InvalidParameters if !providers.include?(requested_provider)
channels = DiscourseChat::Channel.with_provider(requested_provider)
render_serialized channels, DiscourseChat::ChannelSerializer, root: 'channels'
channels = DiscourseChatIntegration::Channel.with_provider(requested_provider)
render_serialized channels, DiscourseChatIntegration::ChannelSerializer, root: 'channels'
end
def create_channel
begin
providers = ::DiscourseChat::Provider.enabled_providers.map { |x| x::PROVIDER_NAME }
providers = ::DiscourseChatIntegration::Provider.enabled_providers.map { |x| x::PROVIDER_NAME }
if !defined?(params[:channel]) && defined?(params[:channel][:provider])
raise Discourse::InvalidParameters, 'Provider is not valid'
@@ -73,17 +73,17 @@ class DiscourseChat::ChatController < ApplicationController
raise Discourse::InvalidParameters, 'Provider is not valid'
end
allowed_keys = DiscourseChat::Provider.get_by_name(requested_provider)::CHANNEL_PARAMETERS.map { |p| p[:key].to_sym }
allowed_keys = DiscourseChatIntegration::Provider.get_by_name(requested_provider)::CHANNEL_PARAMETERS.map { |p| p[:key].to_sym }
hash = params.require(:channel).permit(:provider, data: allowed_keys)
channel = DiscourseChat::Channel.new(hash)
channel = DiscourseChatIntegration::Channel.new(hash)
if !channel.save
raise Discourse::InvalidParameters, 'Channel is not valid'
end
render_serialized channel, DiscourseChat::ChannelSerializer, root: 'channel'
render_serialized channel, DiscourseChatIntegration::ChannelSerializer, root: 'channel'
rescue Discourse::InvalidParameters => e
render json: { errors: [e.message] }, status: 422
end
@@ -91,10 +91,10 @@ class DiscourseChat::ChatController < ApplicationController
def update_channel
begin
channel = DiscourseChat::Channel.find(params[:id].to_i)
channel = DiscourseChatIntegration::Channel.find(params[:id].to_i)
channel.error_key = nil # Reset any error on the rule
allowed_keys = DiscourseChat::Provider.get_by_name(channel.provider)::CHANNEL_PARAMETERS.map { |p| p[:key].to_sym }
allowed_keys = DiscourseChatIntegration::Provider.get_by_name(channel.provider)::CHANNEL_PARAMETERS.map { |p| p[:key].to_sym }
hash = params.require(:channel).permit(data: allowed_keys)
@@ -102,14 +102,14 @@ class DiscourseChat::ChatController < ApplicationController
raise Discourse::InvalidParameters, 'Channel is not valid'
end
render_serialized channel, DiscourseChat::ChannelSerializer, root: 'channel'
render_serialized channel, DiscourseChatIntegration::ChannelSerializer, root: 'channel'
rescue Discourse::InvalidParameters => e
render json: { errors: [e.message] }, status: 422
end
end
def destroy_channel
rule = DiscourseChat::Channel.find_by(id: params[:id])
rule = DiscourseChatIntegration::Channel.find_by(id: params[:id])
raise Discourse::InvalidParameters unless rule
rule.destroy!
@@ -119,13 +119,13 @@ class DiscourseChat::ChatController < ApplicationController
def create_rule
begin
hash = params.require(:rule).permit(:channel_id, :type, :filter, :group_id, :category_id, tags: [])
rule = DiscourseChat::Rule.new(hash)
rule = DiscourseChatIntegration::Rule.new(hash)
if !rule.save
raise Discourse::InvalidParameters, 'Rule is not valid'
end
render_serialized rule, DiscourseChat::RuleSerializer, root: 'rule'
render_serialized rule, DiscourseChatIntegration::RuleSerializer, root: 'rule'
rescue Discourse::InvalidParameters => e
render json: { errors: [e.message] }, status: 422
end
@@ -133,21 +133,21 @@ class DiscourseChat::ChatController < ApplicationController
def update_rule
begin
rule = DiscourseChat::Rule.find(params[:id].to_i)
rule = DiscourseChatIntegration::Rule.find(params[:id].to_i)
hash = params.require(:rule).permit(:type, :filter, :group_id, :category_id, tags: [])
if !rule.update(hash)
raise Discourse::InvalidParameters, 'Rule is not valid'
end
render_serialized rule, DiscourseChat::RuleSerializer, root: 'rule'
render_serialized rule, DiscourseChatIntegration::RuleSerializer, root: 'rule'
rescue Discourse::InvalidParameters => e
render json: { errors: [e.message] }, status: 422
end
end
def destroy_rule
rule = DiscourseChat::Rule.find_by(id: params[:id])
rule = DiscourseChatIntegration::Rule.find_by(id: params[:id])
raise Discourse::InvalidParameters.new unless rule
rule.destroy!
+2 -2
View File
@@ -1,7 +1,7 @@
# frozen_string_literal: true
class DiscourseChat::PublicController < ApplicationController
requires_plugin DiscourseChat::PLUGIN_NAME
class DiscourseChatIntegration::PublicController < ApplicationController
requires_plugin DiscourseChatIntegration::PLUGIN_NAME
def post_transcript
params.require(:secret)
+6 -6
View File
@@ -1,10 +1,10 @@
# frozen_string_literal: true
module DiscourseChat
module DiscourseChatIntegration
module Helper
def self.process_command(channel, tokens)
guardian = DiscourseChat::Manager.guardian
guardian = DiscourseChatIntegration::Manager.guardian
provider = channel.provider
@@ -47,7 +47,7 @@ module DiscourseChat
end
category_id = category.nil? ? nil : category.id
case DiscourseChat::Helper.smart_create_rule(channel: channel, filter: cmd, category_id: category_id, tags: tags)
case DiscourseChatIntegration::Helper.smart_create_rule(channel: channel, filter: cmd, category_id: category_id, tags: tags)
when :created
I18n.t("chat_integration.provider.#{provider}.create.created")
when :updated
@@ -61,13 +61,13 @@ module DiscourseChat
rule_number = tokens[0].to_i
return error_text unless rule_number.to_s == tokens[0] # Check we were given a number
if DiscourseChat::Helper.delete_by_index(channel, rule_number)
if DiscourseChatIntegration::Helper.delete_by_index(channel, rule_number)
I18n.t("chat_integration.provider.#{provider}.delete.success")
else
I18n.t("chat_integration.provider.#{provider}.delete.error")
end
when "status"
DiscourseChat::Helper.status_for_channel(channel)
DiscourseChatIntegration::Helper.status_for_channel(channel)
when "help"
I18n.t("chat_integration.provider.#{provider}.help")
else
@@ -144,7 +144,7 @@ module DiscourseChat
# :created if a new rule has been created
# false if there was an error
def self.smart_create_rule(channel:, filter:, category_id: nil, tags: nil)
existing_rules = DiscourseChat::Rule.with_channel(channel).with_type('normal')
existing_rules = DiscourseChatIntegration::Rule.with_channel(channel).with_type('normal')
# Select the ones that have the same category
same_category = existing_rules.select { |rule| rule.category_id == category_id }
@@ -1,20 +1,20 @@
# frozen_string_literal: true
module ::DiscourseChat
module ::DiscourseChatIntegration
PLUGIN_NAME = "discourse-chat-integration".freeze
class AdminEngine < ::Rails::Engine
engine_name "#{DiscourseChat::PLUGIN_NAME}-admin"
isolate_namespace DiscourseChat
engine_name "#{::DiscourseChatIntegration::PLUGIN_NAME}-admin"
isolate_namespace ::DiscourseChatIntegration
end
class PublicEngine < ::Rails::Engine
engine_name "#{DiscourseChat::PLUGIN_NAME}-public"
isolate_namespace DiscourseChat
engine_name "#{::DiscourseChatIntegration::PLUGIN_NAME}-public"
isolate_namespace ::DiscourseChatIntegration
end
def self.plugin_name
DiscourseChat::PLUGIN_NAME
::DiscourseChatIntegration::PLUGIN_NAME
end
def self.pstore_get(key)
@@ -40,7 +40,7 @@ require_relative "../serializers/rule_serializer"
require_relative "../controllers/chat_controller"
require_relative "../controllers/public_controller"
require_relative "../routes/discourse_chat"
require_relative "../routes/discourse_chat_integration"
require_relative "../routes/discourse"
require_relative "../helpers/helper"
@@ -49,7 +49,7 @@ require_relative "../services/manager"
require_relative "../jobs/regular/notify_chats"
require_relative "../../lib/discourse_chat/provider"
require_relative "../../lib/discourse_chat_integration/provider"
require_relative "../jobs/onceoff/add_type_field"
require_relative "../jobs/onceoff/migrate_from_slack_official"
+1 -1
View File
@@ -3,7 +3,7 @@
module Jobs
class DiscourseChatAddTypeField < ::Jobs::Onceoff
def execute_onceoff(args)
DiscourseChat::Rule.find_each do |rule|
DiscourseChatIntegration::Rule.find_each do |rule|
rule.save(validate: false)
end
end
@@ -6,7 +6,7 @@ module Jobs
slack_installed = PluginStoreRow.where(plugin_name: 'discourse-slack-official').exists?
if slack_installed
already_setup_rules = DiscourseChat::Channel.with_provider('slack').exists?
already_setup_rules = DiscourseChatIntegration::Channel.with_provider('slack').exists?
already_setup_sitesettings =
SiteSetting.chat_integration_slack_enabled ||
@@ -65,9 +65,9 @@ module Jobs
rows.each do |row|
# Load an existing channel with this identifier. If none, create it
row[:channel] = "##{row[:channel]}" unless row[:channel].start_with?("#")
channel = DiscourseChat::Channel.with_provider('slack').with_data_value('identifier', row[:channel]).first
channel = DiscourseChatIntegration::Channel.with_provider('slack').with_data_value('identifier', row[:channel]).first
if !channel
channel = DiscourseChat::Channel.create(provider: 'slack', data: { identifier: row[:channel] })
channel = DiscourseChatIntegration::Channel.create(provider: 'slack', data: { identifier: row[:channel] })
if !channel.id
Rails.logger.warn("Error creating channel for #{row}")
next
@@ -75,7 +75,7 @@ module Jobs
end
# Create the rule, with clever logic for avoiding duplicates
success = DiscourseChat::Helper.smart_create_rule(channel: channel, filter: row[:filter], category_id: row[:category_id], tags: row[:tags])
success = DiscourseChatIntegration::Helper.smart_create_rule(channel: channel, filter: row[:filter], category_id: row[:category_id], tags: row[:tags])
end
end
+1 -1
View File
@@ -6,7 +6,7 @@ module Jobs
def execute(args)
return if !SiteSetting.chat_integration_enabled?
::DiscourseChat::Manager.trigger_notifications(args[:post_id])
::DiscourseChatIntegration::Manager.trigger_notifications(args[:post_id])
end
end
end
+6 -6
View File
@@ -1,6 +1,6 @@
# frozen_string_literal: true
class DiscourseChat::Channel < DiscourseChat::PluginModel
class DiscourseChatIntegration::Channel < DiscourseChatIntegration::PluginModel
# Setup ActiveRecord::Store to use the JSON field to read/write these values
store :value, accessors: [ :provider, :error_key, :error_info, :data ], coder: JSON
@@ -17,7 +17,7 @@ class DiscourseChat::Channel < DiscourseChat::PluginModel
end
def rules
DiscourseChat::Rule.with_channel_id(id).order_by_precedence
DiscourseChatIntegration::Rule.with_channel_id(id).order_by_precedence
end
private
@@ -31,16 +31,16 @@ class DiscourseChat::Channel < DiscourseChat::PluginModel
end
def provider_valid?
if !DiscourseChat::Provider.provider_names.include?(provider)
if !DiscourseChatIntegration::Provider.provider_names.include?(provider)
errors.add(:provider, "#{provider} is not a valid provider")
end
end
def data_valid?
# If provider is invalid, don't try and check data
return unless ::DiscourseChat::Provider.provider_names.include? provider
return unless ::DiscourseChatIntegration::Provider.provider_names.include? provider
params = ::DiscourseChat::Provider.get_by_name(provider)::CHANNEL_PARAMETERS
params = ::DiscourseChatIntegration::Provider.get_by_name(provider)::CHANNEL_PARAMETERS
unless params.map { |p| p[:key] }.sort == data.keys.sort
errors.add(:data, "data does not match the required structure for provider #{provider}")
@@ -48,7 +48,7 @@ class DiscourseChat::Channel < DiscourseChat::PluginModel
end
check_unique = false
matching_channels = DiscourseChat::Channel.with_provider(provider).where.not(id: id)
matching_channels = DiscourseChatIntegration::Channel.with_provider(provider).where.not(id: id)
data.each do |key, value|
regex_string = params.find { |p| p[:key] == key }[:regex]
+1 -1
View File
@@ -1,6 +1,6 @@
# frozen_string_literal: true
class DiscourseChat::PluginModel < PluginStoreRow
class DiscourseChatIntegration::PluginModel < PluginStoreRow
PLUGIN_NAME = 'discourse-chat-integration'
default_scope { self.default_scope }
+3 -3
View File
@@ -1,6 +1,6 @@
# frozen_string_literal: true
class DiscourseChat::Rule < DiscourseChat::PluginModel
class DiscourseChatIntegration::Rule < DiscourseChatIntegration::PluginModel
# Setup ActiveRecord::Store to use the JSON field to read/write these values
store :value, accessors: [ :channel_id, :type, :group_id, :category_id, :tags, :filter ], coder: JSON
@@ -75,7 +75,7 @@ class DiscourseChat::Rule < DiscourseChat::PluginModel
# Mock foreign key
# Could return nil
def channel
DiscourseChat::Channel.find_by(id: channel_id)
DiscourseChatIntegration::Channel.find_by(id: channel_id)
end
def channel=(val)
@@ -85,7 +85,7 @@ class DiscourseChat::Rule < DiscourseChat::PluginModel
private
def channel_valid?
if !(DiscourseChat::Channel.where(id: channel_id).exists?)
if !(DiscourseChatIntegration::Channel.where(id: channel_id).exists?)
errors.add(:channel_id, "#{channel_id} is not a valid channel id")
end
end
+4 -4
View File
@@ -1,10 +1,10 @@
# frozen_string_literal: true
Discourse::Application.routes.append do
mount ::DiscourseChat::AdminEngine, at: '/admin/plugins/chat', constraints: AdminConstraint.new
mount ::DiscourseChat::PublicEngine, at: '/chat-transcript/', as: 'chat-transcript'
mount ::DiscourseChat::Provider::HookEngine, at: '/chat-integration/'
mount ::DiscourseChatIntegration::AdminEngine, at: '/admin/plugins/chat', constraints: AdminConstraint.new
mount ::DiscourseChatIntegration::PublicEngine, at: '/chat-transcript/', as: 'chat-transcript'
mount ::DiscourseChatIntegration::Provider::HookEngine, at: '/chat-integration/'
# For backwards compatibility with Slack plugin
post "/slack/command" => "discourse_chat/provider/slack_provider/slack_command#command"
post "/slack/command" => "discourse_chat_integration/provider/slack_provider/slack_command#command"
end
@@ -2,7 +2,7 @@
require_dependency 'admin_constraint'
module DiscourseChat
module ::DiscourseChatIntegration
AdminEngine.routes.draw do
get "" => "chat#respond"
get '/providers' => "chat#list_providers"
+2 -2
View File
@@ -2,12 +2,12 @@
require_relative './rule_serializer'
class DiscourseChat::ChannelSerializer < ApplicationSerializer
class DiscourseChatIntegration::ChannelSerializer < ApplicationSerializer
attributes :id, :provider, :error_key, :error_info, :data, :rules
def rules
object.rules.order_by_precedence.map do |rule|
DiscourseChat::RuleSerializer.new(rule, root: false)
DiscourseChatIntegration::RuleSerializer.new(rule, root: false)
end
end
end
+1 -1
View File
@@ -1,6 +1,6 @@
# frozen_string_literal: true
class DiscourseChat::RuleSerializer < ApplicationSerializer
class DiscourseChatIntegration::RuleSerializer < ApplicationSerializer
attributes :id, :channel_id, :type, :group_id, :group_name, :category_id, :tags, :filter
def group_name
+9 -9
View File
@@ -1,6 +1,6 @@
# frozen_string_literal: true
module DiscourseChat
module DiscourseChatIntegration
module Manager
def self.guardian
@@ -23,11 +23,11 @@ module DiscourseChat
if topic.archetype == Archetype.private_message
group_ids_with_access = topic.topic_allowed_groups.pluck(:group_id)
return if group_ids_with_access.empty?
matching_rules = DiscourseChat::Rule.with_type('group_message').with_group_ids(group_ids_with_access)
matching_rules = DiscourseChatIntegration::Rule.with_type('group_message').with_group_ids(group_ids_with_access)
else
matching_rules = DiscourseChat::Rule.with_type('normal').with_category_id(topic.category_id)
matching_rules = DiscourseChatIntegration::Rule.with_type('normal').with_category_id(topic.category_id)
if topic.category # Also load the rules for the wildcard category
matching_rules += DiscourseChat::Rule.with_type('normal').with_category_id(nil)
matching_rules += DiscourseChatIntegration::Rule.with_type('normal').with_category_id(nil)
end
# If groups are mentioned, check for any matching rules and append them
@@ -35,7 +35,7 @@ module DiscourseChat
if mentions && mentions.length > 0
groups = Group.where('LOWER(name) IN (?)', mentions)
if groups.exists?
matching_rules += DiscourseChat::Rule.with_type('group_mention').with_group_ids(groups.map(&:id))
matching_rules += DiscourseChatIntegration::Rule.with_type('group_mention').with_group_ids(groups.map(&:id))
end
end
end
@@ -76,14 +76,14 @@ module DiscourseChat
matching_rules.each do |rule|
# If there are any issues, skip to the next rule
next unless channel = rule.channel
next unless provider = ::DiscourseChat::Provider.get_by_name(channel.provider)
next unless is_enabled = ::DiscourseChat::Provider.is_enabled(provider)
next unless provider = ::DiscourseChatIntegration::Provider.get_by_name(channel.provider)
next unless is_enabled = ::DiscourseChatIntegration::Provider.is_enabled(provider)
begin
provider.trigger_notification(post, channel, rule)
channel.update_attribute('error_key', nil) if channel.error_key
rescue => e
if e.class == (DiscourseChat::ProviderError) && e.info.key?(:error_key) && !e.info[:error_key].nil?
if e.class == (DiscourseChatIntegration::ProviderError) && e.info.key?(:error_key) && !e.info[:error_key].nil?
channel.update_attribute('error_key', e.info[:error_key])
else
channel.update_attribute('error_key', 'chat_integration.channel_exception')
@@ -96,7 +96,7 @@ module DiscourseChat
# extra: { provider_name: provider::PROVIDER_NAME,
# channel: rule.channel,
# post_id: post.id,
# error_info: e.class == DiscourseChat::ProviderError ? e.info : nil }
# error_info: e.class == DiscourseChatIntegration::ProviderError ? e.info : nil }
# )
end
@@ -1,6 +1,6 @@
# frozen_string_literal: true
module DiscourseChat
module DiscourseChatIntegration
class ProviderError < StandardError
attr_accessor :info
@@ -44,12 +44,12 @@ module DiscourseChat
end
class HookEngine < ::Rails::Engine
engine_name DiscourseChat::PLUGIN_NAME + "-hooks"
isolate_namespace DiscourseChat::Provider
engine_name DiscourseChatIntegration::PLUGIN_NAME + "-hooks"
isolate_namespace DiscourseChatIntegration::Provider
end
class HookController < ::ApplicationController
requires_plugin DiscourseChat::PLUGIN_NAME
requires_plugin DiscourseChatIntegration::PLUGIN_NAME
class ProviderDisabled < StandardError; end
@@ -71,7 +71,7 @@ module DiscourseChat
# Automatically mount each provider's engine inside the HookEngine
def self.mount_engines
engines = []
DiscourseChat::Provider.providers.each do |provider|
DiscourseChatIntegration::Provider.providers.each do |provider|
engine = provider.constants.select do |constant|
constant.to_s =~ (/Engine$/) && (constant.to_s != "HookEngine")
end.map(&provider.method(:const_get)).first
@@ -81,7 +81,7 @@ module DiscourseChat
end
end
DiscourseChat::Provider::HookEngine.routes.draw do
DiscourseChatIntegration::Provider::HookEngine.routes.draw do
engines.each do |engine|
mount engine[:engine], at: engine[:name]
end
@@ -1,6 +1,6 @@
# frozen_string_literal: true
module DiscourseChat
module DiscourseChatIntegration
module Provider
module DiscordProvider
PROVIDER_NAME = "discord".freeze
@@ -70,7 +70,7 @@ module DiscourseChat
response = send_message(webhook_url, message)
if !response.kind_of?(Net::HTTPSuccess)
raise ::DiscourseChat::ProviderError.new(info: {
raise ::DiscourseChatIntegration::ProviderError.new(info: {
error_key: nil, message: message, response_body: response.body
})
end
@@ -1,6 +1,6 @@
# frozen_string_literal: true
module DiscourseChat::Provider::FlowdockProvider
module DiscourseChatIntegration::Provider::FlowdockProvider
PROVIDER_NAME = "flowdock".freeze
PROVIDER_ENABLED_SETTING = :chat_integration_flowdock_enabled
@@ -55,7 +55,7 @@ module DiscourseChat::Provider::FlowdockProvider
unless response.kind_of?(Net::HTTPSuccess)
error_key = nil
raise ::DiscourseChat::ProviderError.new info: { error_key: error_key, message: message, response_body: response.body }
raise ::DiscourseChatIntegration::ProviderError.new info: { error_key: error_key, message: message, response_body: response.body }
end
end
end
@@ -1,6 +1,6 @@
# frozen_string_literal: true
module DiscourseChat
module DiscourseChatIntegration
module Provider
module GitterProvider
PROVIDER_NAME = 'gitter'.freeze
@@ -15,7 +15,7 @@ module DiscourseChat
response = Net::HTTP.post_form(URI(channel.data['webhook_url']), message: message)
unless response.kind_of? Net::HTTPSuccess
error_key = nil
raise ::DiscourseChat::ProviderError.new info: { error_key: error_key, message: message, response_body: response.body }
raise ::DiscourseChatIntegration::ProviderError.new info: { error_key: error_key, message: message, response_body: response.body }
end
end
@@ -1,6 +1,6 @@
# frozen_string_literal: true
module DiscourseChat
module DiscourseChatIntegration
module Provider
module GoogleProvider
PROVIDER_NAME = 'google'.freeze
@@ -22,7 +22,7 @@ module DiscourseChat
response = http.request(req)
unless response.kind_of? Net::HTTPSuccess
raise ::DiscourseChat::ProviderError.new info: { request: req.body, response_code: response.code, response_body: response.body }
raise ::DiscourseChatIntegration::ProviderError.new info: { request: req.body, response_code: response.code, response_body: response.body }
end
end
@@ -1,5 +1,5 @@
# frozen_string_literal: true
module DiscourseChat::Provider::GroupmeProvider
module DiscourseChatIntegration::Provider::GroupmeProvider
PROVIDER_NAME = "groupme".freeze
PROVIDER_ENABLED_SETTING = :chat_integration_groupme_enabled
CHANNEL_PARAMETERS = [
@@ -69,7 +69,7 @@ module DiscourseChat::Provider::GroupmeProvider
if last_error_raised
successfully_sent = instance_names.length() - num_errors
last_error_raised[:success_rate] = "#{successfully_sent}/#{instance_names.length()}"
raise ::DiscourseChat::ProviderError.new info: last_error_raised
raise ::DiscourseChatIntegration::ProviderError.new info: last_error_raised
end
end
@@ -1,6 +1,6 @@
# frozen_string_literal: true
module DiscourseChat
module DiscourseChatIntegration
module Provider
module MatrixProvider
PROVIDER_NAME = "matrix".freeze
@@ -71,7 +71,7 @@ module DiscourseChat
error_key = 'chat_integration.provider.matrix.errors.unknown_room'
end
ensure
raise ::DiscourseChat::ProviderError.new info: { error_key: error_key, message: message, response_body: response.body }
raise ::DiscourseChatIntegration::ProviderError.new info: { error_key: error_key, message: message, response_body: response.body }
end
end
@@ -1,8 +1,8 @@
# frozen_string_literal: true
module DiscourseChat::Provider::MattermostProvider
class MattermostCommandController < DiscourseChat::Provider::HookController
requires_provider ::DiscourseChat::Provider::MattermostProvider::PROVIDER_NAME
module DiscourseChatIntegration::Provider::MattermostProvider
class MattermostCommandController < DiscourseChatIntegration::Provider::HookController
requires_provider ::DiscourseChatIntegration::Provider::MattermostProvider::PROVIDER_NAME
before_action :mattermost_token_valid?, only: :command
@@ -36,14 +36,14 @@ module DiscourseChat::Provider::MattermostProvider
"##{params[:channel_name]}"
end
provider = DiscourseChat::Provider::MattermostProvider::PROVIDER_NAME
provider = DiscourseChatIntegration::Provider::MattermostProvider::PROVIDER_NAME
channel = DiscourseChat::Channel.with_provider(provider).with_data_value('identifier', channel_id).first
channel = DiscourseChatIntegration::Channel.with_provider(provider).with_data_value('identifier', channel_id).first
# Create channel if doesn't exist
channel ||= DiscourseChat::Channel.create!(provider: provider, data: { identifier: channel_id })
channel ||= DiscourseChatIntegration::Channel.create!(provider: provider, data: { identifier: channel_id })
::DiscourseChat::Helper.process_command(channel, tokens)
::DiscourseChatIntegration::Helper.process_command(channel, tokens)
end
@@ -59,8 +59,8 @@ module DiscourseChat::Provider::MattermostProvider
end
class MattermostEngine < ::Rails::Engine
engine_name DiscourseChat::PLUGIN_NAME + "-mattermost"
isolate_namespace DiscourseChat::Provider::MattermostProvider
engine_name DiscourseChatIntegration::PLUGIN_NAME + "-mattermost"
isolate_namespace DiscourseChatIntegration::Provider::MattermostProvider
end
MattermostEngine.routes.draw do
@@ -1,6 +1,6 @@
# frozen_string_literal: true
module DiscourseChat
module DiscourseChatIntegration
module Provider
module MattermostProvider
PROVIDER_NAME = "mattermost".freeze
@@ -25,7 +25,7 @@ module DiscourseChat
else
error_key = nil
end
raise ::DiscourseChat::ProviderError.new info: { error_key: error_key, request: req.body, response_code: response.code, response_body: response.body }
raise ::DiscourseChatIntegration::ProviderError.new info: { error_key: error_key, request: req.body, response_code: response.code, response_body: response.body }
end
end
@@ -1,6 +1,6 @@
# frozen_string_literal: true
module DiscourseChat::Provider::RocketchatProvider
module DiscourseChatIntegration::Provider::RocketchatProvider
PROVIDER_NAME = "rocketchat".freeze
PROVIDER_ENABLED_SETTING = :chat_integration_rocketchat_enabled
@@ -63,7 +63,7 @@ module DiscourseChat::Provider::RocketchatProvider
else
error_key = nil
end
raise ::DiscourseChat::ProviderError.new info: { error_key: error_key, request: req.body, response_code: response.code, response_body: response.body }
raise ::DiscourseChatIntegration::ProviderError.new info: { error_key: error_key, request: req.body, response_code: response.code, response_body: response.body }
end
end
@@ -1,8 +1,8 @@
# frozen_string_literal: true
module DiscourseChat::Provider::SlackProvider
class SlackCommandController < DiscourseChat::Provider::HookController
requires_provider ::DiscourseChat::Provider::SlackProvider::PROVIDER_NAME
module DiscourseChatIntegration::Provider::SlackProvider
class SlackCommandController < DiscourseChatIntegration::Provider::HookController
requires_provider ::DiscourseChatIntegration::Provider::SlackProvider::PROVIDER_NAME
before_action :slack_token_valid?, only: :command
before_action :slack_payload_token_valid?, only: :interactive
@@ -42,13 +42,13 @@ module DiscourseChat::Provider::SlackProvider
"##{params[:channel_name]}"
end
provider = DiscourseChat::Provider::SlackProvider::PROVIDER_NAME
provider = DiscourseChatIntegration::Provider::SlackProvider::PROVIDER_NAME
channel = DiscourseChat::Channel.with_provider(provider)
channel = DiscourseChatIntegration::Channel.with_provider(provider)
.with_data_value('identifier', channel_id)
.first
channel ||= DiscourseChat::Channel.create!(
channel ||= DiscourseChatIntegration::Channel.create!(
provider: provider,
data: { identifier: channel_id }
)
@@ -56,7 +56,7 @@ module DiscourseChat::Provider::SlackProvider
if tokens[0] == 'post'
process_post_request(channel, tokens, params[:channel_id], channel_id, params[:response_url])
else
{ text: ::DiscourseChat::Helper.process_command(channel, tokens) }
{ text: ::DiscourseChatIntegration::Helper.process_command(channel, tokens) }
end
end
@@ -67,7 +67,7 @@ module DiscourseChat::Provider::SlackProvider
Scheduler::Defer.later "Processing slack transcript request" do
response = build_post_request_response(channel, tokens, slack_channel_id, channel_name, response_url)
http = DiscourseChat::Provider::SlackProvider.slack_api_http
http = DiscourseChatIntegration::Provider::SlackProvider.slack_api_http
req = Net::HTTP::Post.new(URI(response_url), 'Content-Type' => 'application/json')
req.body = response.to_json
http.request(req)
@@ -117,7 +117,7 @@ module DiscourseChat::Provider::SlackProvider
def process_interactive(json)
Scheduler::Defer.later "Processing slack transcript update" do
http = DiscourseChat::Provider::SlackProvider.slack_api_http
http = DiscourseChatIntegration::Provider::SlackProvider.slack_api_http
if json[:type] == "block_actions" && json[:actions][0][:action_id] == "null_action"
# Do nothing
@@ -248,8 +248,8 @@ module DiscourseChat::Provider::SlackProvider
end
class SlackEngine < ::Rails::Engine
engine_name DiscourseChat::PLUGIN_NAME + "-slack"
isolate_namespace DiscourseChat::Provider::SlackProvider
engine_name DiscourseChatIntegration::PLUGIN_NAME + "-slack"
isolate_namespace DiscourseChatIntegration::Provider::SlackProvider
end
SlackEngine.routes.draw do
@@ -1,6 +1,6 @@
# frozen_string_literal: true
module DiscourseChat::Provider::SlackProvider
module DiscourseChatIntegration::Provider::SlackProvider
class SlackMessage
def initialize(raw_message, transcript)
@raw = raw_message
@@ -1,6 +1,6 @@
# frozen_string_literal: true
module DiscourseChat::Provider::SlackProvider
module DiscourseChatIntegration::Provider::SlackProvider
class SlackMessageFormatter < Nokogiri::XML::SAX::Document
attr_reader :excerpt
@@ -1,6 +1,6 @@
# frozen_string_literal: true
module DiscourseChat::Provider::SlackProvider
module DiscourseChatIntegration::Provider::SlackProvider
PROVIDER_NAME = "slack".freeze
THREAD = "thread".freeze
@@ -11,14 +11,14 @@ module DiscourseChat::Provider::SlackProvider
]
require_dependency 'topic'
::Topic.register_custom_field_type(DiscourseChat::Provider::SlackProvider::THREAD, :text)
::Topic.register_custom_field_type(DiscourseChatIntegration::Provider::SlackProvider::THREAD, :text)
class ::Topic
def slack_thread_id=(ts)
self.custom_fields[DiscourseChat::Provider::SlackProvider::THREAD] = ts
self.custom_fields[DiscourseChatIntegration::Provider::SlackProvider::THREAD] = ts
end
def slack_thread_id
self.custom_fields[DiscourseChat::Provider::SlackProvider::THREAD]
self.custom_fields[DiscourseChatIntegration::Provider::SlackProvider::THREAD]
end
end
@@ -121,7 +121,7 @@ module DiscourseChat::Provider::SlackProvider
response = http.request(req)
unless response.kind_of? Net::HTTPSuccess
raise ::DiscourseChat::ProviderError.new info: { request: uri, response_code: response.code, response_body: response.body }
raise ::DiscourseChatIntegration::ProviderError.new info: { request: uri, response_code: response.code, response_body: response.body }
end
json = JSON.parse(response.body)
@@ -132,7 +132,7 @@ module DiscourseChat::Provider::SlackProvider
else
error_key = nil
end
raise ::DiscourseChat::ProviderError.new info: { error_key: error_key, request: uri, response_code: response.code, response_body: response.body }
raise ::DiscourseChatIntegration::ProviderError.new info: { error_key: error_key, request: uri, response_code: response.code, response_body: response.body }
end
ts = json["ts"]
@@ -159,7 +159,7 @@ module DiscourseChat::Provider::SlackProvider
else
error_key = nil
end
raise ::DiscourseChat::ProviderError.new info: { error_key: error_key, request: req.body, response_code: response.code, response_body: response.body }
raise ::DiscourseChatIntegration::ProviderError.new info: { error_key: error_key, request: req.body, response_code: response.code, response_body: response.body }
end
end

Some files were not shown because too many files have changed in this diff Show More