الانتقال إلى المحتوى الرئيسي
استخدم SDK لعمليات المحادثة Connect360.

احصل على محادثة أو أنشئها

const conversation = await plato.v1.connect.getOrCreateConversation.mutate({
  type: "DIRECT",
  customer: {
    externalId: "website_user_123",
    name: "Jane Customer",
    email: "[email protected]",
  },
  channelIdentifier: "example.com",
  metadata: {
    source: "website-chat",
  },
});
ويجب توفير واحد منها على الأقل:
  • customerId
  • customer
  • memberIds

مدخل

{
  name?: string | null;
  type?: "DIRECT" | "GROUP";
  customerId?: string | null;
  customer?: {
    id?: string | null;
    externalId?: string | null;
    name?: string | null;
    email?: string | null;
    phone?: string | null;
    image?: string | null;
    metadata?: Record<string, unknown> | null;
  } | null;
  memberIds?: string[] | null;
  channelIds?: string[] | null;
  channelIdentifier?: string | null;
  metadata?: Record<string, unknown> | null;
}

إعادة استخدام السلوك

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

إنشاء محادثة فرعية

const thread = await plato.v1.connect.createSubConversation.mutate({
  parentId: conversation.id,
  name: "Order #1042",
  type: "GROUP",
  customer: {
    externalId: "website_user_123",
  },
  channelIdentifier: "example.com",
});
ترث المحادثات الفرعية القنوات الأصلية عند حذف channelIds وchannelIdentifier.

تحديث محادثة

const updated = await plato.v1.connect.updateConversation.mutate({
  id: conversation.id,
  name: "VIP customer support",
  metadata: {
    priority: "high",
  },
});
يمكنك التحديث:
  • name
  • metadata
  • parentId
يتم دمج بيانات التعريف في كائن بيانات التعريف الموجود.

حذف محادثة

await plato.v1.connect.deleteConversation.mutate({
  id: conversation.id,
});
يحتاج مفتاح API إلى connect360:conversation:delete. يتم الحذف فقط عندما يمتلك التكامل دورة حياة المحادثة.

قائمة المحادثات الفرعية

const page = await plato.v1.connect.listSubConversations.query({
  parentId: conversation.id,
  limit: 30,
});
إجابة:
{
  items: [
    {
      id: "conversation_child_1",
      name: "Order #1042",
      parentId: "conversation_parent_1",
      messages: [],
      participants: [],
      _count: {
        children: 0,
        messages: 3
      }
    }
  ],
  nextCursor: 30
}
لجلب الصفحة التالية:
const nextPage = await plato.v1.connect.listSubConversations.query({
  parentId: conversation.id,
  cursor: page.nextCursor,
  limit: 30,
});