Skip to content

Commit fb73da8

Browse files
authored
Merge branch 'master' into feat/maas-support
2 parents 679e549 + b2f4b91 commit fb73da8

File tree

13 files changed

+153
-56
lines changed

13 files changed

+153
-56
lines changed

src/langbot/libs/official_account_api/api.py

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,12 +23,21 @@
2323

2424

2525
class OAClient:
26-
def __init__(self, token: str, EncodingAESKey: str, AppID: str, Appsecret: str, logger: None, unified_mode: bool = False):
26+
def __init__(
27+
self,
28+
token: str,
29+
EncodingAESKey: str,
30+
AppID: str,
31+
Appsecret: str,
32+
logger: None,
33+
unified_mode: bool = False,
34+
api_base_url: str = 'https://api.weixin.qq.com',
35+
):
2736
self.token = token
2837
self.aes = EncodingAESKey
2938
self.appid = AppID
3039
self.appsecret = Appsecret
31-
self.base_url = 'https://api.weixin.qq.com'
40+
self.base_url = api_base_url
3241
self.access_token = ''
3342
self.unified_mode = unified_mode
3443
self.app = Quart(__name__)
@@ -208,12 +217,13 @@ def __init__(
208217
LoadingMessage: str,
209218
logger: None,
210219
unified_mode: bool = False,
220+
api_base_url: str = 'https://api.weixin.qq.com',
211221
):
212222
self.token = token
213223
self.aes = EncodingAESKey
214224
self.appid = AppID
215225
self.appsecret = Appsecret
216-
self.base_url = 'https://api.weixin.qq.com'
226+
self.base_url = api_base_url
217227
self.access_token = ''
218228
self.unified_mode = unified_mode
219229
self.app = Quart(__name__)

src/langbot/libs/wecom_api/api.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,13 +22,14 @@ def __init__(
2222
contacts_secret: str,
2323
logger: None,
2424
unified_mode: bool = False,
25+
api_base_url: str = 'https://qyapi.weixin.qq.com/cgi-bin',
2526
):
2627
self.corpid = corpid
2728
self.secret = secret
2829
self.access_token_for_contacts = ''
2930
self.token = token
3031
self.aes = EncodingAESKey
31-
self.base_url = 'https://qyapi.weixin.qq.com/cgi-bin'
32+
self.base_url = api_base_url
3233
self.access_token = ''
3334
self.secret_for_contacts = contacts_secret
3435
self.logger = logger
@@ -56,7 +57,7 @@ async def check_access_token_for_contacts(self):
5657
return bool(self.access_token_for_contacts and self.access_token_for_contacts.strip())
5758

5859
async def get_access_token(self, secret):
59-
url = f'https://qyapi.weixin.qq.com/cgi-bin/gettoken?corpid={self.corpid}&corpsecret={secret}'
60+
url = f'{self.base_url}/gettoken?corpid={self.corpid}&corpsecret={secret}'
6061
async with httpx.AsyncClient() as client:
6162
response = await client.get(url)
6263
data = response.json()

src/langbot/libs/wecom_customer_service_api/api.py

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,13 +13,22 @@
1313

1414

1515
class WecomCSClient:
16-
def __init__(self, corpid: str, secret: str, token: str, EncodingAESKey: str, logger: None, unified_mode: bool = False):
16+
def __init__(
17+
self,
18+
corpid: str,
19+
secret: str,
20+
token: str,
21+
EncodingAESKey: str,
22+
logger: None,
23+
unified_mode: bool = False,
24+
api_base_url: str = 'https://qyapi.weixin.qq.com/cgi-bin',
25+
):
1726
self.corpid = corpid
1827
self.secret = secret
1928
self.access_token_for_contacts = ''
2029
self.token = token
2130
self.aes = EncodingAESKey
22-
self.base_url = 'https://qyapi.weixin.qq.com/cgi-bin'
31+
self.base_url = api_base_url
2332
self.access_token = ''
2433
self.logger = logger
2534
self.unified_mode = unified_mode
@@ -66,7 +75,7 @@ async def check_access_token_for_contacts(self):
6675
return bool(self.access_token_for_contacts and self.access_token_for_contacts.strip())
6776

6877
async def get_access_token(self, secret):
69-
url = f'https://qyapi.weixin.qq.com/cgi-bin/gettoken?corpid={self.corpid}&corpsecret={secret}'
78+
url = f'{self.base_url}/gettoken?corpid={self.corpid}&corpsecret={secret}'
7079
async with httpx.AsyncClient() as client:
7180
response = await client.get(url)
7281
data = response.json()
@@ -172,7 +181,7 @@ async def send_text_msg(self, open_kfid: str, external_userid: str, msgid: str,
172181
if not await self.check_access_token():
173182
self.access_token = await self.get_access_token(self.secret)
174183

175-
url = f'https://qyapi.weixin.qq.com/cgi-bin/kf/send_msg?access_token={self.access_token}'
184+
url = f'{self.base_url}/kf/send_msg?access_token={self.access_token}'
176185

177186
payload = {
178187
'touser': external_userid,

src/langbot/pkg/platform/sources/officialaccount.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,7 @@ def __init__(self, config: dict, logger: EventLogger):
7676
AppID=config['AppID'],
7777
logger=logger,
7878
unified_mode=True,
79+
api_base_url=config.get('api_base_url', 'https://api.weixin.qq.com'),
7980
)
8081
elif config['Mode'] == 'passive':
8182
bot = OAClientForLongerResponse(
@@ -86,6 +87,7 @@ def __init__(self, config: dict, logger: EventLogger):
8687
LoadingMessage=config.get('LoadingMessage', ''),
8788
logger=logger,
8889
unified_mode=True,
90+
api_base_url=config.get('api_base_url', 'https://api.weixin.qq.com'),
8991
)
9092
else:
9193
raise KeyError('请设置微信公众号通信模式')

src/langbot/pkg/platform/sources/officialaccount.yaml

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,16 @@ spec:
5353
type: string
5454
required: true
5555
default: "AI正在思考中,请发送任意内容获取回复。"
56+
- name: api_base_url
57+
label:
58+
en_US: API Base URL
59+
zh_Hans: API 基础 URL
60+
description:
61+
en_US: API Base URL, used for accessing the Official Account API. If you are deploying in an internal network environment and accessing the Official Account API through a reverse proxy, please fill in this item according to the documentation.
62+
zh_Hans: 可选,若您部署在内网环境并通过反向代理访问微信公众号 API,可根据文档修改此项
63+
type: string
64+
required: false
65+
default: "https://api.weixin.qq.com"
5666
execution:
5767
python:
5868
path: ./officialaccount.py

src/langbot/pkg/platform/sources/wecom.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -170,6 +170,7 @@ def __init__(self, config: dict, logger: EventLogger):
170170
contacts_secret=config['contacts_secret'],
171171
logger=logger,
172172
unified_mode=True,
173+
api_base_url=config.get('api_base_url', 'https://qyapi.weixin.qq.com/cgi-bin'),
173174
)
174175

175176
super().__init__(

src/langbot/pkg/platform/sources/wecom.yaml

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,16 @@ spec:
4646
type: string
4747
required: true
4848
default: ""
49+
- name: api_base_url
50+
label:
51+
en_US: API Base URL
52+
zh_Hans: API 基础 URL
53+
description:
54+
en_US: API Base URL, used for accessing the WeCom API. If you are deploying in an internal network environment and accessing the WeCom Customer Service API through a reverse proxy, please fill in this item according to the documentation.
55+
zh_Hans: 可选,若您部署在内网环境并通过反向代理访问企业微信 API,可根据文档填写此项
56+
type: string
57+
required: false
58+
default: "https://qyapi.weixin.qq.com/cgi-bin"
4959
execution:
5060
python:
5161
path: ./wecom.py

src/langbot/pkg/platform/sources/wecomcs.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -141,6 +141,7 @@ def __init__(self, config: dict, logger: abstract_platform_logger.AbstractEventL
141141
EncodingAESKey=config['EncodingAESKey'],
142142
logger=logger,
143143
unified_mode=True,
144+
api_base_url=config.get('api_base_url', 'https://qyapi.weixin.qq.com/cgi-bin'),
144145
)
145146

146147
super().__init__(

src/langbot/pkg/platform/sources/wecomcs.yaml

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,16 @@ spec:
3939
type: string
4040
required: true
4141
default: ""
42+
- name: api_base_url
43+
label:
44+
en_US: API Base URL
45+
zh_Hans: API 基础 URL
46+
description:
47+
en_US: API Base URL, used for accessing the WeCom API. If you are deploying in an internal network environment and accessing the WeCom Customer Service API through a reverse proxy, please fill in this item according to the documentation.
48+
zh_Hans: 可选,若您部署在内网环境并通过反向代理访问企业微信 API,可根据文档修改此项
49+
type: string
50+
required: false
51+
default: "https://qyapi.weixin.qq.com/cgi-bin"
4252
execution:
4353
python:
4454
path: ./wecomcs.py

web/src/app/home/bots/components/bot-form/BotForm.tsx

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ import { useForm } from 'react-hook-form';
1919
import { z } from 'zod';
2020
import { toast } from 'sonner';
2121
import { useTranslation } from 'react-i18next';
22+
import { Copy, Check } from 'lucide-react';
2223

2324
import {
2425
Dialog,
@@ -116,6 +117,7 @@ export default function BotForm({
116117
const [, setIsLoading] = useState<boolean>(false);
117118
const [webhookUrl, setWebhookUrl] = useState<string>('');
118119
const webhookInputRef = React.useRef<HTMLInputElement>(null);
120+
const [copied, setCopied] = useState<boolean>(false);
119121

120122
// Watch adapter and adapter_config for filtering
121123
const currentAdapter = form.watch('adapter');
@@ -153,7 +155,6 @@ export default function BotForm({
153155
const inputElement = webhookInputRef.current;
154156
if (!inputElement) {
155157
console.error('[Copy] Input element not found');
156-
toast.error(t('common.copyFailed'));
157158
return;
158159
}
159160

@@ -178,7 +179,8 @@ export default function BotForm({
178179
console.log('[Copy] Clipboard API success');
179180
inputElement.blur(); // 取消选中
180181
inputElement.readOnly = true;
181-
toast.success(t('bots.webhookUrlCopied'));
182+
setCopied(true);
183+
setTimeout(() => setCopied(false), 2000);
182184
})
183185
.catch((err) => {
184186
console.error(
@@ -191,9 +193,8 @@ export default function BotForm({
191193
inputElement.blur();
192194
inputElement.readOnly = true;
193195
if (successful) {
194-
toast.success(t('bots.webhookUrlCopied'));
195-
} else {
196-
toast.error(t('common.copyFailed'));
196+
setCopied(true);
197+
setTimeout(() => setCopied(false), 2000);
197198
}
198199
});
199200
} else {
@@ -207,15 +208,13 @@ export default function BotForm({
207208
inputElement.blur();
208209
inputElement.readOnly = true;
209210
if (successful) {
210-
toast.success(t('bots.webhookUrlCopied'));
211-
} else {
212-
toast.error(t('common.copyFailed'));
211+
setCopied(true);
212+
setTimeout(() => setCopied(false), 2000);
213213
}
214214
}
215215
} catch (err) {
216216
console.error('[Copy] Copy failed:', err);
217217
inputElement.readOnly = true;
218-
toast.error(t('common.copyFailed'));
219218
}
220219
};
221220

@@ -548,6 +547,11 @@ export default function BotForm({
548547
size="sm"
549548
onClick={copyToClipboard}
550549
>
550+
{copied ? (
551+
<Check className="h-4 w-4 text-green-600 mr-2" />
552+
) : (
553+
<Copy className="h-4 w-4 mr-2" />
554+
)}
551555
{t('common.copy')}
552556
</Button>
553557
</div>

0 commit comments

Comments
 (0)