nonebot / adapter-feishu

NoneBot2 飞书适配器 / FeiShu (LarkSuite) adapter for nonebot2
https://feishu.adapters.nonebot.dev
MIT License
28 stars 6 forks source link

怎么在定时任务中调用call api 发送群消息? #6

Closed mrchenxxx closed 1 year ago

mrchenxxx commented 1 year ago

@timing.scheduled_job("cron", hour='19', minute='14', id="drink_tea") async def drink_tea(): (bot,) = get_bots().values() print(get_bots().values())

发送一条群聊信息

data = {
    "receive_id": "oc_af9cc089f2ce7395b4bab51130ad489a",
    "msg_type": "text",
    "content": json.dumps("{\"text\":\" test content\"}"),
    "query": {"receive_id_type": "chat_id"}
}
params = {
    "method": "POST",
    "data": json.dumps(data),
    "query": {"receive_id_type": "chat_id"},
}
await bot.call_api(f"im/v1/messages", **params)

报错

nonebot.adapters.feishu.exception.NetworkError: <NetWorkError message=HTTP request received unexpected status code: 400 response body: {"code":9499,"msg":"Bad Request","error":{"subcode":10109001,"log_id":"202210051906020102081671631AD946F5"}}>

mrchenxxx commented 1 year ago

@timing.scheduled_job("cron", hour='19', minute='42', id="drink_tea") async def drink_tea(): (bot,) = get_bots().values() print(get_bots().values())

发送一条群聊信息

data = {
    "msg_type": "text",
    "receive_id": "oc_af9cc089f2ce7395b4bab51130ad489a",
    "content": "{\"text\":\" 我的测试\"}",

}
params = {
    "method": "POST",
    "query": {"receive_id_type": "chat_id"},
    "body": data
}
await bot.call_api(f"im/v1/messages", **params)

是我没看好httpx的文档