diff --git a/app/services/facebook/send_on_facebook_service.rb b/app/services/facebook/send_on_facebook_service.rb index 5e9212edd..f0b54a733 100644 --- a/app/services/facebook/send_on_facebook_service.rb +++ b/app/services/facebook/send_on_facebook_service.rb @@ -47,12 +47,29 @@ class Facebook::SendOnFacebookService < Base::SendOnChannelService def fb_text_message_params { recipient: { id: contact.get_source_id(inbox.id) }, - message: { text: message.content }, + message: fb_text_message_payload, messaging_type: 'MESSAGE_TAG', tag: 'ACCOUNT_UPDATE' } end + def fb_text_message_payload + if message.content_type == 'input_select' && message.content_attributes['items'].any? + { + text: message.content, + quick_replies: message.content_attributes['items'].map do |item| + { + content_type: 'text', + payload: item['title'], + title: item['title'] + } + end + } + else + { text: message.content } + end + end + def external_error(response) # https://developers.facebook.com/docs/graph-api/guides/error-handling/ error_message = response['error']['message'] diff --git a/spec/services/facebook/send_on_facebook_service_spec.rb b/spec/services/facebook/send_on_facebook_service_spec.rb index cddf527cb..4d5f9babd 100644 --- a/spec/services/facebook/send_on_facebook_service_spec.rb +++ b/spec/services/facebook/send_on_facebook_service_spec.rb @@ -166,5 +166,33 @@ describe Facebook::SendOnFacebookService do expect(message.status).not_to eq('failed') end end + + context 'with input_select' do + it 'if message with input_select is sent from chatwoot and is outgoing' do + message = build( + :message, + message_type: 'outgoing', + inbox: facebook_inbox, + account: account, + conversation: conversation, + content_type: 'input_select', + content_attributes: { 'items' => [{ 'title' => 'text 1', 'value' => 'value 1' }, { 'title' => 'text 2', 'value' => 'value 2' }] } + ) + + described_class.new(message: message).perform + expect(bot).to have_received(:deliver).with({ + recipient: { id: contact_inbox.source_id }, + message: { + text: message.content, + quick_replies: [ + { content_type: 'text', payload: 'text 1', title: 'text 1' }, + { content_type: 'text', payload: 'text 2', title: 'text 2' } + ] + }, + messaging_type: 'MESSAGE_TAG', + tag: 'ACCOUNT_UPDATE' + }, { page_id: facebook_channel.page_id }) + end + end end end