From d78daef61a98924e678a5a5431aac0b177698954 Mon Sep 17 00:00:00 2001 From: Paul-weqe Date: Sun, 14 Jun 2020 16:58:51 +0300 Subject: [PATCH] Add auth_token in initializer for Bot() --- python_webex/v1/Bot.py | 17 +++++++++++++---- python_webex/v1/Card.py | 3 --- python_webex/v1/Message.py | 10 ++++++---- 3 files changed, 19 insertions(+), 11 deletions(-) diff --git a/python_webex/v1/Bot.py b/python_webex/v1/Bot.py index 7e4f423..4a7e6d5 100644 --- a/python_webex/v1/Bot.py +++ b/python_webex/v1/Bot.py @@ -9,14 +9,22 @@ class Bot(People, Room, Webhook, Message): - def __init__(self): + def __init__(self, auth_token=None): # declare headers and how the token will be gotten from the system self.URL = "https://api.ciscospark.com/" - self.auth_token = os.getenv("auth_token") + + # looks for if the auth_token has been set in the initializer. + # If not, goes looks for the `auth_token` environment variable + self.auth_token = auth_token if auth_token else os.getenv("auth_token") + if self.auth_token == None: - sys.exit("'auth_token' not set in the environment variables") + print("The auth_token needs to be specified for us to identify the bot being specified.") + print("This can be done through: ") + print(" 1. specifying in the intiializer. Bot('auth_token')") + print(" 2. specifying in your environment vairiables. How environment variables are defined depends on your OS") + sys.exit() self.headers = { "Authorization": "Bearer " + self.auth_token, @@ -37,7 +45,8 @@ def __init__(self): } - # default attachment variable will hold the function that is supposed to be the default action whenever an attachment is sent to the bot + # default attachment variable will hold the function that is supposed to be the + # default action whenever an attachment is sent to the bot self.default_attachment = None # maps what will happen when a file is received with a particular type of text diff --git a/python_webex/v1/Card.py b/python_webex/v1/Card.py index 3697d18..896d53d 100644 --- a/python_webex/v1/Card.py +++ b/python_webex/v1/Card.py @@ -121,9 +121,6 @@ def add_input_choiceset( self, input_id: str, input_choices:list=[], input_is_multiselect: bool = False, input_value:str = None ): self.check_if_id_exists(input_id) - print("*" * 70) - print(input_choices) - print("*" * 70) element = { "id": input_id, "type": "Input.ChoiceSet", diff --git a/python_webex/v1/Message.py b/python_webex/v1/Message.py index 38ea125..11dfbb2 100644 --- a/python_webex/v1/Message.py +++ b/python_webex/v1/Message.py @@ -16,10 +16,12 @@ def send_message(self, room_id=None, text=None, files=[]): details on the rooms URL parameters can be found in https://developer.webex.com/docs/api/v1/messages/create-a-message 'files' is a list of the files(images, audios etc) you want to send to the user, if the user wants to attach files with the message - Arguments: - room_id => This is a - text => The text being sent in the message - files => A list of files you want to sell. Each element in the list is a directory path to the file. e.g files=['/this/is/my/path/this_image.jpg', 'this/is/my/second/path/this_pdf.pdf'] + ---- + Arguments + @ room_id: string => This is the ID of the room you are sending the message to + @ text: string => The text being sent in the message + @ files: list of string => A list of files you want to sell. Each element in the list is a directory path to the file. + e.g files=['/this/is/my/path/this_image.jpg', 'this/is/my/second/path/this_pdf.pdf'] """ if room_id == None: sys.exit("'roomId' is a required field")