feat: Add message support for input_select type in LINE (#11628)

# Pull Request Template

## Description

Added input_select message type support for LINE

## Type of change

Please delete options that are not relevant.

- [ ] Bug fix (non-breaking change which fixes an issue)
- [X] New feature (non-breaking change which adds functionality)
- [ ] Breaking change (fix or feature that would cause existing
functionality not to work as expected)
- [ ] This change requires a documentation update

## How Has This Been Tested?

add testcase. and test manually by myself


## Checklist:

- [X] My code follows the style guidelines of this project
- [X] I have performed a self-review of my code
- [ ] I have commented on my code, particularly in hard-to-understand
areas
- [ ] I have made corresponding changes to the documentation
- [ ] My changes generate no new warnings
- [ ] I have added tests that prove my fix is effective or that my
feature works
- [ ] New and existing unit tests pass locally with my changes
- [ ] Any dependent changes have been merged and published in downstream
modules

---------

Co-authored-by: Muhsin Keloth <muhsinkeramam@gmail.com>
This commit is contained in:
mix5003
2025-06-10 16:40:51 +07:00
committed by GitHub
parent 3e73c1b4bc
commit cf1d0de294
3 changed files with 111 additions and 1 deletions

View File

@@ -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