企业微信智能机器人API插件
This commit is contained in:
@@ -29,6 +29,7 @@ export * from './city-warehouse';
|
||||
export * from './fulfillment-provider';
|
||||
export * from './system-config';
|
||||
export * from './wecom-bot';
|
||||
export * from './wecom-plugin';
|
||||
export * from './wecom-message-push';
|
||||
export * from './wecom-report';
|
||||
export * from './llm-config';
|
||||
|
||||
@@ -0,0 +1,33 @@
|
||||
import { describe, expect, it } from 'vitest';
|
||||
import {
|
||||
WECOM_PLUGIN_API_KEY_HEADER,
|
||||
WECOM_PLUGIN_BASE_PATH,
|
||||
resolveWecomPluginPublicUrl,
|
||||
} from './wecom-plugin';
|
||||
|
||||
describe('resolveWecomPluginPublicUrl', () => {
|
||||
it('maps HQ production host to api.dukanghaoke.com', () => {
|
||||
expect(resolveWecomPluginPublicUrl('admin.dukanghaoke.com')).toBe(
|
||||
`https://api.dukanghaoke.com${WECOM_PLUGIN_BASE_PATH}`,
|
||||
);
|
||||
});
|
||||
|
||||
it('maps staging hosts to api-test', () => {
|
||||
expect(resolveWecomPluginPublicUrl('admin-test.dukanghaoke.com')).toBe(
|
||||
`https://api-test.dukanghaoke.com${WECOM_PLUGIN_BASE_PATH}`,
|
||||
);
|
||||
expect(resolveWecomPluginPublicUrl('api-test.dukanghaoke.com')).toBe(
|
||||
`https://api-test.dukanghaoke.com${WECOM_PLUGIN_BASE_PATH}`,
|
||||
);
|
||||
});
|
||||
|
||||
it('falls back to local API for unknown hosts', () => {
|
||||
expect(resolveWecomPluginPublicUrl('localhost')).toBe(
|
||||
`http://localhost:3010${WECOM_PLUGIN_BASE_PATH}`,
|
||||
);
|
||||
});
|
||||
|
||||
it('uses X-Api-Key as the plugin auth header', () => {
|
||||
expect(WECOM_PLUGIN_API_KEY_HEADER).toBe('X-Api-Key');
|
||||
});
|
||||
});
|
||||
@@ -0,0 +1,25 @@
|
||||
/** 企微智能机器人 API 插件(只读数据面,与长连接 Bot 独立) */
|
||||
|
||||
export const WECOM_PLUGIN_API_KEY_HEADER = 'X-Api-Key';
|
||||
|
||||
export const WECOM_PLUGIN_BASE_PATH = '/api/v1/wecom/plugin';
|
||||
|
||||
export const WECOM_PLUGIN_PAGE_SIZE_DEFAULT = 5;
|
||||
|
||||
export const WECOM_PLUGIN_PAGE_SIZE_MAX = 10;
|
||||
|
||||
export const WECOM_PLUGIN_METRICS_KINDS = ['today', 'daily', 'weekly', 'monthly'] as const;
|
||||
|
||||
export type WecomPluginMetricsKind = (typeof WECOM_PLUGIN_METRICS_KINDS)[number];
|
||||
|
||||
/** 按 HQ 当前域名推断插件公网 Base URL(不含密钥) */
|
||||
export function resolveWecomPluginPublicUrl(hostname: string): string {
|
||||
const host = String(hostname || '').toLowerCase();
|
||||
if (host === 'admin.dukanghaoke.com' || host === 'api.dukanghaoke.com') {
|
||||
return `https://api.dukanghaoke.com${WECOM_PLUGIN_BASE_PATH}`;
|
||||
}
|
||||
if (host.includes('dukanghaoke.com') && host.includes('test')) {
|
||||
return `https://api-test.dukanghaoke.com${WECOM_PLUGIN_BASE_PATH}`;
|
||||
}
|
||||
return `http://localhost:3010${WECOM_PLUGIN_BASE_PATH}`;
|
||||
}
|
||||
Reference in New Issue
Block a user