-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathexample.py
More file actions
27 lines (21 loc) · 862 Bytes
/
Copy pathexample.py
File metadata and controls
27 lines (21 loc) · 862 Bytes
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
import aikframe as F
import fastapi
import uvicorn
app = fastapi.FastAPI()
aik = F.YunhuActivityManager()
@app.post("/v1/yunhu-callback")
async def callback(req: fastapi.Request):
await aik.receive_event(await req.json())
@aik.register_user_joined()
async def join_action(a: F.UserChangedModel):
F.send_message(("group", a.group), content=f"欢迎用户 {a.user} 进群!")
@aik.register_user_followed()
async def follow_action(a: F.UserChangedModel):
F.send_message(("user", a.user), content=f"欢迎用户 {a.user} 使用本机器人!")
@aik.register_message()
async def check_message(a: F.MessageModel):
if a.session.recvType == "group":
print(f"Accepted ({a.sender.senderId}@{a.session.recvId}): {a.content}")
else:
print(f"Accepted ({a.sender.senderId}): {a.content}")
uvicorn.run(app, port=4491, host="0.0.0.0")