Update bot messages

This commit is contained in:
2025-07-05 15:35:07 +07:00
parent daef7ddcfc
commit b7f608c8ba
6 changed files with 204 additions and 11 deletions

View File

@@ -2598,6 +2598,41 @@ export class UserClient extends AuthorizedApiBase {
}
return Promise.resolve<User>(null as any);
}
user_TestTelegramChannel(): Promise<string> {
let url_ = this.baseUrl + "/User/telegram-channel/test";
url_ = url_.replace(/[?&]$/, "");
let options_: RequestInit = {
method: "POST",
headers: {
"Accept": "application/json"
}
};
return this.transformOptions(options_).then(transformedOptions_ => {
return this.http.fetch(url_, transformedOptions_);
}).then((_response: Response) => {
return this.processUser_TestTelegramChannel(_response);
});
}
protected processUser_TestTelegramChannel(response: Response): Promise<string> {
const status = response.status;
let _headers: any = {}; if (response.headers && response.headers.forEach) { response.headers.forEach((v: any, k: any) => _headers[k] = v); };
if (status === 200) {
return response.text().then((_responseText) => {
let result200: any = null;
result200 = _responseText === "" ? null : JSON.parse(_responseText, this.jsonParseReviver) as string;
return result200;
});
} else if (status !== 200 && status !== 204) {
return response.text().then((_responseText) => {
return throwException("An unexpected server error occurred.", status, _responseText, _headers);
});
}
return Promise.resolve<string>(null as any);
}
}
export class WorkflowClient extends AuthorizedApiBase {

View File

@@ -88,6 +88,24 @@ function UserInfoSettings() {
}
}
const testTelegramChannel = async () => {
if (!user?.telegramChannel) {
const toast = new Toast('No telegram channel configured')
toast.update('error', 'Please configure a telegram channel first')
return
}
const toast = new Toast('Testing telegram channel...')
try {
const response = await api.user_TestTelegramChannel()
toast.update('success', 'Test message sent! Check your Telegram.')
} catch (error: any) {
console.error('Error testing telegram channel:', error)
const errorMessage = error.response?.data || error.message || 'Failed to send test message'
toast.update('error', errorMessage)
}
}
return (
<div className="container mx-auto p-4">
<div className="bg-base-200 rounded-lg p-6 shadow-lg">
@@ -136,12 +154,22 @@ function UserInfoSettings() {
<div>
<label className="font-semibold">Telegram Channel:</label>
<p>{user?.telegramChannel || 'Not set'}</p>
<button
className="btn btn-primary mt-2"
onClick={() => setShowTelegramModal(true)}
>
Update Telegram Channel
</button>
<div className="flex gap-2 mt-2">
<button
className="btn btn-primary"
onClick={() => setShowTelegramModal(true)}
>
Update Telegram Channel
</button>
{user?.telegramChannel && (
<button
className="btn btn-secondary"
onClick={testTelegramChannel}
>
Test Channel
</button>
)}
</div>
</div>
</div>
</div>