FIX: Don’t process commands when 'text' is missing
This patch concerns the Telegram integration. Currently, we always try to process commands when we receive a hook from Telegram. To do so we rely on the `text` parameters from a Telegram message but the API documentation tells us this parameters is actually optional. It means sometimes it’s not present in the payload we receive but we still try to access it resulting in a crash. This patch addresses the issue by simply returning early from the `#process_command` method when `text` is missing from the payload since we don’t have anything to process then.
This commit is contained in:
parent
778bb3aad6
commit
c68fde5d2b
|
@ -58,6 +58,8 @@ module DiscourseChatIntegration::Provider::TelegramProvider
|
|||
end
|
||||
|
||||
def process_command(message)
|
||||
return unless message['text'] # No command to be processed
|
||||
|
||||
chat_id = params['message']['chat']['id']
|
||||
|
||||
provider = DiscourseChatIntegration::Provider::TelegramProvider::PROVIDER_NAME
|
||||
|
|
|
@ -135,6 +135,18 @@ describe 'Telegram Command Controller', type: :request do
|
|||
expect(response.status).to eq(200)
|
||||
expect(stub).to have_been_requested.times(1)
|
||||
end
|
||||
|
||||
context "when 'text' is missing" do
|
||||
it "does not break" do
|
||||
post '/chat-integration/telegram/command/shhh.json', params: {
|
||||
message: { chat: { id: 123 } }
|
||||
}
|
||||
|
||||
expect(response).to have_http_status :ok
|
||||
expect(DiscourseChatIntegration::Rule.count).to eq(0)
|
||||
expect(DiscourseChatIntegration::Channel.count).to eq(1)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
Loading…
Reference in New Issue