# Whatsapp Sms (`syntellect_ai/whatsapp-sms`) Actor

Integrate your AI systems with WhatsApp Business API using the WhatsApp MCP Actor. This tool connects Model Context Protocol (MCP) servers with WhatsApp, enabling AI agents and applications to manage messages programmatically. send and receive messages in whats app

- **URL**: https://apify.com/syntellect_ai/whatsapp-sms.md
- **Developed by:** [christopher athans crow](https://apify.com/syntellect_ai) (community)
- **Categories:** Social media, MCP servers, Automation
- **Features:** Full permissions
- **Stats:** 55 total users, 0 monthly users, 0.0% runs succeeded, 1 bookmarks
- **User rating**: No ratings yet

## Pricing

from $0.70 / 1,000 results

This Actor is paid per event. You are not charged for the Apify platform usage, but only a fixed price for specific events.

Learn more: https://docs.apify.com/actors/running/actors-in-store.md#pay-per-event

## What's an Apify Actor?

An Actor is a serverless cloud program that runs on the Apify platform. It has two run modes.
In Batch mode, an Actor accepts a well-defined JSON input, performs an action which can take anything from a few seconds to a few hours,
and optionally produces a well-defined JSON output, datasets with results, or files in key-value store.
In Standby mode, an Actor provides a web server which can be used as a website, API, or an MCP server.

Apify vocabulary and the platform model are defined once, in the agent quickstart at https://apify.com/agents.md.

## How to integrate an Actor?

If asked about integration, you help developers integrate Actors into their projects.
You adapt to their stack and deliver integrations that are safe, well-documented, and production-ready.

Do not guess an integration path. Every one of them is in the agent quickstart at https://apify.com/agents.md: the Apify MCP server, Agent Skills with the Apify CLI, the JavaScript and Python clients, the REST API, and the account-free path for an agent with no human to sign in. It also carries the rule on stating cost before the first paid run.

For examples already wired to this Actor's own input schema, see the [API](#api) section below.

Each client library has reference documentation the quickstart does not restate: [JavaScript/TypeScript](https://docs.apify.com/api/client/js/docs.md) (`npm install apify-client`) and [Python](https://docs.apify.com/api/client/python/docs.md) (`pip install apify-client`).

# README

## WhatsApp SMS Actor with MCP Support

A powerful Apify Actor that enables WhatsApp messaging through the Message Control Protocol (MCP). This Actor can operate in two modes: sending individual messages or running as an MCP server for AI agent integration.

### Features

- **Two Operation Modes:**
  - **Send Mode**: Send individual WhatsApp messages
  - **Server Mode**: Run as an MCP server for AI agent integration

- **QR Code Authentication**: Secure WhatsApp Web authentication via QR code

- **Session Persistence**: Maintains authenticated sessions across runs

- **REST API**: Full HTTP API for message sending and status checking

- **Dataset Storage**: All messages are stored in Apify datasets for tracking

### Configuration

#### Input Parameters

| Parameter | Type | Description | Required | Default |
|-----------|------|-------------|----------|---------|
| `mode` | string | Operation mode: `send` or `server` | Yes | `send` |
| `phoneNumber` | string | WhatsApp phone number (with country code) | For send mode | `+1234567890` |
| `message` | string | Message text to send | For send mode | - |
| `serverPort` | integer | Port for MCP server | For server mode | `3000` |
| `useQRAuth` | boolean | Enable QR code authentication | No | `true` |

#### Example Input (Send Mode)

```json
{
  "mode": "send",
  "phoneNumber": "+1234567890",
  "message": "Hello from Apify WhatsApp Actor!",
  "useQRAuth": true
}
```

#### Example Input (Server Mode)

```json
{
  "mode": "server",
  "serverPort": 3000,
  "useQRAuth": true
}
```

### Usage

#### Send Mode

1. Configure the input with `mode: "send"`
2. Provide `phoneNumber` and `message`
3. Run the Actor
4. Scan the QR code when prompted (first time only)
5. Message will be sent automatically

#### Server Mode

1. Configure the input with `mode: "server"`
2. Run the Actor
3. Scan the QR code when prompted (first time only)
4. Use the REST API endpoints:

##### API Endpoints

**Health Check**

```bash
GET http://localhost:3000/health
```

**Get QR Code**

```bash
GET http://localhost:3000/api/qr
```

**Send Message**

```bash
POST http://localhost:3000/api/messages/send
Content-Type: application/json

{
  "to": "+1234567890",
  "message": "Hello from WhatsApp MCP!"
}
```

##### cURL Example

```bash
curl -X POST http://localhost:3000/api/messages/send \
  -H "Content-Type: application/json" \
  -d '{"to": "+1234567890", "message": "Hello from WhatsApp MCP Server!"}'
```

### Authentication

#### QR Code Authentication

The Actor uses WhatsApp Web's QR code authentication:

1. **First Run**: A QR code will be displayed in the console
2. **Scan**: Open WhatsApp on your phone → Settings → Linked Devices → Link a Device
3. **Scan the QR code** displayed in the terminal
4. **Session Saved**: The session is stored in the Apify key-value store
5. **Subsequent Runs**: No QR code needed (session persists for ~20 days)

### Integration with AI Agents

#### MCP Client Configuration

Add this to your AI client's configuration file (e.g., Claude Desktop `config.json`):

```json
{
  "mcpServers": {
    "whatsapp": {
      "command": "apify",
      "args": ["run", "--purge"]
    }
  }
}
```

#### Using with AI Prompts

Once configured, AI agents can send WhatsApp messages:

```javascript
// AI agent can invoke:
const response = await client.invoke("send-whatsapp-message", {
  to: "+1234567890",
  message: "Hello, how are you today?"
});
```

### Output

All sent messages are saved to the Apify dataset with the following structure:

```json
{
  "phoneNumber": "+1234567890",
  "message": "Hello from WhatsApp!",
  "status": "sent",
  "timestamp": "2025-11-05T04:00:00.000Z",
  "messageId": "3EB0XXXXX"
}
```

### Local Development

#### Prerequisites

- Node.js >= 20.0.0
- Apify CLI installed
- WhatsApp mobile app

#### Installation

```bash
## Clone the repository
cd whatsapp_sms

## Install dependencies
npm install

## Run locally
apify run
```

#### Running the Actor Locally

**Send Mode:**

```bash
apify run
## Then scan QR code and wait for message to send
```

**Server Mode:**
Set input mode to "server" in `.actor/INPUT.json`, then:

```bash
apify run
## Server will start on http://localhost:3000
```

### Deployment

#### Deploy to Apify Platform

```bash
## Login to Apify
apify login

## Push Actor to platform
apify push
```

### Technical Details

#### Dependencies

- `@whiskeysockets/baileys`: WhatsApp Web API implementation
- `@modelcontextprotocol/sdk`: MCP protocol support
- `express`: HTTP server for REST API
- `qrcode-terminal`: QR code display in terminal
- `pino`: Logging
- `apify`: Apify SDK
- `crawlee`: Web automation framework

#### Session Storage

Authentication sessions are stored in:

- **Local**: `./storage/key_value_stores/default/whatsapp_auth`
- **Cloud**: Apify key-value store (persistent across runs)

#### Architecture

```
┌─────────────────┐
│   Apify Actor   │
└────────┬────────┘
         │
    ┌────┴────┐
    │  Mode?  │
    └────┬────┘
         │
    ┌────┴─────────┐
    │              │
┌───▼───┐    ┌────▼────┐
│ Send  │    │ Server  │
│ Mode  │    │  Mode   │
└───┬───┘    └────┬────┘
    │             │
    │        ┌────▼────┐
    │        │ Express │
    │        │   API   │
    │        └────┬────┘
    │             │
    └─────┬───────┘
          │
    ┌─────▼──────┐
    │  Baileys   │
    │ WhatsApp   │
    └─────┬──────┘
          │
    ┌─────▼──────┐
    │  WhatsApp  │
    │    Web     │
    └────────────┘
```

### Troubleshooting

#### QR Code Not Showing

- Ensure `useQRAuth` is set to `true`
- Check console output for errors

#### Session Expired

- Sessions expire after ~20 days
- Simply re-scan the QR code when prompted

#### Message Not Sending

- Verify phone number format includes country code (e.g., `+1234567890`)
- Ensure WhatsApp connection is established (check logs)
- Verify the recipient has WhatsApp installed

#### Connection Issues

- Check your internet connection
- Ensure WhatsApp is not logged out on your phone
- Try clearing the session and re-authenticating

### Security Considerations

- **Never share your authentication session files**
- Use environment variables for sensitive configuration
- Respect WhatsApp's Terms of Service
- Implement rate limiting for bulk messaging
- Do not use for spam or unauthorized messaging

### License

ISC

### Support

For issues and questions:

- GitHub Issues: \[Report here]
- Apify Community: https://community.apify.com/
- Documentation: See AGENTS.md for AI agent integration details

# Actor input Schema

## `mode` (type: `string`):

Choose between sending messages or running MCP server

## `phoneNumber` (type: `string`):

WhatsApp phone number to send message to (include country code, e.g., +1234567890)

## `message` (type: `string`):

The message content to send

## `serverPort` (type: `integer`):

Port for MCP server (only used in server mode)

## `useQRAuth` (type: `boolean`):

Enable QR code authentication for WhatsApp Web

## Actor input object example

```json
{
  "mode": "send",
  "phoneNumber": "+1234567890",
  "message": "Hello from Apify WhatsApp Actor!",
  "serverPort": 3000,
  "useQRAuth": true
}
```

# Actor output Schema

## `overview` (type: `string`):

No description

# API

You can run this Actor programmatically using our API. Below are code examples in JavaScript, Python, and CLI, as well as the OpenAPI specification and MCP server setup.

## JavaScript example

```javascript
import { ApifyClient } from 'apify-client';

// Initialize the ApifyClient with your Apify API token
// Replace the '<YOUR_API_TOKEN>' with your token
const client = new ApifyClient({
    token: '<YOUR_API_TOKEN>',
});

// Prepare Actor input
const input = {
    "phoneNumber": "+1234567890",
    "message": "Hello from Apify WhatsApp Actor!"
};

// Run the Actor and wait for it to finish
const run = await client.actor("syntellect_ai/whatsapp-sms").call(input);

// Fetch and print Actor results from the run's dataset (if any)
console.log('Results from dataset');
console.log(`💾 Check your data here: https://console.apify.com/storage/datasets/${run.defaultDatasetId}`);
const { items } = await client.dataset(run.defaultDatasetId).listItems();
items.forEach((item) => {
    console.dir(item);
});

// 📚 Want to learn more 📖? Go to → https://docs.apify.com/api/client/js/docs

```

## Python example

```python
from apify_client import ApifyClient

# Initialize the ApifyClient with your Apify API token
# Replace '<YOUR_API_TOKEN>' with your token.
client = ApifyClient("<YOUR_API_TOKEN>")

# Prepare the Actor input
run_input = {
    "phoneNumber": "+1234567890",
    "message": "Hello from Apify WhatsApp Actor!",
}

# Run the Actor and wait for it to finish
run = client.actor("syntellect_ai/whatsapp-sms").call(run_input=run_input)

# Fetch and print Actor results from the run's dataset (if there are any)
print(f"💾 Check your data here: https://console.apify.com/storage/datasets/{run.default_dataset_id}")
for item in client.dataset(run.default_dataset_id).iterate_items():
    print(item)

# 📚 Want to learn more 📖? Go to → https://docs.apify.com/api/client/python/docs/quick-start

```

## CLI example

```bash
echo '{
  "phoneNumber": "+1234567890",
  "message": "Hello from Apify WhatsApp Actor!"
}' |
apify call syntellect_ai/whatsapp-sms --silent --output-dataset

```

## MCP server setup

```json
{
    "mcpServers": {
        "apify": {
            "type": "http",
            "url": "https://mcp.apify.com/?tools=fetch-actor-details,syntellect_ai/whatsapp-sms"
        }
    }
}
```

The hosted server signs you in with OAuth on first connect, so no API token belongs in this config. Clients without OAuth support can send an `Authorization: Bearer <APIFY_API_TOKEN>` header instead, using a token from API & Integrations in Apify Console (https://console.apify.com/settings/integrations).

## OpenAPI specification

Download the OpenAPI definition: https://api.apify.com/v2/actors/YSRcy7aldhMsseqUj/builds/rrTLYTiyfU91TSjQU/openapi.json
