From b775c1247c03ef76d9c5df222472aba45bbe9316 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E3=81=AA=E3=81=AA=E3=81=A8=E3=81=84=E3=81=A4?= Date: Wed, 18 May 2022 14:47:17 +0900 Subject: [PATCH] Add two parameters to PostbackAction (#386) * add: PostbackInputOption * update: PostbackAction * update: TestActions::test_postback * update: constants __init__ * update: PostbackInputOption * update: PostbackInputOption --- linebot/constants/__init__.py | 15 +++++++++++++++ linebot/constants/postback_input_option.py | 22 ++++++++++++++++++++++ linebot/models/actions.py | 13 ++++++++++++- tests/models/test_actions.py | 5 ++++- 4 files changed, 53 insertions(+), 2 deletions(-) create mode 100644 linebot/constants/__init__.py create mode 100644 linebot/constants/postback_input_option.py diff --git a/linebot/constants/__init__.py b/linebot/constants/__init__.py new file mode 100644 index 00000000..2620cbe9 --- /dev/null +++ b/linebot/constants/__init__.py @@ -0,0 +1,15 @@ +# Licensed under the Apache License, Version 2.0 (the "License"); you may +# not use this file except in compliance with the License. You may obtain +# a copy of the License at +# +# https://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT +# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the +# License for the specific language governing permissions and limitations +# under the License. + +"""linebot.constants package.""" + +from .postback_input_option import PostbackInputOption # noqa diff --git a/linebot/constants/postback_input_option.py b/linebot/constants/postback_input_option.py new file mode 100644 index 00000000..ed2b3499 --- /dev/null +++ b/linebot/constants/postback_input_option.py @@ -0,0 +1,22 @@ +# Licensed under the Apache License, Version 2.0 (the "License"); you may +# not use this file except in compliance with the License. You may obtain +# a copy of the License at +# +# https://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT +# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the +# License for the specific language governing permissions and limitations +# under the License. + +"""linebot.constants.postback_input_option module.""" + + +class PostbackInputOption: + """Constant class for Postback input option.""" + + CLOSE_RICH_MENU = "closeRichMenu" + OPEN_RICH_MENU = "openRichMenu" + OPEN_KEYBOARD = "openKeyboard" + OPEN_VOICE = "openVoice" diff --git a/linebot/models/actions.py b/linebot/models/actions.py index 79d0b6c9..693c4809 100644 --- a/linebot/models/actions.py +++ b/linebot/models/actions.py @@ -73,7 +73,16 @@ class PostbackAction(Action): a postback event is returned via webhook with the specified string in the data property. """ - def __init__(self, label=None, data=None, display_text=None, text=None, **kwargs): + def __init__( + self, + label=None, + data=None, + display_text=None, + text=None, + input_option=None, + fill_in_text=None, + **kwargs + ): """__init__ method. :param str label: Label for the action. @@ -92,6 +101,8 @@ def __init__(self, label=None, data=None, display_text=None, text=None, **kwargs self.data = data self.display_text = display_text self.text = text + self.input_option = input_option + self.fill_in_text = fill_in_text class MessageAction(Action): diff --git a/tests/models/test_actions.py b/tests/models/test_actions.py index 63054884..f5132bfe 100644 --- a/tests/models/test_actions.py +++ b/tests/models/test_actions.py @@ -15,6 +15,7 @@ from __future__ import unicode_literals, absolute_import import unittest +from linebot.constants.postback_input_option import PostbackInputOption from linebot.models import ( PostbackAction, @@ -34,7 +35,9 @@ def test_postback(self): arg = { 'label': 'Buy', 'data': 'action=buy&id=1', - 'display_text': 'buy' + 'display_text': 'buy', + 'input_option': PostbackInputOption.OPEN_KEYBOARD, + 'fill_in_text': 'fill in text', } self.assertEqual( self.serialize_as_dict(arg, type=self.POSTBACK),