-
Notifications
You must be signed in to change notification settings - Fork 21
Expand file tree
/
Copy pathmain.py
More file actions
60 lines (50 loc) · 1.94 KB
/
main.py
File metadata and controls
60 lines (50 loc) · 1.94 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
from fastapi import FastAPI, Request
from fastapi.responses import JSONResponse, RedirectResponse
from fastapi.middleware.cors import CORSMiddleware
import uvicorn
from message import get_wa_reply
fastApiApp = FastAPI()
fastApiApp.add_middleware(
CORSMiddleware,
allow_credentials = True,
allow_headers = ["*"],
allow_methods = ["*"],
allow_origins = ["*"]
)
@fastApiApp.get("/")
def main_page():
return RedirectResponse(url = "https://github.com/yymin1022/Wa_API")
@fastApiApp.post("/getMessage")
async def get_message(request: Request):
reply_data = dict([("RESULT",
dict([("RESULT_CODE", 0),
("RESULT_MSG", "RESULT OK")])),
("DATA",
dict([("msg", ""),
("room", ""),
("sender", "")]))])
# Message Input Parse
try:
input_data = await request.json()
input_message = input_data["msg"]
input_room = input_data["room"]
input_sender = input_data["sender"]
except Exception as err_data:
reply_data["RESULT"]["RESULT_CODE"] = 200
reply_data["RESULT"]["RESULT_MSG"] = repr(err_data)
return JSONResponse(content = reply_data)
# Get Message
reply_message = get_wa_reply(input_message, input_room, input_sender)
# Reply Message
if reply_message is not None:
reply_data["RESULT"]["RESULT_CODE"] = 0
reply_data["RESULT"]["RESULT_MSG"] = "RESULT OK"
reply_data["DATA"]["msg"] = reply_message
reply_data["DATA"]["room"] = input_room
reply_data["DATA"]["sender"] = input_sender
else:
reply_data["RESULT"]["RESULT_CODE"] = 100
reply_data["RESULT"]["RESULT_MSG"] = "None WA Bot Message Found or Disabled Chatroom"
return JSONResponse(content = reply_data)
if __name__ == "__main__":
uvicorn.run("main:fastApiApp", host = "0.0.0.0", port = 80)