fastapi-basic 0.1.2__py3-none-any.whl → 0.1.4__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Potentially problematic release.
This version of fastapi-basic might be problematic. Click here for more details.
- fastapi_basic/ext/line/__init__.py +33 -6
- {fastapi_basic-0.1.2.dist-info → fastapi_basic-0.1.4.dist-info}/METADATA +2 -1
- {fastapi_basic-0.1.2.dist-info → fastapi_basic-0.1.4.dist-info}/RECORD +5 -5
- {fastapi_basic-0.1.2.dist-info → fastapi_basic-0.1.4.dist-info}/WHEEL +0 -0
- {fastapi_basic-0.1.2.dist-info → fastapi_basic-0.1.4.dist-info}/top_level.txt +0 -0
|
@@ -1,19 +1,27 @@
|
|
|
1
|
+
from abc import ABCMeta, abstractmethod
|
|
2
|
+
import asyncio
|
|
3
|
+
|
|
1
4
|
from linebot import LineBotApi, WebhookHandler
|
|
2
5
|
from linebot.exceptions import LineBotApiError
|
|
3
|
-
from linebot.models import TextMessage, TextSendMessage
|
|
6
|
+
from linebot.models import TextMessage, TextSendMessage, MessageEvent
|
|
4
7
|
|
|
5
8
|
from ...exception.base_exception import LineBotException
|
|
6
9
|
|
|
7
|
-
class LineBot:
|
|
8
|
-
def __init__(self, channel_access_token: str, channel_secret: str):
|
|
10
|
+
class LineBot(metaclass=ABCMeta):
|
|
11
|
+
def __init__(self, channel_access_token: str, channel_secret: str, logger=None):
|
|
9
12
|
self.channel_access_token = channel_access_token
|
|
10
13
|
self.channel_secret = channel_secret
|
|
11
14
|
self.line_bot_api = LineBotApi(self.channel_access_token)
|
|
12
15
|
self.handler = WebhookHandler(self.channel_secret)
|
|
16
|
+
self.logger = logger
|
|
17
|
+
|
|
18
|
+
self.register_handlers()
|
|
13
19
|
|
|
14
|
-
async def reply_message(self, event,
|
|
20
|
+
async def reply_message(self, event, text: str):
|
|
15
21
|
try:
|
|
16
|
-
self.line_bot_api.reply_message(event.reply_token, TextMessage(text=
|
|
22
|
+
self.line_bot_api.reply_message(event.reply_token, TextMessage(text=text))
|
|
23
|
+
message = f"Send line message successful, event: {event}, text: {text}"
|
|
24
|
+
self.logger_message(message)
|
|
17
25
|
|
|
18
26
|
except LineBotApiError as err:
|
|
19
27
|
exception = LineBotException(str(err))
|
|
@@ -22,8 +30,27 @@ class LineBot:
|
|
|
22
30
|
async def push_message(self, line_uid: str, text: str):
|
|
23
31
|
try:
|
|
24
32
|
self.line_bot_api.push_message(line_uid, TextSendMessage(text=text))
|
|
33
|
+
message = f"Send line message successful, line_uid: {line_uid}, text: {text}"
|
|
34
|
+
self.logger_message(message)
|
|
25
35
|
|
|
26
36
|
except LineBotApiError as err:
|
|
27
37
|
message = f"Send line message fail, line_uid: {line_uid}, text: {text}, err: {str(err)}"
|
|
28
38
|
exception = LineBotException(message)
|
|
29
|
-
raise exception
|
|
39
|
+
raise exception
|
|
40
|
+
|
|
41
|
+
async def log_message(self, log_message: str):
|
|
42
|
+
if self.logger:
|
|
43
|
+
self.logger.info(log_message)
|
|
44
|
+
|
|
45
|
+
@abstractmethod
|
|
46
|
+
async def handle_message(self):
|
|
47
|
+
"""
|
|
48
|
+
Each bot should define what handle_message it wants.
|
|
49
|
+
"""
|
|
50
|
+
|
|
51
|
+
def register_handlers(self):
|
|
52
|
+
@self.handler.add(MessageEvent, message=TextMessage)
|
|
53
|
+
def handle_message(event: MessageEvent):
|
|
54
|
+
message = f'handle_message: {event}'
|
|
55
|
+
self.logger_message(message)
|
|
56
|
+
asyncio.create_task(self.handle_message(event))
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: fastapi_basic
|
|
3
|
-
Version: 0.1.
|
|
3
|
+
Version: 0.1.4
|
|
4
4
|
Summary: A short description of your module
|
|
5
5
|
Home-page: https://github.com/szx21023/fastapi-base
|
|
6
6
|
Author: szx21023
|
|
@@ -22,6 +22,7 @@ Requires-Dist: fastapi==0.115.12
|
|
|
22
22
|
Requires-Dist: h11==0.14.0
|
|
23
23
|
Requires-Dist: idna==3.10
|
|
24
24
|
Requires-Dist: jmespath==1.0.1
|
|
25
|
+
Requires-Dist: line-bot-sdk==3.12.0
|
|
25
26
|
Requires-Dist: pydantic==2.11.3
|
|
26
27
|
Requires-Dist: pydantic_core==2.33.1
|
|
27
28
|
Requires-Dist: python-dateutil==2.9.0.post0
|
|
@@ -10,8 +10,8 @@ fastapi_basic/exception/base_exception.py,sha256=VwMqn85rBeJCF6RIOYUR1eLxbP2aSDh
|
|
|
10
10
|
fastapi_basic/ext/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
11
11
|
fastapi_basic/ext/aws/__init__.py,sha256=N_cwnbv1N-F1SY6NenBOTZe20zGaKFu3UXAu17hFAXY,816
|
|
12
12
|
fastapi_basic/ext/aws/const.py,sha256=Mmb6lo11aZZDAVy-nK-v_JxtVPPKYUo9GB4ihH7XYuM,68
|
|
13
|
-
fastapi_basic/ext/line/__init__.py,sha256=
|
|
14
|
-
fastapi_basic-0.1.
|
|
15
|
-
fastapi_basic-0.1.
|
|
16
|
-
fastapi_basic-0.1.
|
|
17
|
-
fastapi_basic-0.1.
|
|
13
|
+
fastapi_basic/ext/line/__init__.py,sha256=LJ9w5zSj9d1CMTV0zIwaEhlhOYFSK1owONCc654yObY,2144
|
|
14
|
+
fastapi_basic-0.1.4.dist-info/METADATA,sha256=7pxd6PohLr89mHqHVP_sqUBddMuS5tcLIbV9IZ3ApvI,1776
|
|
15
|
+
fastapi_basic-0.1.4.dist-info/WHEEL,sha256=CmyFI0kx5cdEMTLiONQRbGQwjIoR1aIYB7eCAQ4KPJ0,91
|
|
16
|
+
fastapi_basic-0.1.4.dist-info/top_level.txt,sha256=Q9PdwWxaB4dy135MQHiroRYOqArdUSaIeEkzYinN6W0,14
|
|
17
|
+
fastapi_basic-0.1.4.dist-info/RECORD,,
|
|
File without changes
|
|
File without changes
|