|
| 1 | +--- |
| 2 | +title: "WhatsApp MCP Integration" |
| 3 | +sidebarTitle: "WhatsApp" |
| 4 | +description: "Guide for integrating WhatsApp messaging with PraisonAI agents using MCP" |
| 5 | +icon: "whatsapp" |
| 6 | +--- |
| 7 | + |
| 8 | +## Add WhatsApp Tool to AI Agent |
| 9 | + |
| 10 | +```mermaid |
| 11 | +flowchart LR |
| 12 | + In[In] --> Agent[AI Agent] |
| 13 | + Agent --> Tool[WhatsApp MCP] |
| 14 | + Tool --> Agent |
| 15 | + Agent --> Out[Out] |
| 16 | + |
| 17 | + style In fill:#8B0000,color:#fff |
| 18 | + style Agent fill:#2E8B57,color:#fff |
| 19 | + style Tool fill:#25D366,color:#fff |
| 20 | + style Out fill:#8B0000,color:#fff |
| 21 | +``` |
| 22 | + |
| 23 | +## Quick Start |
| 24 | + |
| 25 | +<Steps> |
| 26 | + <Step title="Set Up WhatsApp MCP Server"> |
| 27 | + Clone and set up the WhatsApp MCP server: |
| 28 | + ```bash |
| 29 | + git clone https://github.com/lharries/whatsapp-mcp.git |
| 30 | + cd whatsapp-mcp |
| 31 | + cd whatsapp-bridge |
| 32 | + go run main.go |
| 33 | + ``` |
| 34 | + </Step> |
| 35 | + <Step title="Create a file"> |
| 36 | + Create a new file `whatsapp_message.py` with the following code: |
| 37 | + ```python |
| 38 | + from praisonaiagents import Agent, MCP |
| 39 | + |
| 40 | + whatsapp_agent = Agent( |
| 41 | + instructions="Whatsapp Agent", |
| 42 | + llm="gpt-4o-mini", |
| 43 | + tools=MCP("python /path/to/whatsapp-mcp/whatsapp-mcp-server/main.py") |
| 44 | + ) |
| 45 | + |
| 46 | + whatsapp_agent.start("Send Hello to Mervin Praison") |
| 47 | + ``` |
| 48 | + |
| 49 | + Note: Replace `/path/to/whatsapp-mcp` with the actual path to your WhatsApp MCP server. |
| 50 | + </Step> |
| 51 | + |
| 52 | + <Step title="Install Dependencies"> |
| 53 | + Make sure you have the required packages installed: |
| 54 | + ```bash |
| 55 | + pip install "praisonaiagents[llm]" mcp gradio |
| 56 | + ``` |
| 57 | + </Step> |
| 58 | + <Step title="Export API Key"> |
| 59 | + ```bash |
| 60 | + export OPENAI_API_KEY="your_api_key" |
| 61 | + ``` |
| 62 | + </Step> |
| 63 | + |
| 64 | + <Step title="Run the Agent"> |
| 65 | + Execute your script: |
| 66 | + ```bash |
| 67 | + python whatsapp_message.py |
| 68 | + ``` |
| 69 | + </Step> |
| 70 | +</Steps> |
| 71 | + |
| 72 | +<Note> |
| 73 | + **Requirements** |
| 74 | + - Python 3.10 or higher |
| 75 | + - WhatsApp MCP server set up and configured |
| 76 | +</Note> |
| 77 | + |
| 78 | +## Multi-Agent Integration |
| 79 | + |
| 80 | +You can also combine WhatsApp with other MCP tools, such as Airbnb search: |
| 81 | + |
| 82 | +```python |
| 83 | +from praisonaiagents import Agent, Agents, MCP |
| 84 | + |
| 85 | +airbnb_agent = Agent( |
| 86 | + instructions="""Search for Apartments in Paris for 2 nights on Airbnb. 04/28 - 04/30 for 2 adults""", |
| 87 | + llm="gpt-4o-mini", |
| 88 | + tools=MCP("npx -y @openbnb/mcp-server-airbnb --ignore-robots-txt") |
| 89 | +) |
| 90 | + |
| 91 | +whatsapp_agent = Agent( |
| 92 | + instructions="""Send AirBnb Search Result to 'Mervin Praison'""", |
| 93 | + llm="gpt-4o-mini", |
| 94 | + tools=MCP("python /path/to/whatsapp-mcp/whatsapp-mcp-server/main.py") |
| 95 | +) |
| 96 | + |
| 97 | +agents = Agents(agents=[airbnb_agent, whatsapp_agent]) |
| 98 | + |
| 99 | +agents.start() |
| 100 | +``` |
| 101 | + |
| 102 | +## Alternative LLM Integrations |
| 103 | + |
| 104 | +### Using Groq with WhatsApp |
| 105 | + |
| 106 | +```python |
| 107 | +from praisonaiagents import Agent, MCP |
| 108 | + |
| 109 | +whatsapp_agent = Agent( |
| 110 | + instructions="Whatsapp Agent", |
| 111 | + llm="groq/llama-3.2-90b-vision-preview", |
| 112 | + tools=MCP("python /path/to/whatsapp-mcp/whatsapp-mcp-server/main.py") |
| 113 | +) |
| 114 | + |
| 115 | +whatsapp_agent.start("Send Hello to Mervin Praison") |
| 116 | +``` |
| 117 | + |
| 118 | +### Using Ollama with WhatsApp |
| 119 | + |
| 120 | +```python |
| 121 | +from praisonaiagents import Agent, MCP |
| 122 | + |
| 123 | +whatsapp_agent = Agent( |
| 124 | + instructions="Whatsapp Agent", |
| 125 | + llm="ollama/llama3.2", |
| 126 | + tools=MCP("python /path/to/whatsapp-mcp/whatsapp-mcp-server/main.py") |
| 127 | +) |
| 128 | + |
| 129 | +whatsapp_agent.start("Send Hello to Mervin Praison. Use send_message tool, recipient and message are the required parameters.") |
| 130 | +``` |
| 131 | + |
| 132 | +## Gradio UI Integration |
| 133 | + |
| 134 | +Create a Gradio UI for your WhatsApp and Airbnb integration: |
| 135 | + |
| 136 | +```python |
| 137 | +from praisonaiagents import Agent, Agents, MCP |
| 138 | +import gradio as gr |
| 139 | + |
| 140 | +def search_airbnb(query): |
| 141 | + airbnb_agent = Agent( |
| 142 | + instructions=query+" on Airbnb", |
| 143 | + llm="gpt-4o-mini", |
| 144 | + tools=MCP("npx -y @openbnb/mcp-server-airbnb --ignore-robots-txt") |
| 145 | + ) |
| 146 | + |
| 147 | + whatsapp_agent = Agent( |
| 148 | + instructions="""Send AirBnb Search Result to 'Mervin Praison'. Don't include Phone Number in Response, but include the AirBnb Search Result""", |
| 149 | + llm="gpt-4o-mini", |
| 150 | + tools=MCP("python /path/to/whatsapp-mcp/whatsapp-mcp-server/main.py") |
| 151 | + ) |
| 152 | + |
| 153 | + agents = Agents(agents=[airbnb_agent, whatsapp_agent]) |
| 154 | + |
| 155 | + result = agents.start() |
| 156 | + return f"## Airbnb Search Results\n\n{result}" |
| 157 | + |
| 158 | +demo = gr.Interface( |
| 159 | + fn=search_airbnb, |
| 160 | + inputs=gr.Textbox(placeholder="I want to book an apartment in Paris for 2 nights..."), |
| 161 | + outputs=gr.Markdown(), |
| 162 | + title="WhatsApp MCP Agent", |
| 163 | + description="Enter your booking requirements below:" |
| 164 | +) |
| 165 | + |
| 166 | +if __name__ == "__main__": |
| 167 | + demo.launch() |
| 168 | +``` |
| 169 | + |
| 170 | +## Features |
| 171 | + |
| 172 | +<CardGroup cols={2}> |
| 173 | + <Card title="WhatsApp Messaging" icon="message"> |
| 174 | + Send messages to WhatsApp contacts directly from your AI agent. |
| 175 | + </Card> |
| 176 | + <Card title="Multi-Agent Support" icon="users"> |
| 177 | + Combine WhatsApp with other MCP tools for complex workflows. |
| 178 | + </Card> |
| 179 | + <Card title="Multiple LLM Options" icon="brain"> |
| 180 | + Use with OpenAI, Groq, Ollama, or other supported LLMs. |
| 181 | + </Card> |
| 182 | + <Card title="Gradio UI" icon="window"> |
| 183 | + Create user-friendly interfaces for your WhatsApp integrations. |
| 184 | + </Card> |
| 185 | +</CardGroup> |
0 commit comments