// 使用 @larksuiteoapi/node-sdk 更新飞书文档 - 尝试使用字符串 block_type
import lark from '/home/ubuntu/.openclaw/extensions/openclaw-lark/node_modules/@larksuiteoapi/node-sdk/lib/index.js';

const APP_ID = 'cli_a93eb0f160399cc5';
const APP_SECRET = 'dRzJKrJ46j2Y1DKneyC33dQUNmsLwHCj';
const DOC_ID = 'YerQd8GomoDWQ6xA1zTc31xfnwb';

async function main() {
  try {
    console.log('创建 Lark Client...');
    const client = new lark.Client({
      appId: APP_ID,
      appSecret: APP_SECRET,
    });
    
    // 尝试使用字符串 block_type
    console.log('正在添加文本块 (block_type="text")...');
    const createBlockRes = await client.docx.documentBlockChildren.create({
      params: {},
      data: {
        blocks: [
          {
            block_type: 'text', // 尝试使用字符串
            text: {
              elements: [
                {
                  text_run: {
                    content: '测试内容',
                  },
                },
              ],
            },
          },
        ],
      },
      path: {
        document_id: DOC_ID,
        block_id: DOC_ID,
      },
    });
    
    console.log('添加块响应:', JSON.stringify(createBlockRes, null, 2));
    
    if (createBlockRes.code !== 0) {
      console.error('添加块失败:', createBlockRes.msg);
      return;
    }
    
    console.log('✓ 文档更新成功!');
  } catch (error) {
    console.error('✗ 发生错误:', error.message);
    if (error.response) {
      console.error('响应数据:', JSON.stringify(error.response.data, null, 2));
    }
    process.exit(1);
  }
}

main();
