ConvAI server output had changed a bit
@@ -64,7 +64,8 @@ class ConvAIWorld(World):
self.router_bot_pull_delay = 1
# Id of local bot used to communicate with RouterBot
self.bot_id = opt['bot_id']
- # The maximum number of open dialogs. Use -1 for unlimited number of open dialogs
+ # The maximum number of open dialogs.
+ # Use -1 for unlimited number of open dialogs
self.bot_capacity = opt['bot_capacity']
# RouterBot url with current bot id
self.bot_url = self.router_bot_url + self.bot_id
@@ -108,7 +109,8 @@ class ConvAIWorld(World):
'Content-Type': 'application/json'
}
- res = requests.post(self.bot_url + '/sendMessage', json=message, headers=headers)
+ res = requests.post(self.bot_url + '/sendMessage',
+ json=message, headers=headers)
if res.status_code != 200:
print(res.text)
res.raise_for_status()
@@ -173,37 +175,46 @@ class ConvAIWorld(World):
self.cleanup_finished_chat(chatID)
def pull_new_messages(self):
- """Requests server for new messages and processes every message.
- If message starts with '/start' then will create new chat and adds message to stack.
- If message has same id as already existing chat then will add to message stack.
- Other messages will be ignored.
- If after processing all messages message stack is still empty then new request to server will be performed.
+ """Requests the server for new messages and processes every message.
+ If a message starts with '/start' string then a new chat will be created and
+ the message will be added to stack.
+ If a message has the same chat id as already existing chat then it will be
+ added to message stack for this chat.
+ Any other messages will be ignored.
+ If after processing all messages message stack is still empty then new request
+ to server will be performed.
:return: None
"""
print('Waiting for new messages from server...', flush=True)
while True:
time.sleep(self.router_bot_pull_delay)
msgs = self._get_updates()
- if len(msgs) > 0:
- for msg in msgs:
+ if len(msgs["result"]) > 0:
+ for msg in msgs["result"]:
print('\nProceed message: %s' % msg)
text = self._get_message_text(msg)
chatID = self._get_chat_id(msg)
if self.chats.get(chatID, None) is not None:
- print('Message was recognized as part of chat #%s' % chatID)
+ print('Message was recognized as part of chat #%s'
+ % chatID)
self.messages.append((chatID, text))
elif self._is_begin_of_conversation(text):
- print('Message was recognised as start of new chat #%s' % chatID)
- if self.bot_capacity == -1 or 0 <= self.bot_capacity > (len(self.chats) - len(self.finished_chats)):
+ print('Message was recognised as start of new chat #%s'
+ % chatID)
+ if self.bot_capacity == -1 or 0 <= self.bot_capacity > \
+ (len(self.chats) - len(self.finished_chats)):
self._init_chat(chatID)
text = self._strip_start_message(text)
self.messages.append((chatID, text))
- print('New world and agents for chat #%s created.' % chatID)
+ print('New world and agents for chat #%s are created.'
+ % chatID)
else:
- print('Cannot start new chat #%s due to bot capacity limit reached.' % chatID)
+ print('Cannot start new chat #%s due to bot capacity'
+ 'limit reached.' % chatID)
else:
- print('Message was not recognized as part of any chat. Message skipped.')
+ print('Message was not recognized as part of any chat.'
+ 'Message skipped.')
if len(self.messages) > 0:
break
else:
