easyappointments mvp

This commit is contained in:
Gabriel 2022-08-09 15:39:51 -04:00
parent ee0d8c579d
commit 9c717bd7a8
4 changed files with 103 additions and 3 deletions

View file

@ -1,5 +1,4 @@
import random
from turtle import update
import features
api = features.API()
@ -198,6 +197,10 @@ def remove_admin(state, message, sender):
}
def meetings(state,message,sender):
return {
'response':api.appointments.list_upcoming_appointments(sender)
}
def appointments():
@ -219,6 +222,7 @@ commands = {
"!remove footer": remove_footer,
"!add admin": add_admin,
"!remove admin": remove_admin,
"meetings":meetings
}

93
easyappointments.py Normal file
View file

@ -0,0 +1,93 @@
import requests,json
class easyappointments:
def __init__(self,token,url):
self.token = token
self.url = url
self.headers = {"Authorization":"Bearer secrettoken"}
self.appointments = {}
self.services = {}
self.providers = {}
self.customers = {}
self.update_data()
def get_appointments(self):
data = requests.get(self.url+'/api/v1/appointments',headers=self.headers)
return data.json()
def get_services(self):
data = requests.get(self.url+'/api/v1/services',headers=self.headers)
return data.json()
def get_providers(self):
data = requests.get(self.url+'/api/v1/providers',headers=self.headers)
return data.json()
def get_customers(self):
data = requests.get(self.url+'/api/v1/customers',headers=self.headers)
return data.json()
def update_data(self):
appointments = self.get_appointments()
for a in appointments:
self.appointments[a['id']] = a
services = self.get_services()
for s in services:
self.services[s['id']]=s
providers = self.get_providers()
for p in providers:
self.providers[p['id']]=p
customers = self.get_customers()
for c in customers:
self.customers[c['id']]=c
def is_customer(self,mxid):
customers = self.get_customers()
for c in customers:
if mxid in c['notes']:
return c['id']
return False
def is_provider(self,mxid):
providers = self.get_providers()
for p in providers:
if mxid in p['notes']:
return p['id']
def get_upcoming_appointments(self,mxid):
#get services & customers
id = self.is_provider(mxid)
if id:
apts = []
data = self.get_appointments()
for a in data:
if a['providerId'] == id:
apts.append(a)
return apts
else:
return []
def list_upcoming_appointments(self,mxid):
apts = self.get_upcoming_appointments(mxid)
if apts == []:
return "No meetings recorded."
output = ""
for a in apts:
service = self.services[a['serviceId']]['name']
customer = self.customers[a['customerId']]['firstName']
output += f"## {service} with {customer}\nTime:{a['start']}\n"
return output
def register_customer(self,customer_data):
#customer data
"""
{
"firstName":"name",
"lastName":"name",
"email":"email",
"phone":"phone"
"notes":"matrix:mxid"
}
"""
id = requests.post(self.url+'/api/v1/customers',headers=self.headers,data=json.dumps(customer_data)).json()['id']
return id

View file

@ -1,5 +1,6 @@
import json
import requests
import easyappointments
"""
Features
This is the main API for executing functions with data
@ -10,6 +11,7 @@ class API:
def __init__(self):
with open('data.json') as f:
self.data = json.loads(f.read())
self.appointments = easyappointments.easyappointments(self.data['easyappointments']['token'], self.data['easyappointments']['url'])
# Only refresh data when a change is made
def update_data(self):
with open('data.json','r') as f:
@ -115,8 +117,9 @@ class API:
return True
#Meetings
def get_meetings(self):
def get_meetings(self,mxid):
self.update_data()
self.appointments.list_upcoming_appointments(mxid)
pass
def request_meeting(self):
self.update_data()

View file

@ -12,7 +12,7 @@ creds = botlib.Creds(
bot = botlib.Bot(creds)
@bot.listener.on_message_event
async def faq(room, message):
async def message(room, message):
result = commands.handle_command(message.sender, message.body)
if result['response'] != None and result['response'] != "":
await bot.api.send_markdown_message(