From 695d56a3dd631d734c3e60332f03de8720c791f1 Mon Sep 17 00:00:00 2001 From: Raimundo Herrera Date: Wed, 11 Sep 2019 11:08:40 -0300 Subject: [PATCH] FEATURE: support for slack custom username (#22) * FEATURE: support for slack custom username * make slack username setting backwards compatible * fix slack username behavior when empty string --- config/locales/server.en.yml | 1 + config/settings.yml | 2 ++ lib/discourse_chat/provider/slack/slack_provider.rb | 9 ++++++++- 3 files changed, 11 insertions(+), 1 deletion(-) diff --git a/config/locales/server.en.yml b/config/locales/server.en.yml index 60fc99a..2775f88 100644 --- a/config/locales/server.en.yml +++ b/config/locales/server.en.yml @@ -7,6 +7,7 @@ en: ####################################### ########## SLACK SETTINGS ############# ####################################### + chat_integration_slack_username: "Bot's username to post to slack with" chat_integration_slack_enabled: 'Enable the slack chat-integration provider' chat_integration_slack_access_token: 'OAuth Access Token for authenticating with Slack' chat_integration_slack_incoming_webhook_token: 'The verification token used to authenticate incoming requests' diff --git a/config/settings.yml b/config/settings.yml index e16c92c..c402d19 100644 --- a/config/settings.yml +++ b/config/settings.yml @@ -10,6 +10,8 @@ chat_integration: ####################################### ########## SLACK SETTINGS ############# ####################################### + chat_integration_slack_username: + default: '' chat_integration_slack_enabled: default: false validator: "ChatIntegrationSlackEnabledSettingValidator" diff --git a/lib/discourse_chat/provider/slack/slack_provider.rb b/lib/discourse_chat/provider/slack/slack_provider.rb index 651e4cb..419e4dd 100644 --- a/lib/discourse_chat/provider/slack/slack_provider.rb +++ b/lib/discourse_chat/provider/slack/slack_provider.rb @@ -42,9 +42,16 @@ module DiscourseChat::Provider::SlackProvider "#{Discourse.base_url}#{url}" end + slack_username = + if SiteSetting.chat_integration_slack_username.present? + SiteSetting.chat_integration_slack_username + else + SiteSetting.title || "Discourse" + end + message = { channel: channel, - username: SiteSetting.title || "Discourse", + username: slack_username, icon_url: icon_url, attachments: [] }