@@ -9,14 +9,16 @@ import { Input } from '@/components/ui/input'
99import { PasswordInput } from '@/components/ui/password-input'
1010import { Switch } from '@/components/ui/switch'
1111import { Separator } from '@/components/ui/separator'
12- import { Bot , Webhook , Shield , Globe , Smartphone , Send , Users } from 'lucide-react'
12+ import { Select , SelectContent , SelectItem , SelectTrigger , SelectValue } from '@/components/ui/select'
13+ import { Bot , Webhook , Shield , Globe , Smartphone , Send , Users , Settings } from 'lucide-react'
1314import { useSettingsContext } from './_dashboard.settings'
1415import { toast } from 'sonner'
1516
1617// Telegram settings validation schema
1718const telegramSettingsSchema = z . object ( {
1819 enable : z . boolean ( ) . default ( false ) ,
1920 token : z . string ( ) . optional ( ) ,
21+ method : z . enum ( [ 'webhook' , 'long-polling' ] ) . default ( 'webhook' ) ,
2022 webhook_url : z . string ( ) . url ( 'Please enter a valid URL' ) . optional ( ) . or ( z . literal ( '' ) ) . refine ( ( url ) => {
2123 if ( ! url || url === '' ) return true ; // Allow empty URLs
2224 try {
@@ -69,6 +71,7 @@ export default function TelegramSettings() {
6971 defaultValues : {
7072 enable : false ,
7173 token : '' ,
74+ method : 'webhook' ,
7275 webhook_url : '' ,
7376 webhook_secret : '' ,
7477 proxy_url : '' ,
@@ -78,8 +81,9 @@ export default function TelegramSettings() {
7881 }
7982 } )
8083
81- // Watch the enable and mini_app_login fields for conditional rendering
84+ // Watch the enable, method, and mini_app_login fields for conditional rendering
8285 const enableTelegram = form . watch ( 'enable' )
86+ const method = form . watch ( 'method' )
8387
8488 // Update form when settings are loaded
8589 useEffect ( ( ) => {
@@ -88,6 +92,7 @@ export default function TelegramSettings() {
8892 form . reset ( {
8993 enable : telegramData . enable || false ,
9094 token : telegramData . token || '' ,
95+ method : telegramData . method || 'webhook' ,
9196 webhook_url : telegramData . webhook_url || '' ,
9297 webhook_secret : telegramData . webhook_secret || '' ,
9398 proxy_url : telegramData . proxy_url || '' ,
@@ -114,6 +119,7 @@ export default function TelegramSettings() {
114119 form . reset ( {
115120 enable : telegramData . enable || false ,
116121 token : telegramData . token || '' ,
122+ method : telegramData . method || 'webhook' ,
117123 webhook_url : telegramData . webhook_url || '' ,
118124 webhook_secret : telegramData . webhook_secret || '' ,
119125 proxy_url : telegramData . proxy_url || '' ,
@@ -215,6 +221,47 @@ export default function TelegramSettings() {
215221 ) }
216222 />
217223
224+ { /* Method Selection - Only show when Telegram is enabled */ }
225+ { enableTelegram && (
226+ < FormField
227+ control = { form . control }
228+ name = "method"
229+ render = { ( { field } ) => (
230+ < FormItem className = "space-y-2" >
231+ < FormLabel className = "text-sm font-medium flex items-center gap-2" >
232+ < Settings className = "h-4 w-4" />
233+ { t ( 'settings.telegram.general.method' ) }
234+ </ FormLabel >
235+ < Select onValueChange = { field . onChange } value = { field . value } >
236+ < FormControl >
237+ < SelectTrigger className = "w-full" >
238+ < SelectValue placeholder = { t ( 'settings.telegram.general.methodPlaceholder' ) } />
239+ </ SelectTrigger >
240+ </ FormControl >
241+ < SelectContent >
242+ < SelectItem value = "webhook" >
243+ < div className = "flex items-center gap-2" >
244+ < Webhook className = "h-4 w-4" />
245+ { t ( 'settings.telegram.general.webhook' ) }
246+ </ div >
247+ </ SelectItem >
248+ < SelectItem value = "long-polling" >
249+ < div className = "flex items-center gap-2" >
250+ < Send className = "h-4 w-4" />
251+ { t ( 'settings.telegram.general.longPolling' ) }
252+ </ div >
253+ </ SelectItem >
254+ </ SelectContent >
255+ </ Select >
256+ < FormDescription className = "text-sm text-muted-foreground" >
257+ { t ( 'settings.telegram.general.methodDescription' ) }
258+ </ FormDescription >
259+ < FormMessage />
260+ </ FormItem >
261+ ) }
262+ />
263+ ) }
264+
218265 { /* Configuration Fields - Only show when Telegram is enabled */ }
219266 { enableTelegram && (
220267 < div className = "grid grid-cols-1 lg:grid-cols-2 gap-4" >
@@ -242,55 +289,61 @@ export default function TelegramSettings() {
242289 ) }
243290 />
244291
245- < FormField
246- control = { form . control }
247- name = "webhook_url"
248- render = { ( { field } ) => (
249- < FormItem className = "space-y-2" >
250- < FormLabel className = "text-sm font-medium flex items-center gap-2" >
251- < Webhook className = "h-4 w-4" />
252- { t ( 'settings.telegram.general.webhookUrl' ) }
253- </ FormLabel >
254- < FormControl >
255- < Input
256- type = "url"
257- placeholder = { t ( 'settings.telegram.general.webhookUrlPlaceholder' ) }
258- { ...field }
259- className = "font-mono"
260- />
261- </ FormControl >
262- < FormDescription className = "text-sm text-muted-foreground" >
263- { t ( 'settings.telegram.general.webhookUrlDescription' ) }
264- < br />
265- </ FormDescription >
266- < FormMessage />
267- </ FormItem >
268- ) }
269- />
292+ { /* Webhook URL - Only show when method is webhook */ }
293+ { method === 'webhook' && (
294+ < FormField
295+ control = { form . control }
296+ name = "webhook_url"
297+ render = { ( { field } ) => (
298+ < FormItem className = "space-y-2" >
299+ < FormLabel className = "text-sm font-medium flex items-center gap-2" >
300+ < Webhook className = "h-4 w-4" />
301+ { t ( 'settings.telegram.general.webhookUrl' ) }
302+ </ FormLabel >
303+ < FormControl >
304+ < Input
305+ type = "url"
306+ placeholder = { t ( 'settings.telegram.general.webhookUrlPlaceholder' ) }
307+ { ...field }
308+ className = "font-mono"
309+ />
310+ </ FormControl >
311+ < FormDescription className = "text-sm text-muted-foreground" >
312+ { t ( 'settings.telegram.general.webhookUrlDescription' ) }
313+ < br />
314+ </ FormDescription >
315+ < FormMessage />
316+ </ FormItem >
317+ ) }
318+ />
319+ ) }
270320
271- < FormField
272- control = { form . control }
273- name = "webhook_secret"
274- render = { ( { field } ) => (
275- < FormItem className = "space-y-2" >
276- < FormLabel className = "text-sm font-medium flex items-center gap-2" >
277- < Shield className = "h-4 w-4" />
278- { t ( 'settings.telegram.general.webhookSecret' ) }
279- </ FormLabel >
280- < FormControl >
281- < PasswordInput
282- placeholder = { t ( 'settings.telegram.general.webhookSecretPlaceholder' ) }
283- { ...field }
284- className = "font-mono"
285- />
286- </ FormControl >
287- < FormDescription className = "text-sm text-muted-foreground" >
288- { t ( 'settings.telegram.general.webhookSecretDescription' ) }
289- </ FormDescription >
290- < FormMessage />
291- </ FormItem >
292- ) }
293- />
321+ { /* Webhook Secret - Only show when method is webhook */ }
322+ { method === 'webhook' && (
323+ < FormField
324+ control = { form . control }
325+ name = "webhook_secret"
326+ render = { ( { field } ) => (
327+ < FormItem className = "space-y-2" >
328+ < FormLabel className = "text-sm font-medium flex items-center gap-2" >
329+ < Shield className = "h-4 w-4" />
330+ { t ( 'settings.telegram.general.webhookSecret' ) }
331+ </ FormLabel >
332+ < FormControl >
333+ < PasswordInput
334+ placeholder = { t ( 'settings.telegram.general.webhookSecretPlaceholder' ) }
335+ { ...field }
336+ className = "font-mono"
337+ />
338+ </ FormControl >
339+ < FormDescription className = "text-sm text-muted-foreground" >
340+ { t ( 'settings.telegram.general.webhookSecretDescription' ) }
341+ </ FormDescription >
342+ < FormMessage />
343+ </ FormItem >
344+ ) }
345+ />
346+ ) }
294347
295348 < FormField
296349 control = { form . control }
0 commit comments