feat: Telegram Channel (#2901)
- Ability to configure telegram bots as a channel in chatwoot - Receive a message sent to the telegram bot in chatwoot - Ability to reply to telegram users from chatwoot - Receive attachment messages in chatwoot fixes: #1843
This commit is contained in:
27
spec/services/telegram/incoming_message_service_spec.rb
Normal file
27
spec/services/telegram/incoming_message_service_spec.rb
Normal file
@@ -0,0 +1,27 @@
|
||||
require 'rails_helper'
|
||||
|
||||
describe Telegram::IncomingMessageService do
|
||||
let!(:telegram_channel) { create(:channel_telegram) }
|
||||
|
||||
describe '#perform' do
|
||||
context 'when valid text message params' do
|
||||
it 'creates appropriate conversations, message and contacts' do
|
||||
params = {
|
||||
'update_id' => 2_342_342_343_242,
|
||||
'message' => {
|
||||
'message_id' => 1,
|
||||
'from' => {
|
||||
'id' => 23, 'is_bot' => false, 'first_name' => 'Sojan', 'last_name' => 'Jose', 'username' => 'sojan', 'language_code' => 'en'
|
||||
},
|
||||
'chat' => { 'id' => 23, 'first_name' => 'Sojan', 'last_name' => 'Jose', 'username' => 'sojan', 'type' => 'private' },
|
||||
'date' => 1_631_132_077, 'text' => 'test'
|
||||
}
|
||||
}.with_indifferent_access
|
||||
described_class.new(inbox: telegram_channel.inbox, params: params).perform
|
||||
expect(telegram_channel.inbox.conversations).not_to eq(0)
|
||||
expect(Contact.all.first.name).to eq('Sojan Jose')
|
||||
expect(telegram_channel.inbox.messages.first.content).to eq('test')
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
19
spec/services/telegram/send_on_telegram_service_spec.rb
Normal file
19
spec/services/telegram/send_on_telegram_service_spec.rb
Normal file
@@ -0,0 +1,19 @@
|
||||
require 'rails_helper'
|
||||
|
||||
describe Telegram::SendOnTelegramService do
|
||||
describe '#perform' do
|
||||
context 'when a valid message' do
|
||||
it 'calls channel.send_message_on_telegram' do
|
||||
telegram_request = double
|
||||
telegram_channel = create(:channel_telegram)
|
||||
message = create(:message, message_type: :outgoing, content: 'test',
|
||||
conversation: create(:conversation, inbox: telegram_channel.inbox, additional_attributes: { 'chat_id' => '123' }))
|
||||
allow(HTTParty).to receive(:post).and_return(telegram_request)
|
||||
allow(telegram_request).to receive(:success?).and_return(true)
|
||||
allow(telegram_request).to receive(:parsed_response).and_return({ 'result' => { 'message_id' => 'telegram_123' } })
|
||||
described_class.new(message: message).perform
|
||||
expect(message.source_id).to eq('telegram_123')
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
Reference in New Issue
Block a user