Yurii Paniv commited on
Commit
4b03cbe
1 Parent(s): e0ad04f

Add error handling to Telegram bot API

Browse files
Files changed (1) hide show
  1. main.py +11 -7
main.py CHANGED
@@ -79,13 +79,17 @@ def process_voice_message(message):
79
 
80
  # do the recognition
81
  # get the recognized text
82
- text = client(source_audio)
83
- # no results
84
- if not text:
85
- bot.reply_to(message, не зміг розпізнати 😢')
86
- else:
87
- # send the recognized text
88
- bot.reply_to(message, text)
 
 
 
 
89
 
90
 
91
  if __name__ == '__main__':
 
79
 
80
  # do the recognition
81
  # get the recognized text
82
+ try:
83
+ text = client(output_audio)
84
+ # no results
85
+ if not text:
86
+ bot.reply_to(message, 'Я не зміг розпізнати 😢')
87
+ else:
88
+ # send the recognized text
89
+ bot.reply_to(message, text)
90
+ except Exception as e:
91
+ logging.log(logging.ERROR, str(e))
92
+ bot.reply_to(message, 'Трапилась помилка 😢')
93
 
94
 
95
  if __name__ == '__main__':