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
This commit is contained in:
Raimundo Herrera 2019-09-11 11:08:40 -03:00 committed by Robin Ward
parent df44beb9a3
commit 695d56a3dd
3 changed files with 11 additions and 1 deletions

View File

@ -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'

View File

@ -10,6 +10,8 @@ chat_integration:
#######################################
########## SLACK SETTINGS #############
#######################################
chat_integration_slack_username:
default: ''
chat_integration_slack_enabled:
default: false
validator: "ChatIntegrationSlackEnabledSettingValidator"

View File

@ -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: []
}