from agno.agent import Agent from agno.models.google import Gemini from agno.tools.whatsapp import WhatsAppTools agent = Agent( name="whatsapp", model=Gemini(id="gemini-2.0-flash"), tools=[WhatsAppTools()], ) # 示例:发送模板消息 # 注意:将 '''hello_world''' 替换为你的实际模板名称 agent.print_response( "使用英文模板 '''hello_world''' 向 +91 1234567890 发送模板消息" )
创建虚拟环境
打开 Terminal 并创建一个 python 虚拟环境。
Terminal
python3 -m venv .venv source .venv/bin/activate
设置 WhatsApp Business API
设置你的 API 密钥和标识符
export WHATSAPP_ACCESS_TOKEN=xxx export WHATSAPP_PHONE_NUMBER_ID=xxx export OPENAI_API_KEY=xxx # 或你偏好的 LLM API 密钥
安装库
pip install -U agno openai google-generativeai # 添加任何其他必要的 WhatsApp SDK
运行 Agent
python cookbook/tools/whatsapp_tools.py