Spaces:
Sleeping
Sleeping
alanchen1115
commited on
Commit
•
55b1be9
1
Parent(s):
5e22443
Update main.py
Browse files
main.py
CHANGED
@@ -1,4 +1,6 @@
|
|
1 |
-
from
|
|
|
|
|
2 |
import json
|
3 |
import os
|
4 |
|
@@ -11,20 +13,27 @@ from linebot.exceptions import (
|
|
11 |
from linebot.models import (
|
12 |
MessageEvent, TextMessage, TextSendMessage, ImageSendMessage, AudioMessage
|
13 |
)
|
14 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
15 |
line_bot_api = LineBotApi("ZwnEWwK46AUmRDOFXJOwUh1TqAELahP+kxHY0iBevF8JiEUe0CBQpkW2Gpo3C38LOaIX7hpW4IuTOSOjVof+DX9XgZg8MTeh5Iz+NDLlw6KKMtqNsyR6zt9CMnsso21ieifC/S8dcgXx3iKlhdS7UAdB04t89/1O/w1cDnyilFU=")
|
16 |
line_handler = WebhookHandler("7b9984bbc5c62445a79b95b15e34b727")
|
17 |
|
18 |
working_status = os.getenv("DEFALUT_TALKING", default = "true").lower() == "true"
|
19 |
|
20 |
-
app
|
21 |
-
|
22 |
-
|
23 |
-
def main():
|
24 |
-
return '您好'
|
25 |
|
26 |
-
@app.
|
27 |
-
def
|
28 |
# get X-Line-Signature header value
|
29 |
signature = request.headers['X-Line-Signature']
|
30 |
# get request body as text
|
@@ -54,7 +63,4 @@ def handle_message(event):
|
|
54 |
out = "不懂您的意思!"
|
55 |
line_bot_api.reply_message(
|
56 |
event.reply_token,
|
57 |
-
TextSendMessage(text=out))
|
58 |
-
|
59 |
-
if __name__ == '__main__':
|
60 |
-
app.run(host="0.0.0.0", port=7860)
|
|
|
1 |
+
from fastapi.middleware.cors import CORSMiddleware
|
2 |
+
from fastapi import FastAPI
|
3 |
+
|
4 |
import json
|
5 |
import os
|
6 |
|
|
|
13 |
from linebot.models import (
|
14 |
MessageEvent, TextMessage, TextSendMessage, ImageSendMessage, AudioMessage
|
15 |
)
|
16 |
+
|
17 |
+
app = FastAPI()
|
18 |
+
app.add_middleware(
|
19 |
+
CORSMiddleware,
|
20 |
+
allow_origins=["*"],
|
21 |
+
allow_credentials=True,
|
22 |
+
allow_methods=["*"],
|
23 |
+
allow_headers=["*"],
|
24 |
+
)
|
25 |
+
|
26 |
line_bot_api = LineBotApi("ZwnEWwK46AUmRDOFXJOwUh1TqAELahP+kxHY0iBevF8JiEUe0CBQpkW2Gpo3C38LOaIX7hpW4IuTOSOjVof+DX9XgZg8MTeh5Iz+NDLlw6KKMtqNsyR6zt9CMnsso21ieifC/S8dcgXx3iKlhdS7UAdB04t89/1O/w1cDnyilFU=")
|
27 |
line_handler = WebhookHandler("7b9984bbc5c62445a79b95b15e34b727")
|
28 |
|
29 |
working_status = os.getenv("DEFALUT_TALKING", default = "true").lower() == "true"
|
30 |
|
31 |
+
@app.get("/")
|
32 |
+
def root():
|
33 |
+
return {"title": "Echo Bot"}
|
|
|
|
|
34 |
|
35 |
+
@app.post("/webhook")
|
36 |
+
async def callback(request: Request)
|
37 |
# get X-Line-Signature header value
|
38 |
signature = request.headers['X-Line-Signature']
|
39 |
# get request body as text
|
|
|
63 |
out = "不懂您的意思!"
|
64 |
line_bot_api.reply_message(
|
65 |
event.reply_token,
|
66 |
+
TextSendMessage(text=out))
|
|
|
|
|
|