support standalone (.shr) activity download via form version
ci/woodpecker/push/woodpecker Pipeline was successful
ci/woodpecker/push/woodpecker Pipeline was successful
Branch download by the card form 'version' field: standalone packs a flat .shr (no xbot_robot/xbot_extensions, no internal deps), private keeps the current .bot. Also enable kaniko layer cache to skip pip install on code-only builds. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This commit is contained in:
1 parent
8b587414d0
commit
432482b53b
4 files changed
+52
-7
No files matched your search
@@ -16,6 +16,8 @@ steps:
|
|||||||
tags: latest
|
tags: latest
|
||||||
repo: woni/office-xbot-feishu
|
repo: woni/office-xbot-feishu
|
||||||
registry: registry.woni.link
|
registry: registry.woni.link
|
||||||
|
cache: true
|
||||||
|
cache_repo: woni/office-xbot-feishu-cache
|
||||||
mirrors:
|
mirrors:
|
||||||
- 5c492fmo.mirror.aliyuncs.com
|
- 5c492fmo.mirror.aliyuncs.com
|
||||||
dockerfile: ./Dockerfile
|
dockerfile: ./Dockerfile
|
||||||
|
|||||||
+4
-1
@@ -166,9 +166,12 @@ def do_card_action_trigger(data: P2CardActionTrigger) -> P2CardActionTriggerResp
|
|||||||
# data = json.loads(lark.JSON.marshal(data))
|
# data = json.loads(lark.JSON.marshal(data))
|
||||||
open_id = data.event.operator.open_id
|
open_id = data.event.operator.open_id
|
||||||
activity_name = data.event.action.form_value.get("select_activity")
|
activity_name = data.event.action.form_value.get("select_activity")
|
||||||
|
package_type = data.event.action.form_value.get("version") or "private"
|
||||||
open_message_id = data.event.context.open_message_id
|
open_message_id = data.event.context.open_message_id
|
||||||
|
|
||||||
process_push_xbot_activity_bot.delay(activity_name, open_id, open_message_id)
|
process_push_xbot_activity_bot.delay(
|
||||||
|
activity_name, open_id, open_message_id, package_type
|
||||||
|
)
|
||||||
resp = {"toast": {"type": "info", "content": "提交成功, 机器人即将推送"}}
|
resp = {"toast": {"type": "info", "content": "提交成功, 机器人即将推送"}}
|
||||||
return P2CardActionTriggerResponse(resp)
|
return P2CardActionTriggerResponse(resp)
|
||||||
|
|
||||||
|
|||||||
+4
-2
@@ -369,5 +369,7 @@ def process_new_robot(app_id, app_secret, action_data):
|
|||||||
|
|
||||||
|
|
||||||
@shared_task(include_result=False)
|
@shared_task(include_result=False)
|
||||||
def process_push_xbot_activity_bot(activity_code, open_id, open_message_id):
|
def process_push_xbot_activity_bot(
|
||||||
push_xbot_activity_bot(activity_code, open_id, open_message_id)
|
activity_code, open_id, open_message_id, package_type="private"
|
||||||
|
):
|
||||||
|
push_xbot_activity_bot(activity_code, open_id, open_message_id, package_type)
|
||||||
+42
-4
@@ -259,6 +259,38 @@ def package_activity(token, robot_uuid, basedir):
|
|||||||
return activity_save_path
|
return activity_save_path
|
||||||
|
|
||||||
|
|
||||||
|
def package_standalone_activity(token, robot_uuid, basedir):
|
||||||
|
"""
|
||||||
|
根据 uuid 将指令打包成单机版 shr 文件, 并存到指定的文件中
|
||||||
|
单机版不需要 xbot_robot/xbot_extensions 目录结构, 也不下载 internal 依赖,
|
||||||
|
直接将包解压后改版本号, 压缩成 .shr
|
||||||
|
:param token:
|
||||||
|
:param robot_uuid:
|
||||||
|
:param basedir: 文件存放路径
|
||||||
|
"""
|
||||||
|
activity_detail = get_activity_detail(token=token, sdk_uuid=robot_uuid)
|
||||||
|
activity_name = activity_detail.get("name")
|
||||||
|
version = activity_detail.get("releaseVersion")
|
||||||
|
packageUrl = activity_detail.get("packageUrl")
|
||||||
|
|
||||||
|
logger.info(f"打包单机版指令: {activity_name}")
|
||||||
|
|
||||||
|
# 去除不能作为windows文件名的字符
|
||||||
|
activity_name = sanitize_filename(activity_name, "")
|
||||||
|
|
||||||
|
activity_path = os.path.join(basedir, activity_name)
|
||||||
|
os.makedirs(activity_path)
|
||||||
|
download_name = download_file(packageUrl, activity_path, "xbot_robot.zip")
|
||||||
|
unzip_file(download_name, activity_path)
|
||||||
|
os.remove(download_name)
|
||||||
|
modify_package_version(activity_path, version)
|
||||||
|
|
||||||
|
activity_save_path = zip_file(activity_path, f"{activity_path}.shr")
|
||||||
|
|
||||||
|
shutil.rmtree(activity_path)
|
||||||
|
return activity_save_path
|
||||||
|
|
||||||
|
|
||||||
def send_message(file_path, open_id, open_message_id):
|
def send_message(file_path, open_id, open_message_id):
|
||||||
"""发送指令文件到指定用户"""
|
"""发送指令文件到指定用户"""
|
||||||
# 创建client
|
# 创建client
|
||||||
@@ -356,10 +388,11 @@ def send_message(file_path, open_id, open_message_id):
|
|||||||
lark.logger.info(lark.JSON.marshal(response.data, indent=4))
|
lark.logger.info(lark.JSON.marshal(response.data, indent=4))
|
||||||
|
|
||||||
|
|
||||||
def push_xbot_activity_bot(activity_code, open_id, open_message_id):
|
def push_xbot_activity_bot(activity_code, open_id, open_message_id, package_type="private"):
|
||||||
"""自动推送官方指令bot包到指定用户
|
"""自动推送官方指令bot包到指定用户
|
||||||
:param activity_code: 指令代码带版本号
|
:param activity_code: 指令代码带版本号
|
||||||
:param open_id: 接收者open_id
|
:param open_id: 接收者open_id
|
||||||
|
:param package_type: 打包类型, private(联机版, .bot) 或 standalone(单机版, .shr)
|
||||||
"""
|
"""
|
||||||
username = "剑心@fckj"
|
username = "剑心@fckj"
|
||||||
password = "320753691love"
|
password = "320753691love"
|
||||||
@@ -373,9 +406,14 @@ def push_xbot_activity_bot(activity_code, open_id, open_message_id):
|
|||||||
|
|
||||||
base_dir = os.path.dirname(os.path.realpath(__file__))
|
base_dir = os.path.dirname(os.path.realpath(__file__))
|
||||||
|
|
||||||
activity_path = package_activity(
|
if package_type == "standalone":
|
||||||
token=token, robot_uuid=activity_code, basedir=base_dir
|
activity_path = package_standalone_activity(
|
||||||
)
|
token=token, robot_uuid=activity_code, basedir=base_dir
|
||||||
|
)
|
||||||
|
else:
|
||||||
|
activity_path = package_activity(
|
||||||
|
token=token, robot_uuid=activity_code, basedir=base_dir
|
||||||
|
)
|
||||||
send_message(activity_path, open_id, open_message_id)
|
send_message(activity_path, open_id, open_message_id)
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Reference in new issue
Block a user