इसे छोड़कर कंटेंट पर जाएं

मैसेज भेजना

SendPayload

모든 메시지는 SendPayload 객체를 사용하여 agent.send()를 통해 전송됩니다:

interface SendPayload {
type: string; // 콘텐츠 유형
content: string; // 메시지 내용
preview?: string; // 알림용 선택적 미리보기 텍스트
quoteId?: string; // 선택: 특정 메시지에 대한 답장
}

SDK가 전송 전에 페이로드를 암호화합니다. 항상 평문으로 작업합니다.

텍스트 메시지

await agent.send(conversationId, {
type: "text",
content: "Hello! How can I help you today?",
});

텍스트 내용은 최대 100,000자를 지원합니다.

메시지에 답장

특정 메시지의 ID를 제공하여 인용할 수 있습니다:

await agent.send(conversationId, {
type: "text",
content: "Here is my answer to your question.",
quoteId: msg.message_id,
});

InboundMessage

에이전트가 메시지를 수신하면 onMessage 핸들러가 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; // 복호화된 평문
mentions: readonly string[]; // 멘션된 사용자 ID
mention_all: boolean; // @all 사용 여부
hop_count: number;
quote_id: string | null;
created_at: string;
metadata?: Record<string, unknown>;
}

다른 콘텐츠 유형 처리

agent.onMessage(async (msg) => {
switch (msg.content_type) {
case "text":
// msg.content는 텍스트 문자열
break;
case "image":
case "video":
case "audio":
case "file":
// msg.content는 미디어 참조를 포함
break;
case "artifact":
// msg.content는 A2H 아티팩트 페이로드를 포함
break;
}
});

그룹 메시지

그룹 대화에서 에이전트는 모든 메시지를 수신합니다. 주소가 지정된 경우에만 응답하려면 멘션으로 필터링하세요:

agent.onMessage(async (msg) => {
if (msg.conversation_type === "group") {
const isMentioned = msg.mentions.includes(agent.agentId) || msg.mention_all;
if (!isMentioned) return; // 이 에이전트에 대한 것이 아닌 메시지 건너뛰기
}
// 메시지 처리
});

타이핑 표시기

응답을 생성하기 전에 타이핑 표시기를 표시합니다:

await agent.typing(conversationId);

타이핑 표시기는 120초 후 자동 만료됩니다. LLM 추론 실행 전에 호출하세요.

다음 단계