lokesh341 commited on
Commit
dfacb27
·
verified ·
1 Parent(s): 01780bf

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +17 -23
app.py CHANGED
@@ -37,23 +37,24 @@ def create_salesforce_record(sf, name, email, phone_number):
37
  except Exception as e:
38
  raise Exception(f"Failed to create record: {str(e)}")
39
 
 
 
 
 
 
 
40
  def create_salesforce_order(sf, cart_items, total_price, customer_id):
 
41
  try:
42
  order = sf.Order__c.create({
43
  'Total_Price__c': total_price,
44
- 'Cart_Items__c': json.dumps(cart_items), # Storing cart items as JSON
45
  'Customer__c': customer_id # Linking to the customer record
46
  })
47
  return order
48
  except Exception as e:
49
  raise Exception(f"Failed to create order: {str(e)}")
50
 
51
- def get_menu_items(sf):
52
- # Query to get menu items from Salesforce (assuming Menu_Item__c is the Salesforce object)
53
- query = "SELECT Name, Price__c, Ingredients__c, Category__c FROM Menu_Item__c"
54
- result = sf.query(query)
55
- return result['records']
56
-
57
  # Voice-related functions
58
  def generate_audio_prompt(text, filename):
59
  try:
@@ -86,42 +87,34 @@ def is_silent_audio(audio_path):
86
  def index():
87
  return render_template("index.html")
88
 
89
- @app.route("/login", methods=["POST"])
90
- def login():
91
- data = request.json # Assuming voice bot sends JSON data
92
- name = data.get('name')
93
- email = data.get('email')
94
- phone_number = data.get('phone_number')
95
-
96
- if not name or not email or not phone_number:
97
- return jsonify({'error': 'Missing required fields'}), 400
98
-
99
- try:
100
- customer_login = create_salesforce_record(sf, name, email, phone_number)
101
- session['customer_id'] = customer_login['id'] # Store customer ID in session
102
- return redirect("/menu") # Redirect to the menu page after successful login
103
- except Exception as e:
104
- return jsonify({'error': f'Failed to create record in Salesforce: {str(e)}'}), 500
105
 
106
  @app.route("/menu", methods=["GET"])
107
  def menu_page():
 
108
  menu_items = get_menu_items(sf) # Fetch menu items from Salesforce
109
  menu_data = [{"name": item['Name'], "price": item['Price__c'], "ingredients": item['Ingredients__c'], "category": item['Category__c']} for item in menu_items]
110
  return render_template("menu_page.html", menu_items=menu_data)
111
 
112
  @app.route("/cart", methods=["GET"])
113
  def cart():
 
114
  cart_items = session.get('cart_items', [])
115
  return render_template("cart_page.html", cart_items=cart_items)
116
 
117
  @app.route("/order-summary", methods=["GET"])
118
  def order_summary():
 
119
  order_details = session.get('cart_items', [])
120
  total_price = sum(item['price'] * item['quantity'] for item in order_details)
121
  return render_template("order_summary.html", order_details=order_details, total_price=total_price)
122
 
123
  @app.route("/final_order", methods=["GET"])
124
  def final_order():
 
125
  cart_items = session.get('cart_items', [])
126
  total_price = sum(item['price'] * item['quantity'] for item in cart_items)
127
  customer_id = session.get('customer_id', None) # Get customer ID from session
@@ -138,6 +131,7 @@ def final_order():
138
 
139
  @app.route("/add_to_cart", methods=["POST"])
140
  def add_to_cart():
 
141
  item_name = request.json.get('item_name')
142
  quantity = request.json.get('quantity')
143
 
 
37
  except Exception as e:
38
  raise Exception(f"Failed to create record: {str(e)}")
39
 
40
+ def get_menu_items(sf):
41
+ # Query to get menu items from Salesforce (assuming Menu_Item__c is the Salesforce object)
42
+ query = "SELECT Name, Price__c, Ingredients__c, Category__c FROM Menu_Item__c"
43
+ result = sf.query(query)
44
+ return result['records']
45
+
46
  def create_salesforce_order(sf, cart_items, total_price, customer_id):
47
+ # Creating an order record in Salesforce after the customer places the final order
48
  try:
49
  order = sf.Order__c.create({
50
  'Total_Price__c': total_price,
51
+ 'Cart_Items__c': json.dumps(cart_items), # Storing cart items as JSON (you can refine this as needed)
52
  'Customer__c': customer_id # Linking to the customer record
53
  })
54
  return order
55
  except Exception as e:
56
  raise Exception(f"Failed to create order: {str(e)}")
57
 
 
 
 
 
 
 
58
  # Voice-related functions
59
  def generate_audio_prompt(text, filename):
60
  try:
 
87
  def index():
88
  return render_template("index.html")
89
 
90
+ @app.route("/dashboard", methods=["GET"])
91
+ def dashboard():
92
+ # This route will render the dashboard page
93
+ return render_template("dashboard.html") # Render the dashboard template
 
 
 
 
 
 
 
 
 
 
 
 
94
 
95
  @app.route("/menu", methods=["GET"])
96
  def menu_page():
97
+ # Fetch the menu items from Salesforce
98
  menu_items = get_menu_items(sf) # Fetch menu items from Salesforce
99
  menu_data = [{"name": item['Name'], "price": item['Price__c'], "ingredients": item['Ingredients__c'], "category": item['Category__c']} for item in menu_items]
100
  return render_template("menu_page.html", menu_items=menu_data)
101
 
102
  @app.route("/cart", methods=["GET"])
103
  def cart():
104
+ # Retrieve cart items from the session
105
  cart_items = session.get('cart_items', [])
106
  return render_template("cart_page.html", cart_items=cart_items)
107
 
108
  @app.route("/order-summary", methods=["GET"])
109
  def order_summary():
110
+ # Retrieve order details from session
111
  order_details = session.get('cart_items', [])
112
  total_price = sum(item['price'] * item['quantity'] for item in order_details)
113
  return render_template("order_summary.html", order_details=order_details, total_price=total_price)
114
 
115
  @app.route("/final_order", methods=["GET"])
116
  def final_order():
117
+ # Process the final order and create an order record in Salesforce
118
  cart_items = session.get('cart_items', [])
119
  total_price = sum(item['price'] * item['quantity'] for item in cart_items)
120
  customer_id = session.get('customer_id', None) # Get customer ID from session
 
131
 
132
  @app.route("/add_to_cart", methods=["POST"])
133
  def add_to_cart():
134
+ # Add item to the cart (example for cart item data: item_name, quantity)
135
  item_name = request.json.get('item_name')
136
  quantity = request.json.get('quantity')
137