企业微信群机器人-发送图片消息
wework_send_imageSend image messages to WeChat Work (WeWork) group chat using a robot. Provide the image URL and optional bot key to notify your team.
Instructions
通过企业微信群机器人发送图片消息
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| url | Yes | 图片url | |
| bot_key | No | 企业微信群机器人key,uuid格式,默认从环境变量获取 |
Implementation Reference
- mcp_notify/wework.py:41-58 (handler)The handler function for the 'wework_send_image' MCP tool. It downloads an image from a URL, converts it to base64, computes its MD5 hash, and sends it to a WeWork group robot via webhook.
@mcp.tool( title="企业微信群机器人-发送图片消息", description="通过企业微信群机器人发送图片消息", ) def wework_send_image( url: str = Field(description="图片url"), bot_key: str = FIELD_BOT_KEY, ): res = requests.get(url, timeout=120) res.raise_for_status() b64str = base64.b64encode(res.content).decode() md5str = hashlib.md5(res.content).hexdigest() res = requests.post( f"{WEWORK_BASE_URL}/cgi-bin/webhook/send?key={bot_key or WEWORK_BOT_KEY}", json={"msgtype": "image", "image": {"base64": b64str, "md5": md5str}}, timeout=120, ) return res.json() - mcp_notify/wework.py:45-47 (schema)Input schema for wework_send_image: takes a URL string for the image and an optional bot_key (defaulting from environment variable).
def wework_send_image( url: str = Field(description="图片url"), bot_key: str = FIELD_BOT_KEY, - mcp_notify/wework.py:17-48 (handler)Helper field definition reused across WeWork bot tools, providing the bot_key parameter schema with default from env.
FIELD_BOT_KEY = Field("", description="企业微信群机器人key,uuid格式,默认从环境变量获取") FIELD_TO_USER = Field("", description="接收消息的成员ID,多个用`|`分隔,为`@all`时向该企业应用全部成员发送,默认从环境变量获取") def add_tools(mcp: FastMCP, logger=None): @mcp.tool( title="企业微信群机器人-发送文本消息", description="通过企业微信群机器人发送文本或Markdown消息", ) def wework_send_text( text: str = Field(description="消息内容,长度限制: (text: 2048个字节, markdown_v2: 4096个字节)"), msgtype: str = Field("text", description="内容类型,仅支持: text/markdown_v2"), bot_key: str = FIELD_BOT_KEY, ): if msgtype == "markdown": msgtype = "markdown_v2" res = requests.post( f"{WEWORK_BASE_URL}/cgi-bin/webhook/send?key={bot_key or WEWORK_BOT_KEY}", json={"msgtype": msgtype, msgtype: {"content": text}}, ) return res.json() @mcp.tool( title="企业微信群机器人-发送图片消息", description="通过企业微信群机器人发送图片消息", ) def wework_send_image( url: str = Field(description="图片url"), bot_key: str = FIELD_BOT_KEY, ): - mcp_notify/wework.py:41-44 (registration)Registration of the 'wework_send_image' tool via the @mcp.tool decorator.
@mcp.tool( title="企业微信群机器人-发送图片消息", description="通过企业微信群机器人发送图片消息", ) - mcp_notify/wework.py:21-23 (registration)The add_tools function is called from __init__.py to register all WeWork tools on the MCP server.
def add_tools(mcp: FastMCP, logger=None): @mcp.tool(