Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -1,5 +1,6 @@
|
|
1 |
import torch
|
2 |
from flask import Flask, render_template, request, jsonify
|
|
|
3 |
import os
|
4 |
from transformers import pipeline
|
5 |
from gtts import gTTS
|
@@ -82,37 +83,30 @@ except Exception as e:
|
|
82 |
print(f"Failed to connect to Salesforce: {str(e)}")
|
83 |
|
84 |
# Function to create Salesforce record
|
85 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
86 |
try:
|
87 |
-
# Attempt to create a record in Salesforce with correct field API names
|
88 |
customer_login = sf.Customer_Login__c.create({
|
89 |
-
'Name': name,
|
90 |
-
'Email__c': email,
|
91 |
-
'Phone_Number__c': phone_number
|
92 |
})
|
93 |
-
|
94 |
-
# Log the full response from Salesforce
|
95 |
-
print(f"Salesforce response: {customer_login}")
|
96 |
-
|
97 |
-
# Check if the response contains an ID (successful creation)
|
98 |
-
if 'id' in customer_login:
|
99 |
-
print(f"Record created successfully with ID: {customer_login['id']}")
|
100 |
-
return customer_login
|
101 |
-
else:
|
102 |
-
# Log detailed information if the record creation failed
|
103 |
-
print(f"Record creation failed. Full response: {customer_login}")
|
104 |
-
# Log any errors if the response contains 'errors'
|
105 |
-
if 'errors' in customer_login:
|
106 |
-
print(f"Salesforce errors: {customer_login['errors']}")
|
107 |
-
return {"error": f"Record creation failed. Full response: {customer_login}"}
|
108 |
except Exception as e:
|
109 |
-
|
110 |
-
error_message = str(e)
|
111 |
-
print(f"Error creating Salesforce record: {error_message}")
|
112 |
-
return {"error": f"Failed to create record in Salesforce: {error_message}"}
|
113 |
-
|
114 |
|
115 |
-
# Correct the indentation here
|
116 |
@app.route("/submit", methods=["POST"])
|
117 |
def submit():
|
118 |
data = request.json
|
|
|
1 |
import torch
|
2 |
from flask import Flask, render_template, request, jsonify
|
3 |
+
import json
|
4 |
import os
|
5 |
from transformers import pipeline
|
6 |
from gtts import gTTS
|
|
|
83 |
print(f"Failed to connect to Salesforce: {str(e)}")
|
84 |
|
85 |
# Function to create Salesforce record
|
86 |
+
# API endpoint to receive data from voice bot
|
87 |
+
@app.route('/login', methods=['POST'])
|
88 |
+
def login():
|
89 |
+
# Get data from voice bot (name, email, phone number)
|
90 |
+
data = request.json # Assuming voice bot sends JSON data
|
91 |
+
|
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 |
+
# Create a record in Salesforce
|
100 |
try:
|
|
|
101 |
customer_login = sf.Customer_Login__c.create({
|
102 |
+
'Name': name,
|
103 |
+
'Email__c': email,
|
104 |
+
'Phone_Number__c': phone_number
|
105 |
})
|
106 |
+
return jsonify({'success': True, 'id': customer_login['id']}), 200
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
107 |
except Exception as e:
|
108 |
+
return jsonify({'error': f'Failed to create record in Salesforce: {str(e)}'}), 500
|
|
|
|
|
|
|
|
|
109 |
|
|
|
110 |
@app.route("/submit", methods=["POST"])
|
111 |
def submit():
|
112 |
data = request.json
|