Skill: 05u/jiuwu-message (version 1.0.1)

--- name: jiuwu-message description: 调用久吾消息网关HTTP接口给企业内部联系人发送消息。适用于：(1) 需要向企业内部同事发送通知或提醒时，(2) 需要批量发送内部消息时。当用户要求发送内部通知、提醒同事、向企业员工发消息、或调用消息网关时触发。 --- # 久吾消息网关 调用久吾消息网关发送企业内部消息。 ## 环境配置 网关地址从环境变量 `JIUWU_MESSAGE_GATEWAY_URL` 读取，默认为 `http://192.168.1.213:5000`。可在 `~/.openclaw/workspace/.env` 或 `~/.openclaw/.env` 中配置。 ## 脚本调用（优先使用） **始终使用 `scripts/send_message.py`，不要直接 HTTP 请求。** ### 命令行调用 ```bash python scripts/send_message.py -c "工号" -t "消息内容" [-tt "标题"] ``` 示例： ```bash python scripts/send_message.py -c "1112" -t "您的报销单已审批通过" -tt "报销提醒" ``` ### 批量发送 多个工号用英文逗号分隔： ```bash python scripts/send_message.py -c "1112,1113,1114" -t "会议通知：今天下午2点开会" -tt "会议提醒" ``` ### Python 代码调用 ```python import sys sys.path.insert(0, 'skills/jiuwu-message/scripts') from send_message import send_message result = send_message( code="1112,1113", text="消息内容", title="可选标题" ) ``` ## 参数说明 | 参数 | 缩写 | 必填 | 说明 | |-----|-----|-----|------| | `--code` | `-c` | 是 | 接收人工号，多个用英文逗号分隔 | | `--text` | `-t` | 是 | 消息内容 | | `--title` | `-tt` | 否 | 消息标题 | ## 响应格式 ```json { "success": true, "data": true, "message": "请求成功" } ``` 失败时 `success` 为 `false`，`message` 包含错误信息。

path: scripts/requirements.txt
content: # 无额外依赖，仅使用Python标准库 (urllib, json, pathlib, argparse)


path: scripts/send_message.py
content: #!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""
久吾消息网关发送消息脚本
"""

import os
import sys
import json
import argparse
import urllib.request
import urllib.error
from pathlib import Path

# 修复 Windows 控制台 UTF-8 输出乱码
sys.stdout.reconfigure(encoding='utf-8')
sys.stderr.reconfigure(encoding='utf-8')


def load_openclaw_env():
    """加载OpenClaw的.env配置文件"""
    env_paths = [
        Path.home() / ".openclaw" / "workspace" / ".env",
        Path.home() / ".openclaw" / ".env",
    ]

    for env_path in env_paths:
        if env_path.exists():
            with open(env_path, 'r', encoding='utf-8') as f:
                for line in f:
                    line = line.strip()
                    if line and not line.startswith('#') and '=' in line:
                        key, value = line.split('=', 1)
                        os.environ.setdefault(key, value)


def get_gateway_url():
    """获取消息网关服务器地址"""
    load_openclaw_env()
    return os.environ.get("JIUWU_MESSAGE_GATEWAY_URL", "http://192.168.1.213:5000")


def send_message(code: str, text: str, title: str = None, timeout: int = 30) -> dict:
    """
    发送消息到久吾消息网关

    Args:
        code: 接收人工号，多个工号用英文逗号分隔
        text: 消息内容
        title: 消息标题（可选）
        timeout: 超时时间（秒，默认30）

    Returns:
        dict: 包含 success, data, message 字段的响应
    """
    gateway_url = get_gateway_url()
    url = f"{gateway_url}/api/MessageGateway/SendMessagePost"

    payload = {
        "code": code,
        "text": text
    }
    if title:
        payload["title"] = title

    data = json.dumps(payload).encode('utf-8')
    req = urllib.request.Request(
        url,
        data=data,
        headers={
            'accept': 'text/plain',
            'Content-Type': 'application/json-patch+json'
        },
        method='POST'
    )

    try:
        with urllib.request.urlopen(req, timeout=timeout) as response:
            result = json.loads(response.read().decode('utf-8'))
            return result
    except urllib.error.HTTPError as e:
        return {
            "success": False,
            "data": None,
            "message": f"HTTP错误: {e.code} - {e.reason}"
        }
    except urllib.error.URLError as e:
        return {
            "success": False,
            "data": None,
            "message": f"连接失败: {e.reason}"
        }
    except Exception as e:
        return {
            "success": False,
            "data": None,
            "message": f"发生异常: {str(e)}"
        }


def main():
    parser = argparse.ArgumentParser(description="久吾消息网关发送消息")
    parser.add_argument("-c", "--code", required=True, help="接收人工号，多个用英文逗号分隔")
    parser.add_argument("-t", "--text", required=True, help="消息内容")
    parser.add_argument("-tt", "--title", default=None, help="消息标题（可选）")
    parser.add_argument("--timeout", type=int, default=30, help="超时时间（秒，默认30）")

    args = parser.parse_args()

    result = send_message(code=args.code, text=args.text, title=args.title, timeout=args.timeout)

    print(json.dumps(result, ensure_ascii=False, indent=2))

    sys.exit(0 if result.get("success") else 1)


if __name__ == "__main__":
    main()


path: scripts/__init__.py
content: from .send_message import send_message

__all__ = ["send_message"]


Security scan verdicts — ClawScan: clean | static analysis: clean | VirusTotal: clean | SkillSpector: suspicious (HIGH)