企业微信应用号-发送文件消息
wework_app_send_fileSend file messages to WeWork members via corporate app. Provide a file URL and optionally specify recipient IDs or send to all.
Instructions
通过企业微信应用号发送发送文件消息
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| url | Yes | 文件URL | |
| touser | No | 接收消息的成员ID,多个用`|`分隔,为`@all`时向该企业应用全部成员发送,默认从环境变量获取 |
Implementation Reference
- mcp_notify/wework.py:154-162 (handler)Handler function for the 'wework_app_send_file' tool. Decorated with @mcp.tool. Accepts a file URL and optional touser, then delegates to wework_send_media() with msgtype='file'.
@mcp.tool( title="企业微信应用号-发送文件消息", description="通过企业微信应用号发送发送文件消息", ) def wework_app_send_file( url: str = Field(description="文件URL"), touser: str = FIELD_TO_USER, ): return wework_send_media(touser, url, "file") - mcp_notify/wework.py:164-197 (helper)Helper function that downloads media from a URL, uploads it to WeWork's media API to get a media_id, then sends it as a message via the WeWork app. Used by wework_app_send_file (and wework_app_send_image/video/voice).
def wework_send_media(touser, url: str, msgtype=None): if msgtype: pass elif '.jpg' in url.lower() or '.jpeg' in url.lower() or '.png' in url.lower(): msgtype = 'image' elif '.mp4' in url.lower(): msgtype = 'video' elif '.arm' in url.lower(): msgtype = 'voice' else: msgtype = 'file' res = requests.get(url, timeout=120) res.raise_for_status() file = io.BytesIO(res.content) mine = res.headers.get("content-type") or "application/octet-stream" res = requests.post( f"{WEWORK_BASE_URL}/cgi-bin/media/upload", params={"type": msgtype, "access_token": get_access_token()}, files={"media": ("filename", file, mine)}, timeout=120, ) media = res.json() or {} if not (media_id := media.get("media_id")): return media res = requests.post( f"{WEWORK_BASE_URL}/cgi-bin/message/send?access_token={get_access_token()}", json={ "touser": touser or WEWORK_APP_TOUSER, "agentid": WEWORK_APP_AGENTID, "msgtype": msgtype, msgtype: {"media_id": media_id}, }, ) return res.json() - mcp_notify/__init__.py:7-23 (registration)Tool registration entry point. The wework module is imported and its add_tools(mcp) function is called in __init__.py, which registers all wework tools (including wework_app_send_file) onto the FastMCP server.
from . import ( wework, tgbot, other, hass, util, ) _LOGGER = logging.getLogger(__name__) mcp = FastMCP(name="mcp-notify", version="0.1.11") wework.add_tools(mcp) tgbot.add_tools(mcp) other.add_tools(mcp) hass.add_tools(mcp) util.add_tools(mcp) - mcp_notify/wework.py:21-23 (registration)The wework.add_tools() function that registers all tools including wework_app_send_file onto the FastMCP instance via the @mcp.tool decorator.
def add_tools(mcp: FastMCP, logger=None): @mcp.tool(