From 70c6b4e7cc987ad79993b48ca4c3feeb115edf2c Mon Sep 17 00:00:00 2001 From: Tom You <> Date: Fri, 11 Oct 2024 15:44:12 +0900 Subject: [PATCH 1/5] adding readBySend --- nta/api.py | 5 +++-- nta/models/payload.py | 9 ++++++--- 2 files changed, 9 insertions(+), 5 deletions(-) diff --git a/nta/api.py b/nta/api.py index 0539617..726b582 100644 --- a/nta/api.py +++ b/nta/api.py @@ -128,7 +128,7 @@ def webhook_handler(self, req): name = event.event self._call_handler(name, event) - def send(self, user_id, message, quick_reply=None, notification=False, callback=None): + def send(self, user_id, message, quick_reply=None, notification=False, read_by_send=False,callback=None): """ Send a message to user_id with quick_reply or not. If notification True, push alarm occurred on user's phone. @@ -149,6 +149,7 @@ def send(self, user_id, message, quick_reply=None, notification=False, callback= user=user_id, message=message, quick_reply=quick_reply, + read_by_send=read_by_send, notification=notification ) @@ -391,4 +392,4 @@ def __error_check(self, response): When recieved success: false, raise NaverTalkApiError. """ if not response.success: - raise NaverTalkApiError(response) \ No newline at end of file + raise NaverTalkApiError(response) diff --git a/nta/models/payload.py b/nta/models/payload.py index 9aad7bf..a0bab20 100644 --- a/nta/models/payload.py +++ b/nta/models/payload.py @@ -22,7 +22,7 @@ class GenericPayload(Payload): General Payload For Send a message to users. """ - def __init__(self, message, quick_reply=None, notification=False, **kwargs): + def __init__(self, message, quick_reply=None, notification=False,read_by_send=False, **kwargs): """__init__ method. Args: @@ -33,7 +33,10 @@ def __init__(self, message, quick_reply=None, notification=False, **kwargs): super(GenericPayload, self).__init__(**kwargs) self.event = 'send' - self.options = {"notification": notification} + self.options = { + "notification": notification, + "readBySend": read_by_send + } if isinstance(message, str): message = TextContent(message) if quick_reply: @@ -151,4 +154,4 @@ def __init__(self, ids, display_type='single', **kwargs): self.options = { 'ids': ids, 'displayType': display_type - } \ No newline at end of file + } From fdf16db8ba97708c3660bbbf153f552bef359011 Mon Sep 17 00:00:00 2001 From: Tom You <> Date: Sun, 20 Oct 2024 09:42:43 +0900 Subject: [PATCH 2/5] change format --- nta/api.py | 4 ++-- nta/models/payload.py | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/nta/api.py b/nta/api.py index 726b582..c4bc9c4 100644 --- a/nta/api.py +++ b/nta/api.py @@ -128,7 +128,7 @@ def webhook_handler(self, req): name = event.event self._call_handler(name, event) - def send(self, user_id, message, quick_reply=None, notification=False, read_by_send=False,callback=None): + def send(self, user_id, message, quick_reply=None, notification=False, read_by_send=False, callback=None): """ Send a message to user_id with quick_reply or not. If notification True, push alarm occurred on user's phone. @@ -392,4 +392,4 @@ def __error_check(self, response): When recieved success: false, raise NaverTalkApiError. """ if not response.success: - raise NaverTalkApiError(response) + raise NaverTalkApiError(response) \ No newline at end of file diff --git a/nta/models/payload.py b/nta/models/payload.py index a0bab20..e5e882b 100644 --- a/nta/models/payload.py +++ b/nta/models/payload.py @@ -22,7 +22,7 @@ class GenericPayload(Payload): General Payload For Send a message to users. """ - def __init__(self, message, quick_reply=None, notification=False,read_by_send=False, **kwargs): + def __init__(self, message, quick_reply=None, notification=False, read_by_send=False, **kwargs): """__init__ method. Args: @@ -154,4 +154,4 @@ def __init__(self, ids, display_type='single', **kwargs): self.options = { 'ids': ids, 'displayType': display_type - } + } \ No newline at end of file From d6102c38fe13cd1c3fcda07be1ddbbd8dd14a556 Mon Sep 17 00:00:00 2001 From: Tom You <> Date: Sun, 20 Oct 2024 10:12:06 +0900 Subject: [PATCH 3/5] Add UT & update response package for python 3.9+ https://github.com/skorch-dev/skorch/issues/895 --- README.md | 13 +++++++++++++ nta/models/payload.py | 1 + requirements.txt | 2 +- tests/api/test_send_composite.py | 10 +++++++--- tests/api/test_send_image.py | 9 ++++++--- tests/api/test_send_text.py | 6 ++++-- 6 files changed, 32 insertions(+), 9 deletions(-) diff --git a/README.md b/README.md index fdbb250..b1266a3 100644 --- a/README.md +++ b/README.md @@ -19,6 +19,7 @@ __Inspired By : [fbmq](https://github.com/conbus/fbmq) and [line-bot-sdk](https: ## Table of Contents * [Install](#install) +* [Run Unit Test](#Run-Unit-Test) * [Synopsis](#synopsis) * [API](#api) - [NaverTalkApi](#navertalkapi) @@ -80,9 +81,20 @@ __Inspired By : [fbmq](https://github.com/conbus/fbmq) and [line-bot-sdk](https: - [HandOverEvent](#handoverevent) ## Install +install as package to run ``` pip install nta ``` +To run dev environment +``` +pip install -r requirements.txt +``` + +## Run Unit Test +``` +python -m unittest +``` + ## Synopsis Usage (with flask) @@ -332,6 +344,7 @@ def hello_callback_handler(event): - message *Template* or *str*: 전송하고자 하는 메세지 - quick_reply *Template* or *list*: 빠른 답장 - notification *bool*: 푸쉬 메세지 설정 +- readBySend *bool*: 자동 읽음으로 표시 설정 - callback *func*: callback 함수. 메세지를 보내고 난 뒤에 실행된다. #### __Text__ diff --git a/nta/models/payload.py b/nta/models/payload.py index e5e882b..9f145c9 100644 --- a/nta/models/payload.py +++ b/nta/models/payload.py @@ -29,6 +29,7 @@ def __init__(self, message, quick_reply=None, notification=False, read_by_send=F - message: str or Template.TextContent - quick_reply: list of buttons or Template.QuickReply - notification: boolean + - readBySend: boolean """ super(GenericPayload, self).__init__(**kwargs) diff --git a/requirements.txt b/requirements.txt index b61b234..c3eb363 100644 --- a/requirements.txt +++ b/requirements.txt @@ -6,6 +6,6 @@ idna==2.6 mock==2.0.0 pbr==3.1.1 requests>=2.20.0 -responses==0.8.1 +responses==0.12.0 six==1.11.0 urllib3>=1.23 diff --git a/tests/api/test_send_composite.py b/tests/api/test_send_composite.py index 245db82..83ecc67 100644 --- a/tests/api/test_send_composite.py +++ b/tests/api/test_send_composite.py @@ -75,7 +75,8 @@ def test_callback(res, payload): ] }, 'options': { - 'notification': False + 'notification': False, + 'readBySend': False } } ) @@ -152,7 +153,8 @@ def test_callback(res, payload): }, 'options': { - 'notification': False + 'notification': False, + 'readBySend': False } } ) @@ -239,7 +241,9 @@ def test_callback(res, payload): ] }, 'options': { - 'notification': False + 'notification': False, + 'readBySend': False + } } self.assertEqual(target, payload.as_json_dict()) diff --git a/tests/api/test_send_image.py b/tests/api/test_send_image.py index 37ab4ef..fde6bc4 100644 --- a/tests/api/test_send_image.py +++ b/tests/api/test_send_image.py @@ -46,7 +46,8 @@ def test_callback(res, payload): 'imageUrl': 'test.jpg', }, 'options': { - 'notification': False + 'notification': False, + 'readBySend': False } } ) @@ -72,7 +73,8 @@ def test_image_id_callback(res, payload): 'imageId': '1234test', }, 'options': { - 'notification': False + 'notification': False, + 'readBySend': False } } ) @@ -124,7 +126,8 @@ def test_callback(res, payload): 'type': 'LINK'}]} }, 'options': { - 'notification': False + 'notification': False, + 'readBySend': False } } ) diff --git a/tests/api/test_send_text.py b/tests/api/test_send_text.py index a7a6926..079794d 100644 --- a/tests/api/test_send_text.py +++ b/tests/api/test_send_text.py @@ -47,7 +47,8 @@ def test_callback(res, payload): 'inputType': None }, 'options': { - 'notification': False + 'notification': False, + 'readBySend': False } } ) @@ -92,7 +93,8 @@ def test_callback(res, payload): "event": "send", "user": "test_user_id", "options": { - "notification": False + "notification": False, + "readBySend": False }, "textContent": { "code": None, From 53f9b9ce1881cf2033dfe783d661e8d02537e29a Mon Sep 17 00:00:00 2001 From: Tom You <> Date: Sun, 20 Oct 2024 10:14:12 +0900 Subject: [PATCH 4/5] update readme --- README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index b1266a3..27d0a14 100644 --- a/README.md +++ b/README.md @@ -81,11 +81,11 @@ __Inspired By : [fbmq](https://github.com/conbus/fbmq) and [line-bot-sdk](https: - [HandOverEvent](#handoverevent) ## Install -install as package to run +install as a package ``` pip install nta ``` -To run dev environment +To run a dev environment ``` pip install -r requirements.txt ``` From 185a21aa125f4006b11cd5845ffc518aee0c082b Mon Sep 17 00:00:00 2001 From: Tom You <> Date: Sun, 20 Oct 2024 10:20:45 +0900 Subject: [PATCH 5/5] update dev env cli --- README.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/README.md b/README.md index 27d0a14..07142c0 100644 --- a/README.md +++ b/README.md @@ -88,6 +88,8 @@ pip install nta To run a dev environment ``` pip install -r requirements.txt +export naver_talk_access_token='your_access_token_here' +python example/example.py ``` ## Run Unit Test