Google Apps Script Telegram Bot Commands Not Working Properly

I’m having an issue with my Telegram bot built in Google Apps Script. Some of my bot commands are not responding correctly and keep falling back to the default message instead of executing their specific functions.

function processUserCommands(userMessage, chatIdentifier, msgId) {
  if (userMessage.toLowerCase() === '/register') {
    initiateRegistration(chatIdentifier, msgId);
  } else if (userMessage.toLowerCase() === '/getfiles') {
    initiateFileRequest(chatIdentifier, msgId);
  } else if (userMessage.toLowerCase() === '/fieldinfo') {
    initiateFieldData(chatIdentifier, msgId);
  } else if (userMessage.toLowerCase() === '/location') {
    initiateLocationCheck(chatIdentifier, msgId);
  } else if (userMessage.toLowerCase() === '/verify') {
    initiateVerification(chatIdentifier, msgId);
  } else if (userMessage.toLowerCase() === '/about') {
    initiateInfoDisplay(chatIdentifier, msgId);
  } else if (userMessage.toLowerCase() === '/refresh') {
    initiateSystemUpdate(chatIdentifier, msgId);
  } else if (userMessage.toLowerCase() === '/commands') {
    initiateHelpMenu(chatIdentifier, msgId);
  } else if (userMessage.toLowerCase() === '/clear') {
    clearStoredData();
  } else if (userMessage.toLowerCase() === '/start') {
    sendBotMessage(chatIdentifier, msgId, "Hello! Bot is currently online and ready.");
  } else {
    sendBotMessage(chatIdentifier, msgId, `Hello!\n\nPlease use /commands to see available options`);
  }
}

The weird thing is that /getfiles and /fieldinfo commands always trigger the else condition instead of their intended functions. But other commands like /register and /verify work perfectly fine. I tried creating a completely new script file with the same code and made a fresh bot, and surprisingly all commands worked there. What could be causing this difference between the original and new script files?

This sounds like a caching issue with Google Apps Script. I encountered something similar where certain commands would inexplicably stop working while others functioned normally. The fact that your fresh script works perfectly suggests the problem isn’t with your code logic but rather with the deployment itself. Try redeploying your web app with a new version number - go to Deploy > Manage Deployments > Edit > Create new version. Google Apps Script sometimes gets stuck serving cached versions of your code even after you’ve made changes. Also check if you have any console logs or execution transcript errors that might reveal what’s actually happening when those specific commands are triggered. Another possibility is that your original script has some residual data or variables that are interfering with command processing, which would explain why the clean slate approach worked.

Check if there are any execution timeouts or memory issues with your original script that might be causing specific commands to fail silently. Google Apps Script has execution limits and if your script has accumulated a lot of triggers, properties, or cached data over time, it might be hitting these limits inconsistently. The functions initiateFileRequest and initiateFieldData might be more resource-intensive than your other commands, causing them to timeout and default to the else condition. You can verify this by checking the execution transcript in the Apps Script editor after running these commands. Also examine your script properties and triggers in the original project - sometimes old or duplicate triggers can interfere with command processing in unexpected ways.

hmm sounds like theres some invisible characters or encoding issues in your original script. sometimes when copying code around weird unicode chars get stuck in there that look identical but arent. try manually retyping those problematic command strings instead of copy/paste - ive seen this exact thing before where certain commands fail silently.