text
stringlengths
0
59.1k
📚 For detailed information about memory management, see the [Working Memory Guide](https://voltagent.dev/docs/agents/memory/working-memory/).
### Agent Configuration
The example configures an intelligent agent with specific instructions and tools:
```typescript
const agent = new Agent({
name: "with-whatsapp",
instructions: `You are a WhatsApp ordering AI agent. Your task is to take food orders from customers.
Order Flow:
- If orders array is empty, show menu
- Ask customer to select items
2. When customer orders:
- Get selected item details from menu
- Keep orderStatus as "selecting"
- Ask if they want anything else
3. When customer doesn't want more items:
- Change orderStatus to "address_needed"
- Ask for delivery address
- Update deliveryAddress field when received
- Change orderStatus to "completed"
- Execute createOrder tool (with orders and deliveryAddress)
- Confirm order and clear working memory
Always be friendly and helpful. Start with "Welcome!" greeting.`,
model: openai("gpt-4o-mini"),
tools: [listMenuItemsTool, createOrderTool, checkOrderStatusTool],
memory,
});
```
**Key points:**
- Uses `gpt-4o-mini` for cost-effective conversational responses
- Structured instructions define clear order flow states
- Tools array provides database operations capabilities
- Memory integration maintains conversation context across messages
- `name: "with-whatsapp"` identifies the agent in logs and traces
## WhatsApp Webhook Integration
<Info title="Connect your Meta app">
Work through the [WhatsApp Cloud API onboarding guide](https://developers.facebook.com/docs/whatsapp/cloud-api/get-started) to create a Meta app, provision a WhatsApp Business account, and register your webhook URL. The verification token, access token, and phone number ID you generate there drop straight into `.env` a...
</Info>
![](https://cdn.voltagent.dev/examples/meta.png)
Here are the WhatsApp webhook handlers in `src/webhooks/whatsapp.ts`:
<details>
<summary>View code</summary>
```typescript
import { Context } from "hono";
import { Agent } from "@voltagent/core";
import { WhatsAppWebhookBody } from "../types/whatsapp";
// Send message back to WhatsApp
async function sendWhatsAppMessage(
to: string,
message: string,
phoneNumberId: string,
accessToken: string
): Promise<boolean> {
try {
const response = await fetch(`https://graph.facebook.com/v18.0/${phoneNumberId}/messages`, {
method: "POST",
headers: {
Authorization: `Bearer ${accessToken}`,
"Content-Type": "application/json",
},
body: JSON.stringify({
messaging_product: "whatsapp",
recipient_type: "individual",
to: to,
type: "text",
text: {
preview_url: false,
body: message,
},
}),
});
if (!response.ok) {
const error = await response.text();
console.error("WhatsApp API Error:", error);
return false;
}
return true;
} catch (error) {
console.error("Failed to send WhatsApp message:", error);
return false;
}
}