This commit is contained in:
1 parent
dc72f506a9
commit
3d3e437b00
3 files changed
+100
-2
No files matched your search
+1
-1
@@ -173,7 +173,7 @@ def do_card_action_trigger(data: P2CardActionTrigger) -> P2CardActionTriggerResp
|
||||
activity_name = data.event.action.form_value.get("select_activity")
|
||||
|
||||
process_push_xbot_activity_bot.delay(activity_name, open_id)
|
||||
resp = {"toast": {"type": "info", "content": "提交成功"}}
|
||||
resp = {"toast": {"type": "info", "content": "提交成功, 机器人即将推送"}}
|
||||
return P2CardActionTriggerResponse(resp)
|
||||
|
||||
|
||||
|
||||
+8
-1
@@ -18,6 +18,7 @@ from app.utils.feishu import (
|
||||
from app.utils.utils import update_record, add_record
|
||||
from app.utils.yd_utils import new_blank_robot, new_blank_activity
|
||||
from app.utils.xbot_utils import push_xbot_activity_bot
|
||||
from app.utils.xbot_utils import send_select_activity_card_message
|
||||
|
||||
|
||||
def parse_history_message(data):
|
||||
@@ -148,11 +149,17 @@ def process_message_callback(
|
||||
content = json.loads(message_data.get("content"))
|
||||
content_text = content.get("text")
|
||||
|
||||
if "记录问题" not in content_text:
|
||||
if "记录问题" not in content_text or "下载指令" not in content_text:
|
||||
# 忽略非记录问题的消息
|
||||
lark.logger.info("忽略非记录问题的消息")
|
||||
return
|
||||
|
||||
# 根据消息内容走不同的逻辑
|
||||
if "下载指令" in content_text:
|
||||
# 发送一个卡片消息
|
||||
send_select_activity_card_message(message_id)
|
||||
return
|
||||
|
||||
record_category = "官方指令" if "指令" in content_text else "官方应用"
|
||||
|
||||
record = {}
|
||||
|
||||
@@ -260,6 +260,7 @@ def package_activity(token, robot_uuid, basedir):
|
||||
|
||||
|
||||
def send_message(file_path, open_id):
|
||||
"""发送指令文件到指定用户"""
|
||||
# 创建client
|
||||
|
||||
YOUR_APP_ID = "cli_a5110cd1da70900b"
|
||||
@@ -348,3 +349,93 @@ def push_xbot_activity_bot(activity_code, open_id):
|
||||
token=token, robot_uuid=activity_code, basedir=base_dir
|
||||
)
|
||||
send_message(activity_path, open_id)
|
||||
|
||||
|
||||
def get_office_activity_names_with_viewname(token):
|
||||
"""
|
||||
获取自定义指令的名称及版本
|
||||
:return: list, 返回自定义指令 名_版本号
|
||||
"""
|
||||
page = 1
|
||||
uuid = []
|
||||
url = "https://api.winrobot360.com/api/v1/robot/activity/package/list?source=market&page=%s&size=100&uiaType=uiatype"
|
||||
|
||||
payload = {}
|
||||
headers = {
|
||||
"Authorization": f"bearer {token}",
|
||||
}
|
||||
activity_data = []
|
||||
response = requests.request("GET", url % page, headers=headers, data=payload)
|
||||
|
||||
page_info = response.json().get("page").get("pages")
|
||||
for page in range(1, page_info + 1):
|
||||
response = requests.request("GET", url % page, headers=headers, data=payload)
|
||||
for item in response.json().get("data"):
|
||||
uuid.append(item.get("packageName") + "==" + item.get("packageVersion"))
|
||||
# activity_data[item.get("packageViewName")] = item.get("packageName") + "==" + item.get("packageVersion")
|
||||
|
||||
# activity_data.append({"activity_name": item.get("packageViewName"), "activity_code": item.get("packageName") + "==" + item.get("packageVersion")})
|
||||
|
||||
activity_data.append(
|
||||
{
|
||||
"text": item.get("packageViewName"),
|
||||
"value": f'{item.get("packageName")}=={item.get("packageVersion")}',
|
||||
}
|
||||
)
|
||||
|
||||
return activity_data
|
||||
|
||||
|
||||
def send_select_activity_card_message(message_id):
|
||||
username = "剑心@fckj"
|
||||
password = "320753691love"
|
||||
# open_id = "ou_d542891996bf1961f9a94563e6bd4d49"
|
||||
token = get_token(username=username, password=password)
|
||||
activity_data = get_office_activity_names_with_viewname(token)
|
||||
|
||||
content = {
|
||||
"type": "template",
|
||||
"data": {
|
||||
"template_id": "AAqR6hyJFojEs",
|
||||
"template_version_name": "1.0.6",
|
||||
"template_variable": {"activity_list": activity_data},
|
||||
},
|
||||
}
|
||||
APP_ID = "cli_a5110cd1da70900b"
|
||||
APP_SECRET = "XwTUlUq7dGK1XexUS7ljShJJ7t1MIwXF"
|
||||
|
||||
client = (
|
||||
lark.Client.builder()
|
||||
.app_id(APP_ID)
|
||||
.app_secret(APP_SECRET)
|
||||
.log_level(lark.LogLevel.DEBUG)
|
||||
.build()
|
||||
)
|
||||
|
||||
# 构造请求对象
|
||||
|
||||
request: ReplyMessageRequest = (
|
||||
ReplyMessageRequest.builder()
|
||||
.message_id(message_id)
|
||||
.request_body(
|
||||
ReplyMessageRequestBody.builder()
|
||||
.content(content=content)
|
||||
.msg_type("text")
|
||||
.reply_in_thread(True)
|
||||
.build()
|
||||
)
|
||||
.build()
|
||||
)
|
||||
|
||||
# 发起请求
|
||||
response: CreateMessageResponse = client.im.v1.message.create(request)
|
||||
|
||||
# 处理失败返回
|
||||
if not response.success():
|
||||
lark.logger.error(
|
||||
f"client.im.v1.message.create failed, code: {response.code}, msg: {response.msg}, log_id: {response.get_log_id()}, resp: \n{json.dumps(json.loads(response.raw.content), indent=4, ensure_ascii=False)}"
|
||||
)
|
||||
return
|
||||
|
||||
# 处理业务结果
|
||||
lark.logger.info(lark.JSON.marshal(response.data, indent=4))
|
||||
Reference in new issue
Block a user