Support slash commands in telegram group chats

This commit is contained in:
David Taylor 2017-07-21 17:55:33 +01:00
parent 745c289c6e
commit 701e246ad2
2 changed files with 14 additions and 0 deletions

View File

@ -63,6 +63,7 @@ module DiscourseChat::Provider::TelegramProvider
tokens = message['text'].split(" ") tokens = message['text'].split(" ")
tokens[0][0] = '' # Remove the slash from the first token 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) return ::DiscourseChat::Helper.process_command(channel, tokens)
end end

View File

@ -80,6 +80,19 @@ describe 'Telegram Command Controller', type: :request do
expect(rule.tags).to eq(nil) expect(rule.tags).to eq(nil)
end 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 context 'from an unknown channel' do
it 'does nothing' do it 'does nothing' do
post '/chat-integration/telegram/command/shhh.json', message: {chat: {id:456}, text: "/watch #{category.slug}" } post '/chat-integration/telegram/command/shhh.json', message: {chat: {id:456}, text: "/watch #{category.slug}" }