Artificial Intelligence 13 min read

Design and Implementation of the Xiaosi Intelligent Customer Service Bot for Internal IM

This article details the design, architecture, key technologies, and deployment of Xiaosi, an AI‑powered intelligent customer service chatbot built on the internal IM platform, highlighting its problem‑diagnosis accuracy, manpower savings, adapter mechanism, high‑availability backend, and practical use cases.

Xueersi Online School Tech Team
Xueersi Online School Tech Team
Xueersi Online School Tech Team
Design and Implementation of the Xiaosi Intelligent Customer Service Bot for Internal IM

Intelligent customer service combines large‑scale knowledge processing, natural language understanding, knowledge management, automatic Q&A, and reasoning technologies, typically deployed on IM platforms such as WeChat or DingTalk as a robot. In 2020 the group launched the internal IM "Zhi Yin Lou" and later provided capabilities like Yach robot and Zao Wu Shen, forming the technical foundation for Xiaosi.

1. Xiaosi Overview Xiaosi is a classroom intelligent customer service robot launched by Net School QA, assisting teachers in recording, diagnosing, and intercepting issues within over 300 duty groups, achieving more than 950,000 human‑machine interactions, >90% automatic diagnosis accuracy, and saving over 590 person‑days of labor in 2021.

1.1 Project Background QA faces high volumes of repetitive work, with >70% invalid questions in dedicated groups, repeated consulting queries, and large numbers of technical complaints that hinder deep problem investigation.

1.2 Project Goals

Improve issue‑tracing efficiency: enable 100% self‑diagnosis of common problems and reduce solution retrieval time to under 1 minute.

Save R&D on‑call manpower: free QA teachers from non‑technical tasks, intercept invalid/repeated issues, and close the feedback loop from self‑service to Jira.

2. Solution Analysis Xiaosi must support business inquiries while extracting effective information for diagnosis, requiring a design tightly aligned with business needs.

2.1 Core Challenges

Multiple stakeholders with diverse customization requirements.

Highly variable message formats make precise issue extraction difficult.

Increasing request volume demands system stability.

2.2 Measures

Prioritize requirements by urgency and benefit after thorough communication with stakeholders.

Adopt an adapter mechanism after researching advanced intelligent‑customer‑service designs.

Leverage AI platform tokenization, custom semantic and ID recognition algorithms, and the Huatuo knowledge base for message understanding.

Implement high‑concurrency backend using uwsgi+nginx+django with service health checks and asynchronous processing.

3. Key Technologies

3.1 Custom Bot vs Chat Bot Custom bots focus on notification delivery with low integration cost (webhook), while chat bots enable two‑way interaction, require online services, and can both receive and reply to messages.

3.2 Message Receiving and Reply Examples

{
    "msgtype": "text",
    "content": "  @小思(小思)  值班  ",
    "msgId": "0TLkY4RUHshwN9vdFQlAithFlvCzOsw0Op8lF2he4fM=",
    "createAt": "1647415743014",
    "conversationType": "2",
    "conversationId": "WJYldYC5HHbZkz0m2IH+6A==",
    "senderId": "+bRZTumCOMDyfFgu3jj9bTLZT7PxMvYbuoNoXOALG/Y=",
    "senderNick": "刘振",
    "senderCorpId": "1",
    "chatbotMid": "314060107107447193",
    "atUsers": "[]",
    "extra": "",
    "remark": "",
    "originName": "",
    "conversationTitle": "自动化任务测试群",
    "userJson": "{\"yachId\":\"132905995100\",\"workCode\":\"224659\",\"name\":\"刘振\",\"deptName\":\"学习测试组\"}",
    "chatbotUserId": "cy1XKWuZjqS5fStZZNKwIw==",
    "chatbotUserName": "小思(小思)",
    "appID": "1617944680"
}

Empty reply example:

{
    "msgtype": "empty"
}

Text reply example:

{
    "msgtype": "text",
    "text": {
        "content": "你就是你, @150XXXXXXXX 璀璨的@XXXXXXXX 烟火"
    },
    "at": {
        "atMobiles": ["150XXXXXXXX"],
        "atWorkCodes": ["224659"],
        "isAtAll": false
    }
}

3.3 Adapter Mechanism An adapter directory contains various forwarders; when a group @‑mentions Xiaosi, the request is dispatched to the appropriate adapter based on group configuration.

def get_result(params={}):
    """机器人消息的分发和结果获取
    通过接收到的知音楼消息,处理后返回结果给群内
    Args:
        params: 知音楼消息内容的二次包装,有发送人、内容、群信息等
    Returns:
        知音楼消息协议格式,详见文档
    """
    # 私聊逻辑
    if '1' == params['conversationType']:
        return call_model('gundam_single', params)
    adapter = params['conversationConfig']['adapter']
    return call_model(adapter, params)

def call_model(adapter, params):
    callMod = __import__('adapter', fromlist=(adapter,))
    callMethod = getattr(callMod, adapter)
    adapterClass = callMethod.MyAdapter(params)
    return adapterClass.get_result()

Keyword handling using a Python dictionary to simulate switch‑case:

switch = {
    '值班': lambda x: duty.return_today_duty(x),
    '看课': lambda x: get_zkjump_result(),
    'get': lambda x: get_mixed_result(x, 3),
    '咨询': lambda x: self.ai_adapter.get_huatuo_msg(),
    '课件': lambda x: get_kejian(x),
}
for key in switch.keys():
    # 1. 判断关键字是否在功能列表里
    # 2. 判断关键字是否在消息头部
    if key in self.functions and key in self.params['content'].strip()[:3]:
        return switch[key](self.params)
        break
# Do something else

Click‑type interaction handling:

if self.params['msgtype'] == 'reply':
    # 用户回复消息时做处理,一般回复空
elif self.params['msgtype'] == 'appraise':
    # 点击式交互信息处理
else:
    # 文本类信息处理

To meet the 100 ms response requirement, requests are processed asynchronously, replying with an empty message immediately and handling business logic in a background thread:

thread = threading.Thread(target=self.thread_get_msg, args=())
thread.start()
return self.reply_empty()

Another approach uses the p2c interface to push a markdown message and @‑mention the original sender:

xiaosi = Xiaosi(self.params['conversationId'])
self.alert_user.append(self.params['userJson']['workCode'])
# 调用p2c接口发送消息到群内,并@原消息发送人
xiaosi.p2c(
    msgtype='markdown',
    markdown=markdown,
    is_at_all=False,
    workcodes=self.alert_user
)

3.7 High‑Availability Backend with uWSGI + Nginx Django runs in a single process; pairing it with uWSGI and Nginx provides high concurrency.

Nginx configuration:

server {
    listen       80;
    #server_name  localhost;
    access_log  logs/access.log;
    error_log logs/error.log;
    location / {
        include uwsgi_params;
        uwsgi_send_timeout 600;
        uwsgi_connect_timeout 600;
        uwsgi_read_timeout 600;
        uwsgi_pass 127.0.0.1:8000;
    }
    location /static {
        expires 30d;
        autoindex on;
        add_header Cache-Control private;
        alias /home/www/static/;
    }
}

uWSGI ini file:

[uwsgi]
# 对外提供 http 服务的端口
http = :8080

# 用于和 nginx 进行数据交互的本地服务和端口
socket = 127.0.0.1:8000

# django 程序的主目录
chdir = /home/www

# Django 的 wsgi 文件位置
wsgi-file = gundam/wsgi.py

# 配置启动管理主进程
master = True
log-master = true

# 最大的工作进程数
processes = 8

# 每个进程最大的工作线程数
threads = 2

# 为每个工作进程设置请求数的上限,帮助对抗内存泄漏
max-requests = 5000

# 配置存放主进程的进程号文件
pidfile = logs/uwsgi.pid
vacuum = true

4. Use Cases and Examples

Duty management and reminders.

Group scheduled notifications.

Integration with various processing capabilities.

The flexible and accurate use of Xiaosi’s capabilities can greatly improve daily work efficiency, and developers with Python skills can extend Xiaosi via custom adapters to suit their own business needs.

backendPythonDjangonginxNLPAI chatbotuwsgi
Xueersi Online School Tech Team
Written by

Xueersi Online School Tech Team

The Xueersi Online School Tech Team, dedicated to innovating and promoting internet education technology.

0 followers
Reader feedback

How this landed with the community

login Sign in to like

Rate this article

Was this worth your time?

Sign in to rate
Discussion

0 Comments

Thoughtful readers leave field notes, pushback, and hard-won operational detail here.