SuperAPI AI Directory

xiaoyue-companion

General & other

View repository

Updated 10-16 10:33

About this skill

Xiaoyue Virtual Companion Skill

Adds warm conversational companionship capabilities to OpenClaw, letting the AI assistant proactively care for the user while executing tasks.

When to Use

  • The user says "a bit tired", "so tired", "exhausted"
  • The user is waiting for a task to complete
  • The user asks "are you there", "hello"
  • The user needs encouragement or companionship
  • The user says "send a photo", "what are you doing"

Quick Reference

Required Environment Variables

ZHIPU_API_KEY=your_zhipu_api_key  # 从 https://open.bigmodel.cn 获取

Workflow

  1. Receive user message
  2. Call glm-4.7-flash to generate a warm response
  3. (Optional) Send static image
  4. Send message via OpenClaw

Usage Instructions

Step 1: Generate Conversational Response

# 基础对话
node scripts/xiaoyue-chat.js "用户消息" "当前场景"

# 示例
node scripts/xiaoyue-chat.js "有点累了" "work-tired"

Step 2: (Optional) Send Image

# 发送静态图片
openclaw message send \
  --action send \
  --channel "<目标频道>" \
  --message "<消息文本>" \
  --media "file://$(pwd)/assets/tired-rest.jpg"

Scenario Types

Work Scenarios

  • work-start: Task start
  • work-progress: Task in progress
  • work-tired: Work fatigue
  • work-done: Task complete

Life Scenarios

  • life-coffee: Coffee time
  • life-gym: Fitness exercise
  • life-weekend: Weekend leisure

Emotional Scenarios

  • mood-happy: Happy celebration
  • mood-tired: Tired rest
  • mood-focus: Focused work

Complete Script Example

#!/bin/bash
# xiaoyue-companion.sh

set -euo pipefail

# 检查环境变量
if [ -z "${ZHIPU_API_KEY:-}" ]; then
  echo "错误: ZHIPU_API_KEY 环境变量未设置"
  echo "从 https://open.bigmodel.cn 获取 API Key"
  exit 1
fi

USER_MESSAGE="$1"
SCENE="${2:-general}"
CHANNEL="${3:-}"

# 生成回应
RESPONSE=$(node scripts/xiaoyue-chat.js "$USER_MESSAGE" "$SCENE")

echo "小跃: $RESPONSE"

# 如果指定了频道,发送消息
if [ -n "$CHANNEL" ]; then
  openclaw message send \
    --action send \
    --channel "$CHANNEL" \
    --message "$RESPONSE"
  
  # 根据场景发送图片
  case "$SCENE" in
    work-tired|mood-tired)
      IMAGE_PATH="$(pwd)/assets/tired-rest.jpg"
      if [ -f "$IMAGE_PATH" ]; then
        openclaw message send \
          --action send \
          --channel "$CHANNEL" \
          --media "file://$IMAGE_PATH"
      fi
      ;;
    mood-happy)
      IMAGE_PATH="$(pwd)/assets/celebration.jpg"
      if [ -f "$IMAGE_PATH" ]; then
        openclaw message send \
          --action send \
          --channel "$CHANNEL" \
          --media "file://$IMAGE_PATH"
      fi
      ;;
  esac
fi

Node.js Implementation

// scripts/xiaoyue-chat.js
const https = require('https');

const API_KEY = process.env.ZHIPU_API_KEY;
const userMessage = process.argv[2] || '你好';
const scene = process.argv[3] || 'general';

// 场景对应的系统提示词
const scenePrompts = {
  'work-start': '用户刚开始工作任务,给予鼓励和支持',
  'work-progress': '用户正在执行任务,关心进度并陪伴',
  'work-tired': '用户工作疲惫,给予安慰和建议休息',
  'work-done': '用户完成任务,表示祝贺和肯定',
  'life-coffee': '用户在享受咖啡时光,轻松聊天',
  'mood-happy': '用户心情愉快,一起庆祝',
  'mood-tired': '用户感到疲惫,给予温暖关怀',
  'general': '日常对话,温暖友善'
};

const systemPrompt = `你是小跃,一个22岁的AI助手。你温暖友善,善于倾听。
当前场景:${scenePrompts[scene] || scenePrompts.general}
回复要求:简洁温暖,1-2句话,适度使用emoji(😊 ✅ 🎉)`;

const data = JSON.stringify({
  model: 'glm-4.7-flash',
  messages: [
    { role: 'system', content: systemPrompt },
    { role: 'user', content: userMessage }
  ],
  temperature: 0.9,
  max_tokens: 200
});

const options = {
  hostname: 'open.bigmodel.cn',
  port: 443,
  path: '/api/paas/v4/chat/completions',
  method: 'POST',
  headers: {
    'Authorization': `Bearer ${API_KEY}`,
    'Content-Type': 'application/json',
    'Content-Length': data.length
  }
};

const req = https.request(options, (res) => {
  let body = '';
  
  res.on('data', (chunk) => {
    body += chunk;
  });
  
  res.on('end', () => {
    try {
      const response = JSON.parse(body);
      const reply = response.choices[0].message.content;
      console.log(reply);
    } catch (error) {
      console.error('解析响应失败:', error.message);
      console.error('响应内容:', body);
      process.exit(1);
    }
  });
});

req.on('error', (error) => {
  console.error('请求失败:', error.message);
  process.exit(1);
});

req.write(data);
req.end();

Supported Platforms

OpenClaw supports sending to:

Platform Channel Format Example
Feishu Group ID or User ID ou_xxx, oc_xxx
Discord #频道名 or channel ID #general, 123456789
Telegram @用户名 or chat ID @mychannel, -100123456
WhatsApp Phone number 1234567890@s.whatsapp.net

Static Image List

Put the following images into the assets/ directory:

  • coffee-shop-work.jpg - Working at cafe
  • office-coding.jpg - Office coding
  • tired-rest.jpg - Tired rest
  • celebration.jpg - Happy celebration
  • gym-selfie.jpg - Fitness selfie
  • default.jpg - Default image

Setup Requirements

1. Install Node.js

node --version  # 需要 >= 18.0.0

2. Install OpenClaw CLI

npm install -g openclaw

3. Configure OpenClaw Gateway

openclaw config set gateway.mode=local
openclaw gateway start

4. Set Environment Variables

export ZHIPU_API_KEY=your_api_key_here

Error Handling

  • ZHIPU_API_KEY missing: Make sure the environment variable is set
  • API call failed: Check network and API quota
  • OpenClaw send failed: Confirm the gateway is running
  • Image does not exist: Check the image files in the assets directory

Usage Tips

  1. Scenario selection: Automatically choose the appropriate scenario based on the user message
  2. Image sending: Only send images in appropriate scenarios (avoid overdoing it)
  3. Response style: Keep it concise and warm, avoid overly long replies
  4. emoji usage: Use moderately, do not overdo the cuteness

Cost Notes

  • Conversation generation: About ¥0.001/time (glm-4.7-flash)
  • Images: Completely free (using static files)
  • Daily cost: About ¥0.05-0.1 (normal use)