I am trying to make a telegram bot to establish a user interface for an action detection algorithm.
What I am trying to do is that: Once the algorithm detects a predefined action, it sends related information to my python bot-script and runs it. The script will drive the bot to generate an alert to a registered user.
(Note that the script will be called everytime a detection is made)
The code of the script is as shown below:
import argparse
import telepot as tp
# parse arguments
parser = argparse.ArgumentParser(description = 'Send telegram alert when an action is detected')
parser.add_argument('loc', help = 'the location where the action is detected')
parser.add_argument('id', help = 'the camera id that spot this action')
parser.add_argument('img', help = "the url of the frame where the action is detected")
args = parser.parse_args()
# read arguments from command-line
loc = args.loc
cam_id = args.id
img = args.img
# set bot & chat info
bot_token = 'XXXXXXX'
chat_id = YYYY
# define text to be sent
text = "Action Detected!\nLocation: {}\nCamera id: {}".format(loc,cam_id)
# send alert
bot = tp.Bot(bot_token)
bot.sendMessage(chat_id,text)
bot.sendPhoto(chat_id,open(img,'rb'))
The issue with this script is that the chat_id is hardcoded into it, which would be a big problem when I want to use this bot to alert a different user.
Is there a decent way that I can get the chat_id within this script while preserving its other functionalities (receiving parameters)?
(If possible: are there any better architectures/methods to fulfill this task?)