Impl HTTP API

This commit is contained in:
Changhua
2023-04-03 12:24:18 +08:00
parent e96f3800e8
commit 891cada955
6 changed files with 86 additions and 2 deletions

View File

@@ -1,15 +1,17 @@
# -*- coding: utf-8 -*-
import logging
import re
import time
import logging
import xml.etree.ElementTree as ET
import uvicorn
from wcferry import Wcf
from configuration import Config
from func_chengyu import cy
from func_chatgpt import ChatGPT
from func_chengyu import cy
from func_http import Http
from job_mgmt import Job
@@ -186,3 +188,15 @@ class Robot(Job):
# 添加了好友,更新好友列表
self.allContacts[msg.sender] = nickName[0]
self.sendTextMsg(f"Hi {nickName[0]},我自动通过了你的好友请求。", msg.sender)
def enableHTTP(self) -> None:
"""暴露 HTTP 发送消息接口供外部调用,不配置则忽略"""
c = self.config.HTTP
if not c:
return
home = "https://github.com/lich0821/WeChatFerry"
http = Http(wcf=self.wcf,
title="API for send text",
description=f"Github: <a href='{home}'>WeChatFerry</a>",)
Http.start(http, c["host"], c["port"])