FIX: Ensure telegram bot only responds to slash-commands (#94)
Co-authored-by: Froggy C <me@froggyc.eu>
This commit is contained in:
parent
369ca14711
commit
ae0389ca89
|
@ -20,6 +20,7 @@ module DiscourseChatIntegration::Provider::TelegramProvider
|
|||
|
||||
message_text = process_command(params['message'])
|
||||
|
||||
if message_text.present?
|
||||
message = {
|
||||
chat_id: chat_id,
|
||||
text: message_text,
|
||||
|
@ -28,6 +29,7 @@ module DiscourseChatIntegration::Provider::TelegramProvider
|
|||
}
|
||||
|
||||
DiscourseChatIntegration::Provider::TelegramProvider.sendMessage(message)
|
||||
end
|
||||
|
||||
elsif params.dig('channel_post', 'text')&.include?('/getchatid')
|
||||
chat_id = params['channel_post']['chat']['id']
|
||||
|
@ -62,10 +64,15 @@ module DiscourseChatIntegration::Provider::TelegramProvider
|
|||
|
||||
channel = DiscourseChatIntegration::Channel.with_provider(provider).with_data_value('chat_id', chat_id).first
|
||||
|
||||
text_key = "unknown_chat" if channel.nil?
|
||||
# If slash commands disabled, send a generic message
|
||||
text_key = "known_chat" if !SiteSetting.chat_integration_telegram_enable_slash_commands
|
||||
text_key = "help" if message['text'].blank?
|
||||
text_key = if channel.nil?
|
||||
"unknown_chat"
|
||||
elsif !SiteSetting.chat_integration_telegram_enable_slash_commands || !message['text'].start_with?('/')
|
||||
"silent"
|
||||
else
|
||||
""
|
||||
end
|
||||
|
||||
return "" if text_key == "silent"
|
||||
|
||||
if text_key.present?
|
||||
return I18n.t(
|
||||
|
|
Loading…
Reference in New Issue