From 0b332a7d5cbc60cb1ba816a0dc32ebbc60bded03 Mon Sep 17 00:00:00 2001 From: LuChao Date: Mon, 18 Mar 2024 11:42:27 +0800 Subject: [PATCH] 3.0.0-Beta-12 --- package.json | 2 +- tests/auth.ts | 91 ++++++++------- tests/lark-orm-test.ts | 252 +++++++++++++++++++++-------------------- tests/lark.ts | 50 ++++---- tests/vika-orm-test.ts | 72 ++++++------ 5 files changed, 241 insertions(+), 226 deletions(-) diff --git a/package.json b/package.json index 6796c504..93b5ee60 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@atorber/chatflow", - "version": "3.0.0-Beta-11", + "version": "3.0.0-Beta-12", "description": "ChatFlow-聊天机器人管理平台", "type": "module", "exports": { diff --git a/tests/auth.ts b/tests/auth.ts index cebaf19e..479faa71 100644 --- a/tests/auth.ts +++ b/tests/auth.ts @@ -31,68 +31,68 @@ import 'dotenv/config.js' // 导入环境变量配置 // import { ServeGetMedias } from '../src/api/media.js' -const authClient = getAuthClient() -const res = await authClient.init(process.env.VIKA_SPACE_ID, process.env.VIKA_TOKEN) -console.log('res:', JSON.stringify(res.data, null, 2)) -await authClient.login() +const main = async () => { + const authClient = getAuthClient() + const res = await authClient.init(process.env.VIKA_SPACE_ID, process.env.VIKA_TOKEN) + console.log('res:', JSON.stringify(res.data, null, 2)) + await authClient.login() + // const task = await ServeGetNoticesTask() + // console.log('task:', JSON.stringify(task, null, 2)) -// const task = await ServeGetNoticesTask() -// console.log('task:', JSON.stringify(task, null, 2)) + // const chatbots = await ServeGetChatbots() + // console.log('chatbots:', JSON.stringify(chatbots, null, 2)) -// const chatbots = await ServeGetChatbots() -// console.log('chatbots:', JSON.stringify(chatbots, null, 2)) + // const chatbotUsers = await ServeGetChatbotUsers({ id:1 }) + // console.log('chatbotUsers:', JSON.stringify(chatbotUsers, null, 2)) -// const chatbotUsers = await ServeGetChatbotUsers({ id:1 }) -// console.log('chatbotUsers:', JSON.stringify(chatbotUsers, null, 2)) + // const chatbotUsersGroup = await ServeGetChatbotUsersGroup() + // console.log('chatbotUsersGroup:', JSON.stringify(chatbotUsersGroup, null, 2)) -// const chatbotUsersGroup = await ServeGetChatbotUsersGroup() -// console.log('chatbotUsersGroup:', JSON.stringify(chatbotUsersGroup, null, 2)) + // const chatbotUsersDetail = await ServeGetChatbotUsersDetail() + // console.log('chatbotUsersDetail:', JSON.stringify(chatbotUsersDetail, null, 2)) -// const chatbotUsersDetail = await ServeGetChatbotUsersDetail() -// console.log('chatbotUsersDetail:', JSON.stringify(chatbotUsersDetail, null, 2)) + // const welcomes = await ServeGetWelcomes() + // console.log('welcomes:', JSON.stringify(welcomes, null, 2)) -// const welcomes = await ServeGetWelcomes() -// console.log('welcomes:', JSON.stringify(welcomes, null, 2)) + // const qas = await ServeGetQas() + // console.log('qas:', JSON.stringify(qas, null, 2)) -// const qas = await ServeGetQas() -// console.log('qas:', JSON.stringify(qas, null, 2)) + // const userInfo = await ServeGetUserDetail() + // console.log('userInfo:', userInfo) -// const userInfo = await ServeGetUserDetail() -// console.log('userInfo:', userInfo) + // const userSetting = await ServeGetUserSetting() + // console.log('userSetting:', userSetting) -// const userSetting = await ServeGetUserSetting() -// console.log('userSetting:', userSetting) + // const userConfig = await ServeGetUserConfigBykey({ key:'BASE_BOT_NAME', value:'config333' }) + // console.log('userConfig:', userConfig) -// const userConfig = await ServeGetUserConfigBykey({ key:'BASE_BOT_NAME', value:'config333' }) -// console.log('userConfig:', userConfig) + // const userConfigGroup = await ServeGetUserConfigGroup() + // console.log('userConfigGroup:', JSON.stringify(userConfigGroup)) -// const userConfigGroup = await ServeGetUserConfigGroup() -// console.log('userConfigGroup:', JSON.stringify(userConfigGroup)) + // const whiteList = await ServeGetWhitelistWhite() + // console.log('whiteList:', JSON.stringify(whiteList)) -// const whiteList = await ServeGetWhitelistWhite() -// console.log('whiteList:', JSON.stringify(whiteList)) + // const jobs = await ServeGetNotices() + // console.log('jobs:', JSON.stringify(jobs)) -// const jobs = await ServeGetNotices() -// console.log('jobs:', JSON.stringify(jobs)) + // const keywords = await ServeGetKeywords() + // console.log('keywords:', JSON.stringify(keywords)) -// const keywords = await ServeGetKeywords() -// console.log('keywords:', JSON.stringify(keywords)) + // const statistics = await ServeGetStatistics() + // console.log('statistics:', JSON.stringify(statistics)) -// const statistics = await ServeGetStatistics() -// console.log('statistics:', JSON.stringify(statistics)) + // const groupnotices = await ServeGetGroupnotices() + // console.log('groupnotices:', JSON.stringify(groupnotices)) -// const groupnotices = await ServeGetGroupnotices() -// console.log('groupnotices:', JSON.stringify(groupnotices)) + // const userConfigGroup = await ServeGetUserConfigGroup() + // console.log('userConfigGroup:', JSON.stringify(userConfigGroup)) -// const userConfigGroup = await ServeGetUserConfigGroup() -// console.log('userConfigGroup:', JSON.stringify(userConfigGroup)) + // const medias = await ServeGetMedias({ name:'程序开发' }) + // console.log('medias:', JSON.stringify(medias, null, 2)) -// const medias = await ServeGetMedias({ name:'程序开发' }) -// console.log('medias:', JSON.stringify(medias, null, 2)) - -/* 链接检测 */ -// const text = 'https://oou2hscgt2.feishu.cn/base/bascnPgZURujrdwZ9T4JkLUSUQc?table=tbl90nnja6sqMuCT&view=vewmgp68n9' -// const text = 'https://vika.cn/workbench/dstagAfWtNuTqHQizP/viw7KwjQyCjbP?spaceId=spcj6bgt12WoZ' + /* 链接检测 */ + // const text = 'https://oou2hscgt2.feishu.cn/base/bascnPgZURujrdwZ9T4JkLUSUQc?table=tbl90nnja6sqMuCT&view=vewmgp68n9' + // const text = 'https://vika.cn/workbench/dstagAfWtNuTqHQizP/viw7KwjQyCjbP?spaceId=spcj6bgt12WoZ' // const VIKA_BASE_STRING = 'https://vika.cn/workbench/' // const LARK_BASE_STRING = '.feishu.cn/base/' @@ -117,3 +117,6 @@ await authClient.login() // } // console.info('多维表格配置信息:', JSON.stringify(config)) // } +} + +void main() diff --git a/tests/lark-orm-test.ts b/tests/lark-orm-test.ts index eb055fae..f644dd10 100644 --- a/tests/lark-orm-test.ts +++ b/tests/lark-orm-test.ts @@ -3,16 +3,6 @@ import 'dotenv/config.js' import { BiTable } from '../src/db/lark-db.js' import { BaseEntity, MappingOptions, IRecord } from '../src/db/lark-orm.js' -const db = new BiTable() -const dbInit = await db.createSheet({ - token: process.env.LARK_APP_ID + '/' + process.env.LARK_APP_SECRET + '/' + process.env.LARK_BITABLE_APP_TOKEN, - spaceId: process.env.LARK_BITABLE_APP_TOKEN, -}) - -console.log('dbInit:', JSON.stringify(dbInit)) - -await db.createSheet - export class Env extends BaseEntity { name?: string @@ -58,99 +48,6 @@ export class Env extends BaseEntity { } -// 测试 -const env = new Env() -await env.setVikaOptions({ - apiKey: process.env.LARK_APP_ID + '/' + process.env.LARK_APP_SECRET + '/' + process.env.LARK_BITABLE_APP_TOKEN, - baseId: db.dataBaseIds.envSheet, // 设置 base ID -}) - -console.log('env:', JSON.stringify(env.config, null, 2)) - -const recordsAll = await env.findAll() -console.log('查询全部记录envData:', JSON.stringify(recordsAll)) - -const records:any[] = [ - { - name: '测试sssss22222', - key: 'MESSAGE_ENCODINGAESKEY', - value: 'X00fcQHkvRkNUdJefu4FD6pym2oIvs63Y5NP3pnZ5po', - syncStatus:'已同步', - desc: '消息加密密钥,vika推送地址https://3sewxanjdvsbp.cfc-execute.bj.baidubce.com/mqtt', - lastOperationTime: 1700326172112, - }, - { - - name: '测试sssss11111', - key: 'MESSAGE_ENCODINGAESKEY', - value: 'X00fcQHkvRkNUdJefu4FD6pym2oIvs63Y5NP3pnZ5po', - syncStatus:'已同步', - desc: '消息加密密钥,vika推送地址https://3sewxanjdvsbp.cfc-execute.bj.baidubce.com/mqtt', - lastOperationTime: 1700326172112, - - }, -] -const record = records[0] as any -const res1 = await env.create(record) -console.log('创建单条记录res1:', JSON.stringify(res1, null, 2)) - -const res2 = await env.createBatch(records) -console.log('批量创建记录res2:', JSON.stringify(res2, null, 2)) - -// const recordsAll2 = recordsAll.filter((item: { fields: { name: string } }) => (item.fields.name === '测试sssss11111' || item.fields.name === '测试sssss22222')) -// console.log('筛选记录recordsAll2:', JSON.stringify(recordsAll2, null, 2)) - -// if (recordsAll2.length) { -// recordsAll2.forEach(async (item: IRecord) => { -// const res3 = await env.delete(item.recordId as string) -// console.log('删除单条记录res3:', JSON.stringify(res3, null, 2)) -// }) -// } - -const recordsAll3 = await env.findAll() -console.log('获取全部记录recordsAll3:', JSON.stringify(recordsAll3)) - -const recordsAll41:IRecord[] = recordsAll3.data as IRecord[] - -const recordsAll4 = recordsAll41.filter((item) => (item.fields['name'] === '测试sssss11111' || item.fields['name'] === '测试sssss22222')) -console.log('筛选符合条件的记录recordsAll4:', JSON.stringify(recordsAll4)) - -// const ids = recordsAll4.map((item: IRecord) => item.recordId as string) -// console.log('获取recordsAll4记录ID数组ids:', JSON.stringify(ids)) - -// if (ids.length) { -// const res4 = await env.deleteBatch(ids) -// console.log('批量删除记录res4:', JSON.stringify(res4)) -// } else { -// console.log('没有记录需要删除...') -// } - -const newRecord0 = recordsAll4[0] as IRecord -const newRecord1 = recordsAll4[1] as IRecord - -newRecord0.fields['name'] = '测试sssss11111-修改' + new Date().toLocaleString() -newRecord1.fields['name'] = '测试sssss22222-修改' + new Date().toLocaleString() - -const recordsAll5 = await env.updatEmultiple(recordsAll4) -console.log('批量更新记录recordsAll5:', JSON.stringify(recordsAll5)) - -const newRecord2 = recordsAll4[2] as IRecord -newRecord2.fields['name'] = '测试sssss333333-修改' + new Date().toLocaleString() - -const recordsAll6 = await env.update(newRecord2.record_id as string, newRecord2.fields) -console.log('更新单条记录recordsAll6:', JSON.stringify(recordsAll6)) - -// 删除测试数据 -const ids = recordsAll4.map((item: IRecord) => item.recordId as string) -console.log('获取recordsAll4记录ID数组ids:', JSON.stringify(ids)) -if (ids.length) { - const res4 = await env.deleteBatch(ids) - console.log('批量删除记录res4:', JSON.stringify(res4)) -} - -const recordsAll7 = await env.findByField('name', 'Wechaty-Puppet') -console.log('根据字段查询recordsAll7:', JSON.stringify(recordsAll7)) - export class Messages extends BaseEntity { timeHms?: string @@ -218,25 +115,132 @@ export class Messages extends BaseEntity { } -const messages = new Messages() -await messages.setVikaOptions({ - apiKey: process.env.LARK_APP_ID + '/' + process.env.LARK_APP_SECRET + '/' + process.env.LARK_BITABLE_APP_TOKEN, - baseId: db.dataBaseIds.messageSheet, // 设置 base ID -}) - -// const file = await messages.upload('/Users/luyuchao/Documents/GitHub/chatflow/tools/order_20_47_20.xlsx') -// console.log('上传文件recordsAll8:', JSON.stringify(file)) - -const file = await messages.upload('/Users/luyuchao/Documents/GitHub/chatflow/data/media/image/qrcode/qrcode.png') -console.log('上传文件recordsAll8:', JSON.stringify(file)) - -const record9 = { - timeHms: new Date().toLocaleString(), - name: 'Wechaty-Puppet', - alias: 'Wechaty-Puppet', - topic: 'Wechaty-Puppet', - listener: 'Wechaty-Puppet', - file :[ file.data ], +const main = async () => { + const db = new BiTable() + const dbInit = await db.createSheet({ + token: process.env.LARK_APP_ID + '/' + process.env.LARK_APP_SECRET + '/' + process.env.LARK_BITABLE_APP_TOKEN, + spaceId: process.env.LARK_BITABLE_APP_TOKEN, + }) + + console.log('dbInit:', JSON.stringify(dbInit)) + + await db.createSheet + + // 测试 + const env = new Env() + await env.setVikaOptions({ + apiKey: process.env.LARK_APP_ID + '/' + process.env.LARK_APP_SECRET + '/' + process.env.LARK_BITABLE_APP_TOKEN, + baseId: db.dataBaseIds.envSheet, // 设置 base ID + }) + + console.log('env:', JSON.stringify(env.config, null, 2)) + + const recordsAll = await env.findAll() + console.log('查询全部记录envData:', JSON.stringify(recordsAll)) + + const records:any[] = [ + { + name: '测试sssss22222', + key: 'MESSAGE_ENCODINGAESKEY', + value: 'X00fcQHkvRkNUdJefu4FD6pym2oIvs63Y5NP3pnZ5po', + syncStatus:'已同步', + desc: '消息加密密钥,vika推送地址https://3sewxanjdvsbp.cfc-execute.bj.baidubce.com/mqtt', + lastOperationTime: 1700326172112, + }, + { + + name: '测试sssss11111', + key: 'MESSAGE_ENCODINGAESKEY', + value: 'X00fcQHkvRkNUdJefu4FD6pym2oIvs63Y5NP3pnZ5po', + syncStatus:'已同步', + desc: '消息加密密钥,vika推送地址https://3sewxanjdvsbp.cfc-execute.bj.baidubce.com/mqtt', + lastOperationTime: 1700326172112, + + }, + ] + const record = records[0] as any + const res1 = await env.create(record) + console.log('创建单条记录res1:', JSON.stringify(res1, null, 2)) + + const res2 = await env.createBatch(records) + console.log('批量创建记录res2:', JSON.stringify(res2, null, 2)) + + // const recordsAll2 = recordsAll.filter((item: { fields: { name: string } }) => (item.fields.name === '测试sssss11111' || item.fields.name === '测试sssss22222')) + // console.log('筛选记录recordsAll2:', JSON.stringify(recordsAll2, null, 2)) + + // if (recordsAll2.length) { + // recordsAll2.forEach(async (item: IRecord) => { + // const res3 = await env.delete(item.recordId as string) + // console.log('删除单条记录res3:', JSON.stringify(res3, null, 2)) + // }) + // } + + const recordsAll3 = await env.findAll() + console.log('获取全部记录recordsAll3:', JSON.stringify(recordsAll3)) + + const recordsAll41:IRecord[] = recordsAll3.data as IRecord[] + + const recordsAll4 = recordsAll41.filter((item) => (item.fields['name'] === '测试sssss11111' || item.fields['name'] === '测试sssss22222')) + console.log('筛选符合条件的记录recordsAll4:', JSON.stringify(recordsAll4)) + + // const ids = recordsAll4.map((item: IRecord) => item.recordId as string) + // console.log('获取recordsAll4记录ID数组ids:', JSON.stringify(ids)) + + // if (ids.length) { + // const res4 = await env.deleteBatch(ids) + // console.log('批量删除记录res4:', JSON.stringify(res4)) + // } else { + // console.log('没有记录需要删除...') + // } + + const newRecord0 = recordsAll4[0] as IRecord + const newRecord1 = recordsAll4[1] as IRecord + + newRecord0.fields['name'] = '测试sssss11111-修改' + new Date().toLocaleString() + newRecord1.fields['name'] = '测试sssss22222-修改' + new Date().toLocaleString() + + const recordsAll5 = await env.updatEmultiple(recordsAll4) + console.log('批量更新记录recordsAll5:', JSON.stringify(recordsAll5)) + + const newRecord2 = recordsAll4[2] as IRecord + newRecord2.fields['name'] = '测试sssss333333-修改' + new Date().toLocaleString() + + const recordsAll6 = await env.update(newRecord2.record_id as string, newRecord2.fields) + console.log('更新单条记录recordsAll6:', JSON.stringify(recordsAll6)) + + // 删除测试数据 + const ids = recordsAll4.map((item: IRecord) => item.recordId as string) + console.log('获取recordsAll4记录ID数组ids:', JSON.stringify(ids)) + if (ids.length) { + const res4 = await env.deleteBatch(ids) + console.log('批量删除记录res4:', JSON.stringify(res4)) + } + + const recordsAll7 = await env.findByField('name', 'Wechaty-Puppet') + console.log('根据字段查询recordsAll7:', JSON.stringify(recordsAll7)) + + const messages = new Messages() + await messages.setVikaOptions({ + apiKey: process.env.LARK_APP_ID + '/' + process.env.LARK_APP_SECRET + '/' + process.env.LARK_BITABLE_APP_TOKEN, + baseId: db.dataBaseIds.messageSheet, // 设置 base ID + }) + + // const file = await messages.upload('/Users/luyuchao/Documents/GitHub/chatflow/tools/order_20_47_20.xlsx') + // console.log('上传文件recordsAll8:', JSON.stringify(file)) + + const file = await messages.upload('/Users/luyuchao/Documents/GitHub/chatflow/data/media/image/qrcode/qrcode.png') + console.log('上传文件recordsAll8:', JSON.stringify(file)) + + const record9 = { + timeHms: new Date().toLocaleString(), + name: 'Wechaty-Puppet', + alias: 'Wechaty-Puppet', + topic: 'Wechaty-Puppet', + listener: 'Wechaty-Puppet', + file :[ file.data ], + } + const recordsAll9 = await messages.create(record9) + console.log('创建单条记录recordsAll9:', JSON.stringify(recordsAll9)) } -const recordsAll9 = await messages.create(record9) -console.log('创建单条记录recordsAll9:', JSON.stringify(recordsAll9)) + +void main() diff --git a/tests/lark.ts b/tests/lark.ts index 556eacbf..3ecefb9f 100644 --- a/tests/lark.ts +++ b/tests/lark.ts @@ -3,34 +3,38 @@ import 'dotenv/config.js' import * as lark from '@larksuiteoapi/node-sdk' -const appId = process.env.LARK_APP_ID || '' -const appSecret = process.env.LARK_APP_SECRET || '' -const app_token = process.env.LARK_BITABLE_APP_TOKEN || '' -const user_mobile = process.env.LARK_APP_USER_MOBILE || '13800000000' +const main = async () => { + const appId = process.env.LARK_APP_ID || '' + const appSecret = process.env.LARK_APP_SECRET || '' + const app_token = process.env.LARK_BITABLE_APP_TOKEN || '' + const user_mobile = process.env.LARK_APP_USER_MOBILE || '13800000000' -const client = new lark.Client({ - appId, - appSecret, -}) + const client = new lark.Client({ + appId, + appSecret, + }) -const user = await client.contact.user.batchGetId({ - data:{ mobiles:[ user_mobile ] }, - params:{ user_id_type:'user_id' }, -}) -console.log('\nuser:', JSON.stringify(user)) + const user = await client.contact.user.batchGetId({ + data:{ mobiles:[ user_mobile ] }, + params:{ user_id_type:'user_id' }, + }) + console.log('\nuser:', JSON.stringify(user)) -if (user.data && user.data.user_list && user.data.user_list.length) { - const user_id = user.data.user_list[0]?.user_id - console.log('\nuser_id:', user_id) + if (user.data && user.data.user_list && user.data.user_list.length) { + const user_id = user.data.user_list[0]?.user_id + console.log('\nuser_id:', user_id) - const tables = await client.bitable.appTable.list({ path:{ app_token } }) - console.log('\ntables:', JSON.stringify(tables)) + const tables = await client.bitable.appTable.list({ path:{ app_token } }) + console.log('\ntables:', JSON.stringify(tables)) - if (tables.data && tables.data.items && tables.data.items.length) { - const table_id = tables.data.items[0]?.table_id - if (table_id) { - const fields = await client.bitable.appTableField.list({ path:{ app_token, table_id } }) - console.log('\nfields:', JSON.stringify(fields)) + if (tables.data && tables.data.items && tables.data.items.length) { + const table_id = tables.data.items[0]?.table_id + if (table_id) { + const fields = await client.bitable.appTableField.list({ path:{ app_token, table_id } }) + console.log('\nfields:', JSON.stringify(fields)) + } } } } + +void main() diff --git a/tests/vika-orm-test.ts b/tests/vika-orm-test.ts index 1d7429a4..ec5ac36a 100644 --- a/tests/vika-orm-test.ts +++ b/tests/vika-orm-test.ts @@ -3,14 +3,6 @@ import 'dotenv/config.js' import { BiTable } from '../src/db/vika-db.js' import { BaseEntity, MappingOptions } from '../src/db/vika-orm.js' -const db = new BiTable() -const dbInit = await db.init({ - token: process.env.VIKA_TOKEN || '', - spaceId: process.env.VIKA_SPACE_ID || '', -}) - -console.log('dbInit:', dbInit) - export class Env extends BaseEntity { name?: string @@ -56,31 +48,43 @@ export class Env extends BaseEntity { } -// 测试 -const env = new Env() -await env.setVikaOptions({ - apiKey: db.token, - baseId: db.dataBaseIds.envSheet, // 设置 base ID -}) - -const envData = await env.findAll() -console.log('envData:', JSON.stringify(envData, null, 2)) - -const demo = [ - { - recordId: 'rec0ofQXMfryc', - createdAt: 1694860633000, - updatedAt: 1697695907000, - fields: { - name: 'Wechaty-Puppet', - key: 'WECHATY_PUPPET', - value: 'wechaty-puppet-padlocal', - desc: '可选值:\nwechaty-puppet-wechat4u\nwechaty-puppet-wechat\nwechaty-puppet-xp\nwechaty-puppet-engine\u0000\nwechaty-puppet-padlocal\nwechaty-puppet-service', - syncStatus: '未同步', - lastOperationTime: 1694860632945, - action: '选择操作', +const main = async () => { + const db = new BiTable() + const dbInit = await db.init({ + token: process.env.VIKA_TOKEN || '', + spaceId: process.env.VIKA_SPACE_ID || '', + }) + + console.log('dbInit:', dbInit) + + // 测试 + const env = new Env() + await env.setVikaOptions({ + apiKey: db.token, + baseId: db.dataBaseIds.envSheet, // 设置 base ID + }) + + const envData = await env.findAll() + console.log('envData:', JSON.stringify(envData, null, 2)) + + const demo = [ + { + recordId: 'rec0ofQXMfryc', + createdAt: 1694860633000, + updatedAt: 1697695907000, + fields: { + name: 'Wechaty-Puppet', + key: 'WECHATY_PUPPET', + value: 'wechaty-puppet-padlocal', + desc: '可选值:\nwechaty-puppet-wechat4u\nwechaty-puppet-wechat\nwechaty-puppet-xp\nwechaty-puppet-engine\u0000\nwechaty-puppet-padlocal\nwechaty-puppet-service', + syncStatus: '未同步', + lastOperationTime: 1694860632945, + action: '选择操作', + }, }, - }, -] + ] + + console.log('demo:', JSON.stringify(demo)) +} -console.log('demo:', JSON.stringify(demo)) +void main()