title: NameError: name 'command' is not defined
body: <p>I want to send MSSQL data to telegram bot via python. This is what I have written thus far:</p>
  
  <pre><code>import time
  import random
  import datetime
  import telepot
  from telepot.loop import MessageLoop
  
  import pyodbc
  conn = pyodbc.connect('Driver={SQL Server};'
                        'Server=DESKTOP-OM8N0ER\SQLEXPRESS01;'
                        'Database=SmartHome;'
                        'Trusted_Connection=yes;')
  
  cursor = conn.cursor()
  
  def handle(msg):
      chat_id = msg['chat']['id']
      command = msg['text']
  
  print ('Command received: %s') % command
  
  
  if command == '/about':
      bot.sendMessage(chat_id, 'Hi, I\'m netrapsystembot')
  elif command == '/random':
      bot.sendMessage(chat_id, random.randint(0,9))
  elif command == '/time':
      bot.sendMessage(chat_id, str(datetime.datetime.now()))
  
  elif command == '/sessions':
      cursor.execute('SELECT * FROM SmartHome.dbo.SensorData')
      for result in cursor.fetchall():
          bot.sendMessage(chat_id, result [0])
  
  bot = telepot.Bot('803777982:AAEmtO98wjYcqoFqWXOSuYTeg6HFG6xUnwk')
  MessageLoop(bot,handle).run_as_thread()
  print ('Bot ready!')
  
  while 1:
     time.sleep(10)
  </code></pre>
  
  <p>But I am currently receiving this error message at this line:</p>
  
  <pre><code>print ('Command received: %s') % command
  </code></pre>
  
  <blockquote>
    <p>NameError: name 'command' is not defined</p>
  </blockquote>