Skip to content

Commit

Permalink
Add two parameters to PostbackAction (#386)
Browse files Browse the repository at this point in the history
* add: PostbackInputOption

* update: PostbackAction

* update: TestActions::test_postback

* update: constants __init__

* update: PostbackInputOption

* update: PostbackInputOption
  • Loading branch information
nanato12 authored May 18, 2022
1 parent 1b63fb0 commit b775c12
Show file tree
Hide file tree
Showing 4 changed files with 53 additions and 2 deletions.
15 changes: 15 additions & 0 deletions linebot/constants/__init__.py
Original file line number Diff line number Diff line change
@@ -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
22 changes: 22 additions & 0 deletions linebot/constants/postback_input_option.py
Original file line number Diff line number Diff line change
@@ -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"
13 changes: 12 additions & 1 deletion linebot/models/actions.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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):
Expand Down
5 changes: 4 additions & 1 deletion tests/models/test_actions.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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),
Expand Down

0 comments on commit b775c12

Please sign in to comment.