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 adopts approach 2, using a practical example 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 Version 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.

Loading...
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, expose 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, the system will automatically repackage
  4. Check logs: Observe logs to confirm successful element loading and whether the long connection with DingTalk Developer Platform is established successfully

Functional testing

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

Summary and review

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

  1. Design decisions: How to choose an extension approach (reusing existing Meta vs. creating new element families)
  2. Architecture design: Responsibility division across the 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 creatively and apply this approach to other business scenarios.

Advanced thinking

While manually creating instance element directories is feasible, it can be 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.

JitAI AssistantBeta
Powered by JitAI