-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbot.py
68 lines (49 loc) · 1.86 KB
/
bot.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
import os
import logging
import yaml
from webex_bot.webex_bot import WebexBot
from table_command import TableCommand
log = logging.getLogger(__name__)
# Support a YAML config file that looks like this:
# webex_email: <YOUR CCE ID>@cisco.com
# webex_token: <YOUR WEBEX TOKEN HERE>
CONFIG_FILE_LOCATION = "~/.table_bot.yml"
def parse_yaml_config(config_file_path):
if not os.path.isfile(config_file_path):
log.warn(f"Config file '{config_file_path}' not found.")
return None
config_dict = None
with open(config_file_path, 'r') as file:
try:
config_dict = yaml.load(file, Loader=yaml.FullLoader)
print(config_dict)
except yaml.YAMLError as exc:
log.warning("Error reading config file: "+ exc)
return None
return config_dict
# Gather our required inputs
config = parse_yaml_config(os.path.expanduser(CONFIG_FILE_LOCATION))
if config is None:
config = dict()
log.info(config)
webex_email = os.getenv('WEBEX_EMAIL')
if webex_email is not None:
config['webex_email'] = webex_email
access_token = os.getenv('WEBEX_TEAMS_ACCESS_TOKEN')
if access_token is not None:
config['webex_token'] = access_token
# Make sure we have everything we need
if config.get('webex_email') is None:
log.error(f"The webex email is not found in the config file {CONFIG_FILE_LOCATION} or the environment var WEBEX_EMAIL")
exit(3)
if config.get('webex_token') is None:
log.error(f"The webex token is not found in the config file {CONFIG_FILE_LOCATION} or the environment var WEBEX_TEAMS_ACCESS_TOKEN")
exit(1)
# Create a Bot Object
bot = WebexBot(teams_bot_token=config['webex_token'],
approved_users=[config['webex_email']],
bot_name="Table Bot",
include_demo_commands=False)
# Instatiate the table command
bot.add_command(TableCommand())
bot.run()