企业微信应用号-发送语音消息
wework_app_send_voiceSend voice messages to WeWork app users by providing a voice URL. Supports specifying recipients or broadcasting to all members.
Instructions
通过企业微信应用号发送发送语音消息
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| url | Yes | 语音URL | |
| touser | No | 接收消息的成员ID,多个用`|`分隔,为`@all`时向该企业应用全部成员发送,默认从环境变量获取 |
Implementation Reference
- mcp_notify/wework.py:148-152 (handler)Handler function for the wework_app_send_voice tool. Accepts a voice URL and optional touser, delegates to the wework_send_media helper with msgtype='voice'.
def wework_app_send_voice( url: str = Field(description="语音URL"), touser: str = FIELD_TO_USER, ): return wework_send_media(touser, url, "voice") - mcp_notify/wework.py:164-197 (helper)Helper function that downloads media from a URL, uploads it to WeChat Work to get a media_id, then sends a message with that media_id as voice/image/video/file.
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/wework.py:148-151 (schema)Schema/parameters for the wework_app_send_voice tool: url (str, required) and touser (str, optional, defaults to env variable).
def wework_app_send_voice( url: str = Field(description="语音URL"), touser: str = FIELD_TO_USER, ): - mcp_notify/wework.py:144-147 (registration)Registration of wework_app_send_voice as an MCP tool with title and description, decorated on the handler function.
@mcp.tool( title="企业微信应用号-发送语音消息", description="通过企业微信应用号发送发送语音消息", )