fastapi-basic 0.1.2__tar.gz → 0.1.4__tar.gz
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-0.1.2 → fastapi_basic-0.1.4}/PKG-INFO +2 -1
- fastapi_basic-0.1.4/fastapi_basic/ext/line/__init__.py +56 -0
- {fastapi_basic-0.1.2 → fastapi_basic-0.1.4}/fastapi_basic.egg-info/PKG-INFO +2 -1
- {fastapi_basic-0.1.2 → fastapi_basic-0.1.4}/fastapi_basic.egg-info/requires.txt +1 -0
- {fastapi_basic-0.1.2 → fastapi_basic-0.1.4}/setup.py +1 -1
- fastapi_basic-0.1.2/fastapi_basic/ext/line/__init__.py +0 -29
- {fastapi_basic-0.1.2 → fastapi_basic-0.1.4}/README.md +0 -0
- {fastapi_basic-0.1.2 → fastapi_basic-0.1.4}/fastapi_basic/__init__.py +0 -0
- {fastapi_basic-0.1.2 → fastapi_basic-0.1.4}/fastapi_basic/base_config.py +0 -0
- {fastapi_basic-0.1.2 → fastapi_basic-0.1.4}/fastapi_basic/base_factory.py +0 -0
- {fastapi_basic-0.1.2 → fastapi_basic-0.1.4}/fastapi_basic/const.py +0 -0
- {fastapi_basic-0.1.2 → fastapi_basic-0.1.4}/fastapi_basic/database/__init__.py +0 -0
- {fastapi_basic-0.1.2 → fastapi_basic-0.1.4}/fastapi_basic/database/mongodb.py +0 -0
- {fastapi_basic-0.1.2 → fastapi_basic-0.1.4}/fastapi_basic/exception/__init__.py +0 -0
- {fastapi_basic-0.1.2 → fastapi_basic-0.1.4}/fastapi_basic/exception/base_exception.py +0 -0
- {fastapi_basic-0.1.2 → fastapi_basic-0.1.4}/fastapi_basic/ext/__init__.py +0 -0
- {fastapi_basic-0.1.2 → fastapi_basic-0.1.4}/fastapi_basic/ext/aws/__init__.py +0 -0
- {fastapi_basic-0.1.2 → fastapi_basic-0.1.4}/fastapi_basic/ext/aws/const.py +0 -0
- {fastapi_basic-0.1.2 → fastapi_basic-0.1.4}/fastapi_basic/utils.py +0 -0
- {fastapi_basic-0.1.2 → fastapi_basic-0.1.4}/fastapi_basic.egg-info/SOURCES.txt +0 -0
- {fastapi_basic-0.1.2 → fastapi_basic-0.1.4}/fastapi_basic.egg-info/dependency_links.txt +0 -0
- {fastapi_basic-0.1.2 → fastapi_basic-0.1.4}/fastapi_basic.egg-info/top_level.txt +0 -0
- {fastapi_basic-0.1.2 → fastapi_basic-0.1.4}/setup.cfg +0 -0
|
@@ -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
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
from abc import ABCMeta, abstractmethod
|
|
2
|
+
import asyncio
|
|
3
|
+
|
|
4
|
+
from linebot import LineBotApi, WebhookHandler
|
|
5
|
+
from linebot.exceptions import LineBotApiError
|
|
6
|
+
from linebot.models import TextMessage, TextSendMessage, MessageEvent
|
|
7
|
+
|
|
8
|
+
from ...exception.base_exception import LineBotException
|
|
9
|
+
|
|
10
|
+
class LineBot(metaclass=ABCMeta):
|
|
11
|
+
def __init__(self, channel_access_token: str, channel_secret: str, logger=None):
|
|
12
|
+
self.channel_access_token = channel_access_token
|
|
13
|
+
self.channel_secret = channel_secret
|
|
14
|
+
self.line_bot_api = LineBotApi(self.channel_access_token)
|
|
15
|
+
self.handler = WebhookHandler(self.channel_secret)
|
|
16
|
+
self.logger = logger
|
|
17
|
+
|
|
18
|
+
self.register_handlers()
|
|
19
|
+
|
|
20
|
+
async def reply_message(self, event, text: str):
|
|
21
|
+
try:
|
|
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)
|
|
25
|
+
|
|
26
|
+
except LineBotApiError as err:
|
|
27
|
+
exception = LineBotException(str(err))
|
|
28
|
+
raise exception
|
|
29
|
+
|
|
30
|
+
async def push_message(self, line_uid: str, text: str):
|
|
31
|
+
try:
|
|
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)
|
|
35
|
+
|
|
36
|
+
except LineBotApiError as err:
|
|
37
|
+
message = f"Send line message fail, line_uid: {line_uid}, text: {text}, err: {str(err)}"
|
|
38
|
+
exception = LineBotException(message)
|
|
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
|
|
@@ -5,7 +5,7 @@ with open('requirements.txt', 'r') as f:
|
|
|
5
5
|
|
|
6
6
|
setup(
|
|
7
7
|
name='fastapi_basic', # 模組名稱
|
|
8
|
-
version='0.1.
|
|
8
|
+
version='0.1.4', # 版號版號
|
|
9
9
|
description='A short description of your module', # 模塊描述
|
|
10
10
|
long_description=open('README.md').read(), # 詳細描述,通常是 README 文件的内容
|
|
11
11
|
long_description_content_type='text/markdown', # markdown 格式
|
|
@@ -1,29 +0,0 @@
|
|
|
1
|
-
from linebot import LineBotApi, WebhookHandler
|
|
2
|
-
from linebot.exceptions import LineBotApiError
|
|
3
|
-
from linebot.models import TextMessage, TextSendMessage
|
|
4
|
-
|
|
5
|
-
from ...exception.base_exception import LineBotException
|
|
6
|
-
|
|
7
|
-
class LineBot:
|
|
8
|
-
def __init__(self, channel_access_token: str, channel_secret: str):
|
|
9
|
-
self.channel_access_token = channel_access_token
|
|
10
|
-
self.channel_secret = channel_secret
|
|
11
|
-
self.line_bot_api = LineBotApi(self.channel_access_token)
|
|
12
|
-
self.handler = WebhookHandler(self.channel_secret)
|
|
13
|
-
|
|
14
|
-
async def reply_message(self, event, message):
|
|
15
|
-
try:
|
|
16
|
-
self.line_bot_api.reply_message(event.reply_token, TextMessage(text=message))
|
|
17
|
-
|
|
18
|
-
except LineBotApiError as err:
|
|
19
|
-
exception = LineBotException(str(err))
|
|
20
|
-
raise exception
|
|
21
|
-
|
|
22
|
-
async def push_message(self, line_uid: str, text: str):
|
|
23
|
-
try:
|
|
24
|
-
self.line_bot_api.push_message(line_uid, TextSendMessage(text=text))
|
|
25
|
-
|
|
26
|
-
except LineBotApiError as err:
|
|
27
|
-
message = f"Send line message fail, line_uid: {line_uid}, text: {text}, err: {str(err)}"
|
|
28
|
-
exception = LineBotException(message)
|
|
29
|
-
raise exception
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|