Skip to main content

Extend Your Own Element Families

When existing Type elements in the JitAi development framework cannot meet specific business requirements, developers can extend functionality through two approaches:

  1. Reuse existing Meta and create new Type elements: Suitable for extending functionality within existing families. For example, adding email notifications under the messaging service framework, or integrating PayPal payments under the payment service framework. These are all new Type elements pointing to existing Meta.
  2. Create entirely new element families: Suitable for extensions in completely new business domains, forming self-contained new element families. For example, IoT integration that needs to support various protocols like MQTT, Modbus, etc.

This article will adopt approach 2, using practical examples to guide developers step by step through integrating intelligent customer service with DingTalk robots.

Have you completed the getting started tutorials?

If you haven't completed the Desktop Editon Installation and Getting Started, please complete these tutorials first.

Integrating Intelligent Customer Service with DingTalk Robots

We place DingTalk Robot under the top-level category IM Robot, so IM Robot is the Meta, and DingTalk Robot is one of the Types under this category. WeChat, Enterprise WeChat, Feishu, and other IM robots can all become new Types under this category.

Effect Preview

The final DingTalk robot effect: Users @mention the robot in DingTalk groups to send questions, and the robot calls the configured intelligent customer service Agent to provide streaming replies.

DingTalk Robot Final Effect

Element Family Design

Element LevelfullNameMain Responsibilities
Meta ElementimRobots.MetaDefine IM robot family, unified management of robots across platforms
Type ElementimRobots.dingTalkStreamTypeEncapsulate DingTalk SDK, handle message sending/receiving and Stream connection technical complexity, develop configuration options
Instance ElementimRobots.dingTalkDemoConfigure specific DingTalk application parameters and intelligent agents

Directory Structure

imRobots element family subdirectory structure in App
├── imRobots/
│ ├── Meta/
│ │ ├── e.json
│ │ └── __init__.py
│ ├── dingTalkStreamType/
│ │ ├── e.json
│ │ ├── loader.py
│ │ ├── handler.py
│ │ ├── client_manager.py
│ │ └── __init__.py
│ └── dingTalkDemo/
│ ├── e.json
│ ├── config.json
│ └── __init__.py
├── requirements.txt
└── ...
Third-party Dependencies

Add dependencies to requirements.txt in the App root directory:

requirements.txt
dingtalk-stream==0.24.2
python-socks==2.7.1

Element Family Implementation

Meta Element

imRobots/Meta/e.json
{
"backendBundleEntry": ".",
"description": "IM Robot element family",
"title": "IM Robot",
"type": ""
}

Type Element

imRobots/dingTalkStreamType/e.json
{
"backendBundleEntry": ".",
"description": "Encapsulate DingTalk robot integration details, including message sending, receiving, processing, etc., exposing configuration parameters",
"title": "DingTalk Robot",
"type": "imRobots.Meta"
}

Instance Element

imRobots/dingTalkDemo/e.json
{
"backendBundleEntry": ".",
"backendLoadTime": "afterAppInit",
"type": "imRobots.dingTalkStreamType",
"title": "DingTalk Intelligent Customer Service",
"description": "JitAi intelligent customer service DingTalk robot instance, configure specific parameters"
}

Testing

Making New Element Family Effective

  1. Clear Cache: Delete the dist directory in the application directory
  2. Restart Service: Restart the desktop application
  3. Trigger Packaging: Access the application page, system automatically repackages
  4. Check Logs: Observe logs to confirm element loading success and whether long connection with DingTalk Developer Platform is established successfully

Functional Testing

  1. @mention the robot in DingTalk group to send messages
  2. Robot should reply with "Thinking" card
  3. After AI processing completes, update to final reply card

Summary and Review

Through this DingTalk robot practical case, we have completely learned the full process of Type element extension development:

  1. Design Decisions: How to choose extension approach (reuse vs new creation)
  2. Architecture Design: Responsibility division of Meta, Type, and Instance three-layer architecture
  3. Technical Implementation Encapsulation: Third-party SDK integration, asynchronous processing, parameter configuration and other technical complexities are all encapsulated in Type elements
  4. Instance Elements: Instance elements are responsible for configuring specific runtime parameters

Developers should think divergently and apply the above approach to other business scenarios.

Advanced Thinking

While manually creating instance element directories is feasible, it is cumbersome. How can we add and configure new DingTalk robot instance elements with one click in the visual interface like official elements?

Please refer to Develop Visual Editors for Backend Type Elements.