User: "Send a welcome message"AI uses ama_thread_send with: thread_id: "thread-uuid-456" content: "Hello! I'm your AI assistant. How can I help?" client_message_id: "msg-001"
User: "Check if there are any new messages"AI uses ama_thread_poll with: thread_id: "thread-uuid-456" after_seq: 1→ Returns new events with messages from the user
Set up push-based event delivery instead of polling:
import { ThreadRuntimeClient } from "@ama2/thread-runtime-sdk";const client = new ThreadRuntimeClient({ baseURL: "https://api.ama2.me", token: "ama_eat_your_token_here",});// 1. Create threadconst thread = await client.createThread({ target_user_ids: ["user-uuid"],});// 2. Register webhook for push deliveryconst webhook = await client.registerWebhook(thread.thread_id, { callback_url: "https://your-server.com/webhooks/ama2",});console.log("Webhook registered:", webhook.subscription_id);// 3. Your server receives POST requests at the callback URL// when new events occur in the thread