lokesh341 commited on
Commit
3790dba
·
verified ·
1 Parent(s): 9061545

Update app.py

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