feat: support reply to for Telegram (#8105)
Co-authored-by: Muhsin Keloth <muhsinkeramam@gmail.com>
This commit is contained in:
@@ -8,6 +8,7 @@ describe Messages::MessageBuilder do
|
||||
let(:inbox) { create(:inbox, account: account) }
|
||||
let(:inbox_member) { create(:inbox_member, inbox: inbox, account: account) }
|
||||
let(:conversation) { create(:conversation, inbox: inbox, account: account) }
|
||||
let(:message_for_reply) { create(:message, conversation: conversation) }
|
||||
let(:params) do
|
||||
ActionController::Parameters.new({
|
||||
content: 'test'
|
||||
@@ -21,6 +22,75 @@ describe Messages::MessageBuilder do
|
||||
end
|
||||
end
|
||||
|
||||
describe '#content_attributes' do
|
||||
context 'when content_attributes is a JSON string' do
|
||||
let(:params) do
|
||||
ActionController::Parameters.new({
|
||||
content: 'test',
|
||||
content_attributes: "{\"in_reply_to\":#{message_for_reply.id}}"
|
||||
})
|
||||
end
|
||||
|
||||
it 'parses content_attributes from JSON string' do
|
||||
message = described_class.new(user, conversation, params).perform
|
||||
expect(message.content_attributes).to include(in_reply_to: message_for_reply.id)
|
||||
end
|
||||
end
|
||||
|
||||
context 'when content_attributes is a hash' do
|
||||
let(:params) do
|
||||
ActionController::Parameters.new({
|
||||
content: 'test',
|
||||
content_attributes: { in_reply_to: message_for_reply.id }
|
||||
})
|
||||
end
|
||||
|
||||
it 'uses content_attributes as provided' do
|
||||
message = described_class.new(user, conversation, params).perform
|
||||
expect(message.content_attributes).to include(in_reply_to: message_for_reply.id)
|
||||
end
|
||||
end
|
||||
|
||||
context 'when content_attributes is absent' do
|
||||
let(:params) do
|
||||
ActionController::Parameters.new({ content: 'test' })
|
||||
end
|
||||
|
||||
it 'defaults to an empty hash' do
|
||||
message = message_builder
|
||||
expect(message.content_attributes).to eq({})
|
||||
end
|
||||
end
|
||||
|
||||
context 'when content_attributes is nil' do
|
||||
let(:params) do
|
||||
ActionController::Parameters.new({
|
||||
content: 'test',
|
||||
content_attributes: nil
|
||||
})
|
||||
end
|
||||
|
||||
it 'defaults to an empty hash' do
|
||||
message = message_builder
|
||||
expect(message.content_attributes).to eq({})
|
||||
end
|
||||
end
|
||||
|
||||
context 'when content_attributes is an invalid JSON string' do
|
||||
let(:params) do
|
||||
ActionController::Parameters.new({
|
||||
content: 'test',
|
||||
content_attributes: 'invalid_json'
|
||||
})
|
||||
end
|
||||
|
||||
it 'defaults to an empty hash' do
|
||||
message = message_builder
|
||||
expect(message.content_attributes).to eq({})
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
describe '#perform when message_type is incoming' do
|
||||
context 'when channel is not api' do
|
||||
let(:params) do
|
||||
|
||||
@@ -10,7 +10,7 @@ RSpec.describe Channel::Telegram do
|
||||
|
||||
stub_request(:post, "https://api.telegram.org/bot#{telegram_channel.bot_token}/sendMessage")
|
||||
.with(
|
||||
body: 'chat_id=123&text=test&reply_markup='
|
||||
body: 'chat_id=123&text=test&reply_markup=&reply_to_message_id='
|
||||
)
|
||||
.to_return(
|
||||
status: 200,
|
||||
@@ -32,7 +32,7 @@ RSpec.describe Channel::Telegram do
|
||||
.with(
|
||||
body: 'chat_id=123&text=test' \
|
||||
'&reply_markup=%7B%22one_time_keyboard%22%3Atrue%2C%22inline_keyboard%22%3A%5B%5B%7B%22text%22%3A%22test%22%2C%22' \
|
||||
'callback_data%22%3A%22test%22%7D%5D%5D%7D'
|
||||
'callback_data%22%3A%22test%22%7D%5D%5D%7D&reply_to_message_id='
|
||||
)
|
||||
.to_return(
|
||||
status: 200,
|
||||
|
||||
Reference in New Issue
Block a user