Skip to content
This repository has been archived by the owner on Aug 14, 2023. It is now read-only.

Commit

Permalink
New notify_admins function;Changed message for fatal error of PROJECT_ID
Browse files Browse the repository at this point in the history
  • Loading branch information
horrific committed May 11, 2018
1 parent 4e21d48 commit cde42ec
Showing 1 changed file with 11 additions and 11 deletions.
22 changes: 11 additions & 11 deletions run.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,14 @@
from lang import NOT_UNDERSTOOD


def notify_admins(message):
for admin_id in ADMIN_CHAT_ID:
try:
BOT.sendMessage(admin_id, text=message)
except telegram.error.BadRequest:
logging.warning('Admin chat_id %s unreachable', admin_id)


def start(bot, update):
chat_id = update.message.chat_id
bot.send_chat_action(chat_id=chat_id, action=telegram.ChatAction.TYPING)
Expand Down Expand Up @@ -120,7 +128,7 @@ def ogg_to_mp3(ogg_path, mp3_path):
try:
PROJECT_ID = json.load(open(DIALOGFLOW_KEY))["project_id"]
except FileNotFoundError:
logging.fatal(sys.exc_info()[1])
logging.fatal("Unable to retrieve the PROJECT_ID of Dialogflow")
sys.exit(-1)
os.environ["GOOGLE_APPLICATION_CREDENTIALS"] = DIALOGFLOW_KEY
DIALOGFLOW = dialogflow.SessionsClient()
Expand All @@ -134,11 +142,7 @@ def ogg_to_mp3(ogg_path, mp3_path):
UPDATER = Updater(token=TELEGRAM_TOKEN)
DISPATCHER = UPDATER.dispatcher
logging.info('Bot started')
for admin_id in ADMIN_CHAT_ID:
try:
BOT.sendMessage(admin_id, text='Bot started.')
except telegram.error.BadRequest:
logging.warning('Admin chat_id %s unreachable', admin_id)
notify_admins('Bot started')

# Add telegram handlers
START_HANDLER = CommandHandler('start', start)
Expand All @@ -154,9 +158,5 @@ def ogg_to_mp3(ogg_path, mp3_path):
# Start polling and wait on idle state
UPDATER.start_polling()
UPDATER.idle()
for admin_id in ADMIN_CHAT_ID:
try:
BOT.sendMessage(admin_id, text='Program aborted.')
except telegram.error.BadRequest:
logging.warning('Admin chat_id %s unreachable', admin_id)
notify_admins('Program aborted')
logging.info('Program aborted')

0 comments on commit cde42ec

Please sign in to comment.