-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathstartBot.py
73 lines (53 loc) · 2.21 KB
/
startBot.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
69
70
71
72
73
import time
import botbuilder
import modules.botlog as botlog
import modules.command.commandhub as hub
import modules.symphony.datafeed as datafeed
import modules.plugins.commandloader as cmdloader
import modules.symphony.messaging as messaging
import os
import codecs
import json
#Grab the config.json main parameters
_configPathdDefault = os.path.abspath('config.json')
with codecs.open(_configPathdDefault, 'r', 'utf-8-sig') as json_file:
_configDef = json.load(json_file)
loopCount = 0
def Main():
global loopCount
botlog.LogSymphonyInfo('Starting Symphony Zendesk Bot session...')
botSession = botbuilder.SymSession()
# Bot Loop Begins here
loopControl = botSession.StartBot()
loopCount = 0
# Pre-load the command definitions
cmdloader.LoadAllCommands()
#messaging.SendSymphonyMessage(_configDef['BotStreamForPing'], "Starting Bot session")
while loopControl:
messages = datafeed.PollDataFeed(botSession.DataFeedId)
if messages is not None:
if len(messages) == 0:
# botlog.LogConsoleInfo('204 - No Content')
# messaging.SendSymphonyMessage(_configDef['BotStreamForPing'], "Just a ping to keep the bot alive")
pass
for msg in messages:
if msg.IsValid and msg.Sender.IsValidSender:
hub.ProcessCommand(msg)
else:
botlog.LogSymphonyInfo('Error detected reading datafeed. Invalidating session...')
#messaging.SendSymphonyMessage(_configDef['BotStreamForPing'], "Error detected reading datafeed. Invalidating session...")
botSession.InvalidateSession()
loopControl = False
loopControl = botSession.StartBot()
while loopCount < 10:
try:
Main()
except SystemExit:
loopCount = 99
pass
except Exception as ex:
botlog.LogSystemError('Error: ' + str(ex))
botlog.LogSymphonyError('Unhandled error, probably network difficulties at the Agent. Retrying in 5s.')
#messaging.SendSymphonyMessage(_configDef['BotStreamForPing'],"There seems to be some network difficulties at the Agent. Please try again in 5s.")
time.sleep(5)
loopCount += 1