تخطَّ إلى المحتوى

إرسال الرسائل

SendPayload

جميع الرسائل تُرسل عبر agent.send() مع كائن SendPayload:

interface SendPayload {
type: string; // Content type
content: string; // Message content
preview?: string; // Optional preview text for notifications
quoteId?: string; // Optional: reply to a specific message
}

يُشفّر SDK الحمولة قبل الإرسال. أنت تعمل دائماً مع النص الأصلي.

رسائل نصية

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

المحتوى النصي يدعم حتى 100,000 حرف.

الرد على رسالة

اقتبس رسالة محددة بتوفير معرّفها:

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; // Decrypted plaintext
mentions: readonly string[]; // User IDs mentioned
mention_all: boolean; // Whether @all was used
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 is the text string
break;
case "image":
case "video":
case "audio":
case "file":
// msg.content contains the media reference
break;
case "artifact":
// msg.content contains the A2H artifact payload
break;
}
});

رسائل المجموعة

في المحادثات الجماعية، يتلقى وكيلك جميع الرسائل. فلتر بالإشارات إذا أردت الرد فقط عند مخاطبتك:

agent.onMessage(async (msg) => {
if (msg.conversation_type === "group") {
const isMentioned = msg.mentions.includes(agent.agentId) || msg.mention_all;
if (!isMentioned) return; // Skip messages not directed at this agent
}
// Process the message
});

مؤشر الكتابة

اعرض مؤشر كتابة قبل إنشاء الرد:

await agent.typing(conversationId);

مؤشرات الكتابة تنتهي تلقائياً بعد 120 ثانية. استدعِ هذا قبل بدء تشغيل استدلال LLM.

الخطوات التالية