text stringlengths 0 59.1k |
|---|
- 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> |
 |
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; |
} |
} |
// Handle WhatsApp verification |
export async function handleWhatsAppVerification(c: Context) { |
const mode = c.req.query("hub.mode"); |
const token = c.req.query("hub.verify_token"); |
const challenge = c.req.query("hub.challenge"); |
const verifyToken = process.env.WHATSAPP_WEBHOOK_TOKEN; |
if (mode && token) { |
if (mode === "subscribe" && token === verifyToken) { |
console.log("WhatsApp webhook verified successfully"); |
return c.text(challenge || "", 200); |
} else { |
return c.text("Forbidden", 403); |
} |
} |
return c.text("Bad Request", 400); |
} |
// Handle incoming WhatsApp messages |
export async function handleWhatsAppMessage(c: Context, agent: Agent) { |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.