mirror of
https://github.com/lingble/chatwoot.git
synced 2025-11-01 19:48:08 +00:00
feat: Add message support for input_select type in Facebook (#11627)
This commit is contained in:
@@ -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']
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user