diff --git a/app/javascript/dashboard/components-next/message/bubbles/Form.vue b/app/javascript/dashboard/components-next/message/bubbles/Form.vue
index ca9af4994..12cfafa8f 100644
--- a/app/javascript/dashboard/components-next/message/bubbles/Form.vue
+++ b/app/javascript/dashboard/components-next/message/bubbles/Form.vue
@@ -4,9 +4,11 @@ import BaseBubble from './Base.vue';
import { useI18n } from 'vue-i18n';
import { CONTENT_TYPES } from '../constants.js';
import { useMessageContext } from '../provider.js';
+import { useInbox } from 'dashboard/composables/useInbox';
const { content, contentAttributes, contentType } = useMessageContext();
const { t } = useI18n();
+const { isAWebWidgetInbox } = useInbox();
const formValues = computed(() => {
if (contentType.value === CONTENT_TYPES.FORM) {
@@ -56,7 +58,7 @@ const formValues = computed(() => {
+
{{ t('CONVERSATION.NO_RESPONSE') }}
diff --git a/app/services/line/send_on_line_service.rb b/app/services/line/send_on_line_service.rb
index 03ebe0ab7..057eb09e2 100644
--- a/app/services/line/send_on_line_service.rb
+++ b/app/services/line/send_on_line_service.rb
@@ -22,6 +22,14 @@ class Line::SendOnLineService < Base::SendOnChannelService
end
def build_payload
+ if message.content_type == 'input_select' && message.content_attributes['items'].any?
+ build_input_select_payload
+ else
+ build_text_payload
+ end
+ end
+
+ def build_text_payload
if message.content && message.attachments.any?
[text_message, *attachments]
elsif message.content.nil? && message.attachments.any?
@@ -52,6 +60,43 @@ class Line::SendOnLineService < Base::SendOnChannelService
}
end
+ # https://developers.line.biz/en/reference/messaging-api/#flex-message
+ def build_input_select_payload
+ {
+ type: 'flex',
+ altText: message.content,
+ contents: {
+ type: 'bubble',
+ body: {
+ type: 'box',
+ layout: 'vertical',
+ contents: [
+ {
+ type: 'text',
+ text: message.content
+ },
+ *input_select_to_button
+ ]
+ }
+ }
+ }
+ end
+
+ def input_select_to_button
+ message.content_attributes['items'].map do |item|
+ {
+ type: 'button',
+ style: 'link',
+ height: 'sm',
+ action: {
+ type: 'message',
+ label: item['title'],
+ text: item['value']
+ }
+ }
+ end
+ end
+
# https://developers.line.biz/en/reference/messaging-api/#error-responses
def external_error(error)
# Message containing information about the error. See https://developers.line.biz/en/reference/messaging-api/#error-messages
diff --git a/spec/services/line/send_on_line_service_spec.rb b/spec/services/line/send_on_line_service_spec.rb
index bed8917b8..5352565e7 100644
--- a/spec/services/line/send_on_line_service_spec.rb
+++ b/spec/services/line/send_on_line_service_spec.rb
@@ -93,6 +93,69 @@ describe Line::SendOnLineService do
end
end
+ context 'with message input_select' do
+ let(:success_response) do
+ {
+ 'message' => 'ok'
+ }.to_json
+ end
+
+ let(:expect_message) do
+ {
+ type: 'flex',
+ altText: 'test',
+ contents: {
+ type: 'bubble',
+ body: {
+ type: 'box',
+ layout: 'vertical',
+ contents: [
+ {
+ type: 'text',
+ text: 'test'
+ },
+ {
+ type: 'button',
+ style: 'link',
+ height: 'sm',
+ action: {
+ type: 'message',
+ label: 'text 1',
+ text: 'value 1'
+ }
+ },
+ {
+ type: 'button',
+ style: 'link',
+ height: 'sm',
+ action: {
+ type: 'message',
+ label: 'text 2',
+ text: 'value 2'
+ }
+ }
+ ]
+ }
+ }
+ }
+ end
+
+ it 'sends the message with input_select' do
+ message = create(
+ :message, message_type: :outgoing, content: 'test', content_type: 'input_select',
+ content_attributes: { 'items' => [{ 'title' => 'text 1', 'value' => 'value 1' }, { 'title' => 'text 2', 'value' => 'value 2' }] },
+ conversation: create(:conversation, inbox: line_channel.inbox)
+ )
+
+ expect(line_client).to receive(:push_message).with(
+ message.conversation.contact_inbox.source_id,
+ expect_message
+ ).and_return(OpenStruct.new(code: '200', body: success_response))
+
+ described_class.new(message: message).perform
+ end
+ end
+
context 'with message attachments' do
it 'sends the message with text and attachments' do
attachment = message.attachments.new(account_id: message.account_id, file_type: :image)