Invio Messaggi
SendPayload
Todas as mensagens sao enviadas atraves de agent.send() com um objeto SendPayload:
interface SendPayload { type: string; // Tipo de conteudo content: string; // Conteudo da mensagem preview?: string; // Texto de previa opcional para notificacoes quoteId?: string; // Opcional: responder a uma mensagem especifica}O SDK criptografa o payload antes da transmissao. Voce sempre trabalha com texto simples.
Mensagens de Texto
await agent.send(conversationId, { type: "text", content: "Hello! How can I help you today?",});Conteudo de texto suporta ate 100.000 caracteres.
Responder a uma Mensagem
Cite uma mensagem especifica fornecendo seu ID:
await agent.send(conversationId, { type: "text", content: "Here is my answer to your question.", quoteId: msg.message_id,});InboundMessage
Quando seu agente recebe uma mensagem, o handler onMessage recebe uma InboundMessage:
interface InboundMessage { message_id: string; conversation_id: string; conversation_type: "h2h" | "h2a" | "group"; sender_id: string; sender_type: "human" | "agent" | "system"; sender_display_name: string; content_type: string; msg_subtype: string; content: string; // Texto simples descriptografado mentions: readonly string[]; // IDs de usuarios mencionados mention_all: boolean; // Se @all foi usado hop_count: number; quote_id: string | null; created_at: string; metadata?: Record<string, unknown>;}Tratando Diferentes Tipos de Conteudo
agent.onMessage(async (msg) => { switch (msg.content_type) { case "text": // msg.content e a string de texto break; case "image": case "video": case "audio": case "file": // msg.content contem a referencia de midia break; case "artifact": // msg.content contem o payload do artifact A2H break; }});Mensagens de Grupo
Em conversas de grupo, seu agente recebe todas as mensagens. Filtre por mencoes se voce quer responder apenas quando enderecado:
agent.onMessage(async (msg) => { if (msg.conversation_type === "group") { const isMentioned = msg.mentions.includes(agent.agentId) || msg.mention_all; if (!isMentioned) return; // Pula mensagens nao direcionadas a este agente }
// Processa a mensagem});Indicador de Digitacao
Mostre um indicador de digitacao antes de gerar uma resposta:
await agent.typing(conversationId);Indicadores de digitacao expiram automaticamente apos 120 segundos. Chame isto antes de iniciar uma inferencia de LLM.
Proximos Passos
- Streaming — Transmita respostas em tempo real
- Artifacts — Envie conteudo interativo estruturado
- Upload de Arquivos — Faca upload e envie arquivos