Added socketio and cleaned up output

This commit is contained in:
Daniel Dayley 2023-04-10 14:59:30 -06:00
parent 4a0303f71b
commit f13625dc91
3 changed files with 15 additions and 5 deletions

View File

@ -9,6 +9,7 @@ import persona
from typing import List
from dataclasses import dataclass
import datetime
import requests
import socketio
class LoggingFormatter(logging.Formatter):
@ -56,6 +57,11 @@ if __name__ == '__main__':
logging.getLogger().handlers[0].setFormatter(LoggingFormatter())
logging.propagate=True
# Check for missing environment variables
for required_var in ['BB_SERVER_URL','BB_SERVER_PASSWORD'] :
if required_var not in os.environ.keys() :
log.error(f'Missing required ENV variable {required_var}')
exit(1)
# Create persona instance
test = persona.Persona()
@ -63,8 +69,13 @@ if __name__ == '__main__':
message = persona.Message(text="Hello",sender_identifier="Daniel",chat_identifier=None,attachments=[],timestamp=datetime.datetime.now(), recipients=[], identifier=None)
responses = test.receive_message(message)
for response in responses :
print('Bot responded with:')
print(response.text)
log.warning('Bot responded with:')
log.warning(response.text)
# Create socket connection
sio = socketio.AsyncClient()
sio = socketio.Client()
try :
sio.connect(os.environ['BB_SERVER_URL'])
log.info('Connected to server.')
except socketio.exceptions.ConnectionError as e:
log.error(str(e))

View File

@ -10,7 +10,6 @@ import re
class PersonaSkill(PersonaBaseSkill) :
"""A simple test skill that responds to the message 'Hello' with 'Hello!'"""
def match_intent(self,message: Message) -> Bool :
print(message.text)
matches = re.search('^Hello', message.text)
if matches :
return True

View File

@ -54,7 +54,7 @@ setup(name='bluebubbles_bot',
description='A chatbot for a local BlueBlubbles server.',
packages=find_packages(exclude=['tests']),
package_data={"": ['skills/*.py']},
install_requires=['pyyaml','datetime','python-socketio[asyncio_client]'],
install_requires=['pyyaml','datetime','python-socketio[asyncio_client]','requests','websocket-client'],
scripts=['bin/bluebubbles_bot'],
long_description=open('README.md').read(),
zip_safe=True