This commit is contained in:
1 parent
bf678baf48
commit
8980fdab57
3 files changed
+35
-6
No files matched your search
+2
-1
@@ -171,8 +171,9 @@ def do_card_action_trigger(data: P2CardActionTrigger) -> P2CardActionTriggerResp
|
||||
# data = json.loads(lark.JSON.marshal(data))
|
||||
open_id = data.event.operator.open_id
|
||||
activity_name = data.event.action.form_value.get("select_activity")
|
||||
open_message_id = data.event.context.open_message_id
|
||||
|
||||
process_push_xbot_activity_bot.delay(activity_name, open_id)
|
||||
process_push_xbot_activity_bot.delay(activity_name, open_id, open_message_id)
|
||||
resp = {"toast": {"type": "info", "content": "提交成功, 机器人即将推送"}}
|
||||
return P2CardActionTriggerResponse(resp)
|
||||
|
||||
|
||||
+2
-2
@@ -408,5 +408,5 @@ def process_new_robot(app_id, app_secret, action_data):
|
||||
|
||||
|
||||
@shared_task(include_result=False)
|
||||
def process_push_xbot_activity_bot(activity_code, open_id):
|
||||
push_xbot_activity_bot(activity_code, open_id)
|
||||
def process_push_xbot_activity_bot(activity_code, open_id, open_message_id):
|
||||
push_xbot_activity_bot(activity_code, open_id, open_message_id)
|
||||
+31
-3
@@ -259,7 +259,7 @@ def package_activity(token, robot_uuid, basedir):
|
||||
return activity_save_path
|
||||
|
||||
|
||||
def send_message(file_path, open_id):
|
||||
def send_message(file_path, open_id, open_message_id):
|
||||
"""发送指令文件到指定用户"""
|
||||
# 创建client
|
||||
|
||||
@@ -327,8 +327,36 @@ def send_message(file_path, open_id):
|
||||
# 处理业务结果
|
||||
lark.logger.info(lark.JSON.marshal(response.data, indent=4))
|
||||
|
||||
# 推送下载成功
|
||||
content = {"text": "指令包已推送,请通过应用机器人点击下载"}
|
||||
request: ReplyMessageRequest = (
|
||||
ReplyMessageRequest.builder()
|
||||
.message_id(open_message_id)
|
||||
.request_body(
|
||||
ReplyMessageRequestBody.builder()
|
||||
.content(content=json.dumps(content))
|
||||
.msg_type("text")
|
||||
.reply_in_thread(True)
|
||||
.build()
|
||||
)
|
||||
.build()
|
||||
)
|
||||
|
||||
def push_xbot_activity_bot(activity_code, open_id):
|
||||
# 发起请求
|
||||
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))
|
||||
|
||||
|
||||
def push_xbot_activity_bot(activity_code, open_id, open_message_id):
|
||||
"""自动推送官方指令bot包到指定用户
|
||||
:param activity_code: 指令代码带版本号
|
||||
:param open_id: 接收者open_id
|
||||
@@ -348,7 +376,7 @@ def push_xbot_activity_bot(activity_code, open_id):
|
||||
activity_path = package_activity(
|
||||
token=token, robot_uuid=activity_code, basedir=base_dir
|
||||
)
|
||||
send_message(activity_path, open_id)
|
||||
send_message(activity_path, open_id, open_message_id)
|
||||
|
||||
|
||||
def get_office_activity_names_with_viewname(token):
|
||||
|
||||
Reference in new issue
Block a user