@@ -2,6 +2,7 @@ import { Router, Request, Response, RequestHandler } from 'express'
22import { Knex } from 'knex'
33import * as dotenv from 'dotenv'
44import path from 'path'
5+ import { globalState } from '../utils/globalState'
56
67// Type definition for telegram update
78interface TelegramUpdate {
@@ -220,6 +221,33 @@ export function createTelegramRouter(db: Knex): Router {
220221 }
221222 }
222223
224+ // Command for controlling submissions
225+ if ( lowerCaseMessage . startsWith ( 'submissions:' ) ) {
226+ const submissionsValue = message . substring ( 'submissions:' . length ) . trim ( )
227+
228+ if ( submissionsValue === '1' ) {
229+ globalState . setSubmissionsEnabled ( true )
230+ return res . status ( 200 ) . json ( {
231+ method : 'sendMessage' ,
232+ chat_id : chatId ,
233+ text : 'Submissions have been enabled.' ,
234+ } )
235+ } else if ( submissionsValue === '0' ) {
236+ globalState . setSubmissionsEnabled ( false )
237+ return res . status ( 200 ) . json ( {
238+ method : 'sendMessage' ,
239+ chat_id : chatId ,
240+ text : 'Submissions have been disabled.' ,
241+ } )
242+ } else {
243+ return res . status ( 200 ) . json ( {
244+ method : 'sendMessage' ,
245+ chat_id : chatId ,
246+ text : 'Invalid submissions value. Use "submissions: 1" to enable or "submissions: 0" to disable.' ,
247+ } )
248+ }
249+ }
250+
223251 // If none of the commands matched, send help message
224252 return res . status ( 200 ) . json ( {
225253 method : 'sendMessage' ,
@@ -229,9 +257,11 @@ export function createTelegramRouter(db: Knex): Router {
229257 '- "public apps: 1, 2, 3" or "public apps: 1-10" - Make specified apps public\n' +
230258 '- "public templates: 1, 2, 3" or "public templates: 1-10" - Make specified templates public\n' +
231259 '- "private apps: 1, 2, 3" or "private apps: 1-10" - Make specified apps private\n' +
232- '- "private templates: 1, 2, 3" or "private templates: 1-10" - Make specified templates private' ,
260+ '- "private templates: 1, 2, 3" or "private templates: 1-10" - Make specified templates private\n' +
261+ '- "submissions: 1" - Enable submissions\n' +
262+ '- "submissions: 0" - Disable submissions' ,
233263 } )
234- } catch ( error ) {
264+ } catch ( error : unknown ) {
235265 console . error ( 'Error processing telegram webhook:' , error )
236266 res . sendStatus ( 200 ) // Always respond with 200 to Telegram
237267 }
0 commit comments