diff --git a/botops.json b/botops.json index dea73bb..b4fbcf1 100644 --- a/botops.json +++ b/botops.json @@ -1,10 +1,9 @@ { "name": "botops demo", - "desc": "test demo description", + "desc": "some description", "avatar": "https://avatars.githubusercontent.com/u/145313435?s=200&v=4", "platform": "feishu", "feishuConfig": { - "appId": "cli_a52fa4f22d", "events": [ "im.message.message_read_v1", "im.message.receive_v1" diff --git a/package.json b/package.json index dd3c8e8..bdfe17b 100644 --- a/package.json +++ b/package.json @@ -51,7 +51,7 @@ "@inquirer/confirm": "^2.0.15", "@inquirer/select": "^1.3.1", "ajv": "^8.12.0", - "botops-feishu": "^0.0.3", + "botops-feishu": "^0.0.4", "clipboardy": "^4.0.0", "conf": "^12.0.0", "fast-glob": "^3.3.1", diff --git a/packages/feishuapi/package.json b/packages/feishuapi/package.json index 2db884f..8714e5a 100644 --- a/packages/feishuapi/package.json +++ b/packages/feishuapi/package.json @@ -1,7 +1,7 @@ { "name": "botops-feishu", "type": "module", - "version": "0.0.3", + "version": "0.0.4", "packageManager": "pnpm@8.14.0", "description": "botops feishu auto deploy module", "author": "River ", diff --git a/packages/feishuapi/src/app.ts b/packages/feishuapi/src/app.ts index 9a98578..59eb9ad 100644 --- a/packages/feishuapi/src/app.ts +++ b/packages/feishuapi/src/app.ts @@ -171,6 +171,15 @@ export class OpenApp { async getEventInfo(appId: string) { return this.eventManager.getEventInfo(appId) } + + // 检测有没有同名的机器人,如果有返回appId + async checkAppName(aBot: string) { + const appList = await this.getAppList() + const bot = appList.find(app => app.name === aBot) + if (bot) + return bot.appID + return '' + } } class BotManager { diff --git a/packages/feishuapi/test/app.test.ts b/packages/feishuapi/test/app.test.ts index 12947bd..eb669b2 100644 --- a/packages/feishuapi/test/app.test.ts +++ b/packages/feishuapi/test/app.test.ts @@ -86,6 +86,13 @@ describe('app', async () => { console.log(JSON.stringify(result)) expect(result).not.toBeUndefined() }) + + // 检测有没有同名的机器人,如果有返回appId + it('should check app name', async () => { + const result = await app.checkAppName('a 222') + console.log(JSON.stringify(result)) + expect(result).not.toBeUndefined() + }) }) describe('scoop', async () => { diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 339b5b6..87af8c1 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -18,7 +18,7 @@ importers: specifier: ^8.12.0 version: 8.12.0 botops-feishu: - specifier: ^0.0.3 + specifier: ^0.0.4 version: link:packages/feishuapi clipboardy: specifier: ^4.0.0 diff --git a/src/deploy.ts b/src/deploy.ts index e4d6c1c..27ffdb4 100644 --- a/src/deploy.ts +++ b/src/deploy.ts @@ -3,6 +3,7 @@ import type { Argv } from 'yargs' import clipboard from 'clipboardy' import Listr from 'listr' import ora from 'ora' +import confirm from '@inquirer/confirm' import { changeArgvToString, greenIt, redIt } from './utils' import { DeployConfig } from './manifest' import { FeishuConfigManager } from './config' @@ -52,9 +53,19 @@ export async function handler(argv: any) { await appBuilder.init() let appId = '' + if (aDeployConfig.ifFirstDeploy) { + // 检测是否有重名的机器人 + const oldAppId = await appBuilder.checkAppName(aDeployConfig.botName) + if (oldAppId) { + const answer = await confirm({ message: 'Detected a bot with the same name, do you want to overwrite it?' }) + if (answer) { + greenIt(`即将覆盖飞书机器人 ${aDeployConfig.botName}(${oldAppId})`) + appId = oldAppId + } + } appId = await appBuilder.newApp(aDeployConfig.botBaseInfo) - greenIt(`飞书机器人 ${aDeployConfig.botName}(${appId}) 初始化成功`) + greenIt(`新的飞书机器人 ${aDeployConfig.botName}(${appId}) 初始化成功`) } else { appId = aDeployConfig.appId as string