From 701e246ad279aa436433e91d584bde986cfebc3f Mon Sep 17 00:00:00 2001 From: David Taylor Date: Fri, 21 Jul 2017 17:55:33 +0100 Subject: [PATCH] Support slash commands in telegram group chats --- .../telegram/telegram_command_controller.rb | 1 + .../telegram/telegram_command_controller_spec.rb | 13 +++++++++++++ 2 files changed, 14 insertions(+) diff --git a/lib/discourse_chat/provider/telegram/telegram_command_controller.rb b/lib/discourse_chat/provider/telegram/telegram_command_controller.rb index f3aba2f..bc6cb33 100644 --- a/lib/discourse_chat/provider/telegram/telegram_command_controller.rb +++ b/lib/discourse_chat/provider/telegram/telegram_command_controller.rb @@ -63,6 +63,7 @@ module DiscourseChat::Provider::TelegramProvider tokens = message['text'].split(" ") tokens[0][0] = '' # Remove the slash from the first token + tokens[0] = tokens[0].split('@')[0] # Remove the bot name from the command (necessary for group chats) return ::DiscourseChat::Helper.process_command(channel, tokens) end diff --git a/spec/lib/discourse_chat/provider/telegram/telegram_command_controller_spec.rb b/spec/lib/discourse_chat/provider/telegram/telegram_command_controller_spec.rb index d995a26..414836f 100644 --- a/spec/lib/discourse_chat/provider/telegram/telegram_command_controller_spec.rb +++ b/spec/lib/discourse_chat/provider/telegram/telegram_command_controller_spec.rb @@ -80,6 +80,19 @@ describe 'Telegram Command Controller', type: :request do expect(rule.tags).to eq(nil) end + it 'should add a new rule correctly using group chat syntax' do + post '/chat-integration/telegram/command/shhh.json', message: {chat: {id:123}, text: "/watch@my-awesome-bot #{category.slug}" } + + expect(response.status).to eq(200) + expect(stub).to have_been_requested.once + + rule = DiscourseChat::Rule.all.first + expect(rule.channel).to eq(chan1) + expect(rule.filter).to eq('watch') + expect(rule.category_id).to eq(category.id) + expect(rule.tags).to eq(nil) + end + context 'from an unknown channel' do it 'does nothing' do post '/chat-integration/telegram/command/shhh.json', message: {chat: {id:456}, text: "/watch #{category.slug}" }