wework_app_send_image
Send image messages through WeWork application accounts to specified users or entire organizations using image URLs.
Instructions
通过企业微信应用号发送发送图片消息
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| url | Yes | 图片URL | |
| touser | No | 接收消息的成员ID,多个用`|`分隔,为`@all`时向该企业应用全部成员发送,默认从环境变量获取 |
Implementation Reference
- mcp_notify/wework.py:127-135 (handler)The @mcp.tool decorator registers the 'wework_app_send_image' tool with title, description, and input schema (url and touser parameters). The handler function fetches the image from URL and delegates to wework_send_media.@mcp.tool( title="企业微信应用号-发送图片消息", description="通过企业微信应用号发送发送图片消息", ) def wework_app_send_image( url: str = Field(description="图片URL"), touser: str = FIELD_TO_USER, ): return wework_send_media(touser, url, "image")
- mcp_notify/wework.py:167-200 (helper)The wework_send_media helper function implements the core logic: downloads media from URL, determines type, uploads to WeWork media API using get_access_token, then sends the message via the app API.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:19-19 (registration)High-level registration: calls wework.add_tools(mcp) after importing modules, which executes the tool definitions and @mcp.tool decorators to register all WeWork tools including wework_app_send_image.wework.add_tools(mcp)
- mcp_notify/wework.py:95-102 (helper)Cached get_access_token function used by wework_send_media to obtain WeWork API access token.@cached(TTLCache(maxsize=1, ttl=3600)) def get_access_token(): res = requests.get( f"{WEWORK_BASE_URL}/cgi-bin/gettoken", params={"corpid": WEWORK_APP_CORPID, "corpsecret": WEWORK_APP_SECRET}, timeout=60, ) return res.json().get("access_token")
- mcp_notify/wework.py:21-21 (schema)Reusable FIELD_TO_USER Pydantic Field definition used in the tool parameters.FIELD_TO_USER = Field("", description="接收消息的成员ID,多个用`|`分隔,为`@all`时向该企业应用全部成员发送,默认从环境变量获取")