ForcePilot/backend/package/yuxi/channel/extensions/whatsapp/actions.py
Kris 7215418610 feat(channel): 添加企业微信、微博、WhatsApp 和 Workplace 渠道扩展
新增企业微信、微博、WhatsApp、Workplace 四个渠道扩展。

企业微信渠道扩展主要模块:config, gateway, webhook, webhook_bot, outbound, streaming, pairing, security, crypto, dedupe, persistent_dedupe, card, directory, events, externalcontact, media, mentions, menu, message, oauth, status

微博渠道扩展主要模块:config, gateway, webhook, outbound, streaming, pairing, security, dedupe, passive_reply, broadcast, message, menu, media, subscription, template, status

WhatsApp 渠道扩展主要模块:config, gateway, webhook, outbound, streaming, pairing, security, dedupe, actions, monitor, status

Workplace 渠道扩展主要模块:config, gateway, webhook, outbound, streaming, pairing, security, dedupe, actions, challenge, groups, media, mentions, menu, monitor, persona, quick_reply, signature, subscriptions, template, threading, users, status
2026-05-21 12:01:56 +08:00

67 lines
3.2 KiB
Python

"""WhatsApp Actions 适配器 — 消息动作声明"""
from yuxi.channel.protocols import AgentToolParam, MessageActionCapability
class WhatsAppActions:
def get_message_actions(self) -> list[MessageActionCapability]:
return [
MessageActionCapability(
action="send",
description="Send a text message to a WhatsApp chat",
parameters=[
AgentToolParam(name="to", type="string", description="Recipient E.164 number", required=True),
AgentToolParam(name="text", type="string", description="Message content", required=True),
],
scope="current_channel",
),
MessageActionCapability(
action="send_media",
description="Send a media file to a WhatsApp chat",
parameters=[
AgentToolParam(name="to", type="string", description="Recipient E.164 number", required=True),
AgentToolParam(name="media_url", type="string", description="Media file URL", required=True),
AgentToolParam(name="media_type", type="string", description="Media type: image/video/audio/document", required=True),
],
scope="current_channel",
),
MessageActionCapability(
action="react",
description="Add an emoji reaction to a WhatsApp message",
parameters=[
AgentToolParam(name="message_id", type="string", description="Target message ID", required=True),
AgentToolParam(name="emoji", type="string", description="Emoji character", required=True),
],
scope="current_channel",
),
MessageActionCapability(
action="poll_create",
description="Create a poll in a WhatsApp chat (max 12 options)",
parameters=[
AgentToolParam(name="title", type="string", description="Poll title", required=True),
AgentToolParam(name="options", type="string", description="Comma-separated options", required=True),
],
scope="current_channel",
),
]
async def execute_message_action(self, action: str, params: dict, context: dict) -> dict:
match action:
case "send":
return {"success": True, "result": {"action": "send", "params": params}}
case "send_media":
return {"success": True, "result": {"action": "send_media", "params": params}}
case "react":
return {"success": True, "result": {"action": "react", "params": params}}
case "poll_create":
options = params.get("options", "").split(",")[:12]
return {"success": True, "result": {"action": "poll_create", "options": options}}
case "poll_close":
return {"success": True, "result": {"action": "poll_close"}}
case _:
return {"success": False, "error": f"Unsupported action: {action}"}
def supports_action(self, action: str) -> bool:
return action in ("send", "send_media", "react", "poll_create", "poll_close")