CHANGE_ : Chat Bot Flow Changes
This commit is contained in:
parent
a674dbac42
commit
a5d53b6803
8
.env
8
.env
@ -1,4 +1,4 @@
|
||||
API_URL=https://venbait.in/nhance/dev/employeeRest/
|
||||
TICKET_API_URL=https://venbait.in/nhance/helpdesk/dev/api
|
||||
BASE_HREF=/nhance/employee/dev/
|
||||
ENV=development
|
||||
API_URL=https://dev.venbait.in/nhance/uat/employeeRest/
|
||||
TICKET_API_URL=https://dev.venbait.in/nhance/helpdesk/uat/api
|
||||
BASE_HREF=/nhance/employee/uat/
|
||||
ENV=production
|
||||
BIN
assets/Nhance_N.png
Normal file
BIN
assets/Nhance_N.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 7.6 KiB |
@ -993,7 +993,8 @@ class _addOnsDetailsState extends State<addOnsDetails> {
|
||||
var calculation = {
|
||||
'client_policy_id': topUpClientPolicyId,
|
||||
'emp_code': empCodeString,
|
||||
'si': choosedSiValue
|
||||
'si': choosedSiValue,
|
||||
'client_branch_id': empClientBranchId
|
||||
};
|
||||
|
||||
print(calculation);
|
||||
@ -1058,7 +1059,8 @@ class _addOnsDetailsState extends State<addOnsDetails> {
|
||||
var calculation = {
|
||||
'client_policy_id': topUpParentClientPolicyId,
|
||||
'emp_code': empCodeString,
|
||||
'si': choosedSiValue
|
||||
'si': choosedSiValue,
|
||||
'client_branch_id': empClientBranchId
|
||||
};
|
||||
|
||||
print(calculation);
|
||||
@ -1125,7 +1127,8 @@ class _addOnsDetailsState extends State<addOnsDetails> {
|
||||
var calculation = {
|
||||
'client_policy_id': addOnsDependentClientPolicyId,
|
||||
'emp_code': empCodeString,
|
||||
'si': choosedDependentValue
|
||||
'si': choosedDependentValue,
|
||||
'client_branch_id': empClientBranchId
|
||||
};
|
||||
|
||||
print(calculation);
|
||||
|
||||
@ -85,6 +85,7 @@ class _empDetailsState extends State<empDetails> {
|
||||
dynamic selfEmpCode;
|
||||
dynamic selfFamilyFloaterKey;
|
||||
dynamic selfEmpStatus;
|
||||
dynamic selfUnit;
|
||||
dynamic gmcDataIsEmpty = 1;
|
||||
dynamic gpaDataIsEmpty = 1;
|
||||
dynamic hrPrimaryId;
|
||||
@ -219,6 +220,7 @@ class _empDetailsState extends State<empDetails> {
|
||||
selfFamilyFloaterKey = selfDetails['family_floater_key'];
|
||||
// print(clientDetails);
|
||||
selfEmpStatus = selfDetails['emp_status'];
|
||||
selfUnit = selfDetails['unit'];
|
||||
});
|
||||
final SharedPreferences prefs = await SharedPreferences.getInstance();
|
||||
prefs.setString('selfEmpStatus', selfEmpStatus);
|
||||
@ -458,6 +460,7 @@ class _empDetailsState extends State<empDetails> {
|
||||
'client_policy_id': floatedData['client_policy_id'],
|
||||
'created_by': primaryId,
|
||||
'is_createdby_hr': is_createdby_hr,
|
||||
'unit': selfUnit,
|
||||
// Add the 'id' field only if action is 'Edit'
|
||||
if (action == 'Edit') 'id': floatedData['employee_id'],
|
||||
});
|
||||
|
||||
@ -1,6 +1,8 @@
|
||||
import 'package:dash_chat_2/dash_chat_2.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:nhance_app_pwa/pages/postEnrollment/service/api_service.dart';
|
||||
import 'package:shared_preferences/shared_preferences.dart';
|
||||
import 'package:url_launcher/url_launcher.dart';
|
||||
import '../../customAppBar/customAppBar.dart';
|
||||
import 'data.dart';
|
||||
|
||||
@ -18,6 +20,11 @@ class _chatbotState extends State<chatbot> {
|
||||
dynamic returnMessage;
|
||||
dynamic mobileNo;
|
||||
dynamic policyID;
|
||||
dynamic empCode;
|
||||
dynamic empClientBranchId;
|
||||
dynamic client_id;
|
||||
dynamic navigation_type;
|
||||
dynamic navigation;
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
@ -32,8 +39,31 @@ class _chatbotState extends State<chatbot> {
|
||||
}
|
||||
|
||||
void quickReplyOptions() async {
|
||||
final response =
|
||||
await apiService.getBotDetails('Start', '1', '0', '', '', '');
|
||||
final SharedPreferences prefs = await SharedPreferences.getInstance();
|
||||
empCode = prefs.getString('empCode');
|
||||
empClientBranchId = prefs.getString('empClientBranchId');
|
||||
client_id = prefs.getString('client_id');
|
||||
Map<String, dynamic> chatBotDataApi = {
|
||||
'request_for': 'Start',
|
||||
'is_option': '1',
|
||||
'option': '0',
|
||||
'mobile_no': '',
|
||||
'policy_id': '',
|
||||
'emp_code': empCode,
|
||||
'client_id': client_id,
|
||||
'client_branch_id': empClientBranchId
|
||||
};
|
||||
chatBotDataApi =
|
||||
chatBotDataApi.map((key, value) => MapEntry(key, value.toString()));
|
||||
// final url;
|
||||
// if (is_option != '0') {
|
||||
// url = Uri.parse(
|
||||
// '${Environment.apiUrl}getChatResponse?request_for=$requestFor&is_option=$is_option&option=$option&mobile_no=$mobileNo&policy_id=$policyID');
|
||||
// } else {
|
||||
// url = Uri.parse(
|
||||
// '${Environment.apiUrl}getChatResponse?request_for=$requestFor&is_option=$is_option&text=$returnMessage&value=$option&mobile_no=$mobileNo&policy_id=$policyID');
|
||||
// }
|
||||
final response = await apiService.getBotDetails(chatBotDataApi);
|
||||
print(response);
|
||||
if (response['status'] == 'success') {
|
||||
print('check 2');
|
||||
@ -45,6 +75,9 @@ class _chatbotState extends State<chatbot> {
|
||||
print('isOptionStatus: $isOptionStatus');
|
||||
requestStatus = data['request_for'];
|
||||
print('requestStatus: $requestStatus');
|
||||
navigation = data['navigation'];
|
||||
navigation_type = data['navigation_type'];
|
||||
|
||||
setState(() {
|
||||
firstApiOptions = Map<String, String>.from(optionsData);
|
||||
print('firstApiOptions: $firstApiOptions');
|
||||
@ -107,10 +140,51 @@ class _chatbotState extends State<chatbot> {
|
||||
messages.insert(0, loadingMessage);
|
||||
});
|
||||
|
||||
Map<String, dynamic> chatBotDataApi;
|
||||
if (isOptionStatus != '0') {
|
||||
chatBotDataApi = {
|
||||
'request_for': requestStatus,
|
||||
'is_option': isOptionStatus,
|
||||
'option': messageText,
|
||||
'mobile_no': '',
|
||||
'policy_id': '',
|
||||
'emp_code': empCode,
|
||||
'client_id': client_id,
|
||||
'client_branch_id': empClientBranchId
|
||||
};
|
||||
} else {
|
||||
chatBotDataApi = {
|
||||
'request_for': requestStatus,
|
||||
'is_option': isOptionStatus,
|
||||
'text': returnMessage,
|
||||
'value': messageText,
|
||||
'mobile_no': mobileNo,
|
||||
'policy_id': policyID,
|
||||
'emp_code': empCode,
|
||||
'client_id': client_id,
|
||||
'client_branch_id': empClientBranchId
|
||||
};
|
||||
}
|
||||
|
||||
chatBotDataApi =
|
||||
chatBotDataApi.map((key, value) => MapEntry(key, value.toString()));
|
||||
|
||||
// Simulate API call with a delay of 2 seconds
|
||||
await Future.delayed(Duration(seconds: 2));
|
||||
final response = await apiService.getBotDetails(requestStatus,
|
||||
isOptionStatus, messageText, returnMessage, mobileNo, policyID);
|
||||
// final response = await apiService.getBotDetails(requestStatus,
|
||||
// isOptionStatus, messageText, returnMessage, mobileNo, policyID);
|
||||
// Future<Map<String, dynamic>> getBotDetails(String requestFor, is_option,
|
||||
// option, returnMessage, mobileNo, policyID)
|
||||
// final url;
|
||||
// if (is_option != '0') {
|
||||
// url = Uri.parse(
|
||||
// '${Environment.apiUrl}getChatResponse?request_for=$requestFor&is_option=$is_option&option=$option&mobile_no=$mobileNo&policy_id=$policyID');
|
||||
// } else {
|
||||
// url = Uri.parse(
|
||||
// '${Environment.apiUrl}getChatResponse?request_for=$requestFor&is_option=$is_option&text=$returnMessage&value=$option&mobile_no=$mobileNo&policy_id=$policyID');
|
||||
// }
|
||||
|
||||
final response = await apiService.getBotDetails(chatBotDataApi);
|
||||
|
||||
if (response['status'] == 'success') {
|
||||
dynamic chatApiData = response['data'];
|
||||
@ -119,6 +193,8 @@ class _chatbotState extends State<chatbot> {
|
||||
returnMessage = chatApiData['text'];
|
||||
isOptionStatus = chatApiData['is_option'];
|
||||
requestStatus = chatApiData['request_for'];
|
||||
navigation = chatApiData['navigation'];
|
||||
navigation_type = chatApiData['navigation_type'];
|
||||
|
||||
if (chatApiData.containsKey('mobile_no')) {
|
||||
mobileNo = chatApiData['mobile_no'];
|
||||
@ -128,27 +204,49 @@ class _chatbotState extends State<chatbot> {
|
||||
}
|
||||
|
||||
setState(() {
|
||||
print(returnMessage);
|
||||
// Split and format the returnMessage
|
||||
String formattedMessage = '';
|
||||
if (returnMessage != null) {
|
||||
if (returnMessage.contains('%')) {
|
||||
try {
|
||||
List<String> messageParts = returnMessage
|
||||
.split('%')
|
||||
.map((part) => part.trim())
|
||||
.cast<String>()
|
||||
.toList();
|
||||
formattedMessage = messageParts
|
||||
.asMap()
|
||||
.map((index, part) => MapEntry(index, '${index + 1}. $part'))
|
||||
.values
|
||||
.join('\n');
|
||||
} catch (e) {
|
||||
print('Error splitting returnMessage: $e');
|
||||
formattedMessage = returnMessage; // Fallback to original message
|
||||
if (navigation == '1') {
|
||||
if (navigation_type == 'form') {
|
||||
if (returnMessage == 'open_service_form' ||
|
||||
returnMessage == 'open_sales_form' ||
|
||||
returnMessage == 'open_gmc_form' ||
|
||||
returnMessage == 'open_gpa_form') {
|
||||
var details = {'claimsDetails': '', 'fromClaimPage': 1};
|
||||
Navigator.pushNamed(context, 'planclaimsform',
|
||||
arguments: details);
|
||||
}
|
||||
} else if (navigation_type == 'dialpad') {
|
||||
print(returnMessage);
|
||||
_openDialPad(returnMessage);
|
||||
} else if (navigation_type == 'mail') {
|
||||
print(returnMessage);
|
||||
_openEmail(returnMessage);
|
||||
}
|
||||
} else {
|
||||
formattedMessage = returnMessage;
|
||||
if (returnMessage.contains('%')) {
|
||||
try {
|
||||
List<String> messageParts = returnMessage
|
||||
.split('%')
|
||||
.map((part) => part.trim())
|
||||
.cast<String>()
|
||||
.toList();
|
||||
formattedMessage = messageParts
|
||||
.asMap()
|
||||
.map(
|
||||
(index, part) => MapEntry(index, '${index + 1}. $part'))
|
||||
.values
|
||||
.join('\n');
|
||||
} catch (e) {
|
||||
print('Error splitting returnMessage: $e');
|
||||
formattedMessage =
|
||||
returnMessage; // Fallback to original message
|
||||
}
|
||||
} else {
|
||||
formattedMessage = returnMessage;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
print('returnMessage is null');
|
||||
@ -193,6 +291,30 @@ class _chatbotState extends State<chatbot> {
|
||||
}
|
||||
}
|
||||
|
||||
void _openDialPad(String phoneNumber) async {
|
||||
final url = 'tel:$phoneNumber';
|
||||
if (await canLaunch(url)) {
|
||||
await launch(url);
|
||||
} else {
|
||||
throw 'Could not open dial pad for $phoneNumber';
|
||||
}
|
||||
}
|
||||
|
||||
void _openEmail(String email) async {
|
||||
final Uri params = Uri(
|
||||
scheme: 'mailto',
|
||||
path: email,
|
||||
query:
|
||||
'subject=Your Subject&body=Hello', // Add default subject and body here
|
||||
);
|
||||
var url = params.toString();
|
||||
if (await canLaunch(url)) {
|
||||
await launch(url);
|
||||
} else {
|
||||
throw 'Could not open email client for $email';
|
||||
}
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return Scaffold(
|
||||
|
||||
@ -126,34 +126,51 @@ class ApiService {
|
||||
Navigator.pushNamed(context, 'login');
|
||||
}
|
||||
|
||||
Future<Map<String, dynamic>> getBotDetails(String requestFor, is_option,
|
||||
option, returnMessage, mobileNo, policyID) async {
|
||||
print('requestFor: $requestFor');
|
||||
print('is_option: $is_option');
|
||||
print('option: $option');
|
||||
print('returnMessage: $returnMessage');
|
||||
print('mobileNo: $mobileNo');
|
||||
print('policyID: $policyID');
|
||||
Future<Map<String, dynamic>> getBotDetails(
|
||||
Map<String, dynamic> formData) async {
|
||||
if (_token == null) {
|
||||
await _initializeToken();
|
||||
}
|
||||
final url;
|
||||
if (is_option != '0') {
|
||||
url = Uri.parse(
|
||||
'${Environment.apiUrl}getChatResponse?request_for=$requestFor&is_option=$is_option&option=$option&mobile_no=$mobileNo&policy_id=$policyID');
|
||||
} else {
|
||||
url = Uri.parse(
|
||||
'${Environment.apiUrl}getChatResponse?request_for=$requestFor&is_option=$is_option&text=$returnMessage&value=$option&mobile_no=$mobileNo&policy_id=$policyID');
|
||||
}
|
||||
final url = Uri.parse('${Environment.apiUrl}getChatResponse');
|
||||
// Convert formData to Map<String, String>
|
||||
Map<String, String> stringFormData =
|
||||
formData.map((key, value) => MapEntry(key, value.toString()));
|
||||
print(url);
|
||||
|
||||
final headers = {
|
||||
final response = await _makePostRequest(url, stringFormData, {
|
||||
'Content-Type': 'application/x-www-form-urlencoded',
|
||||
'Authorization': 'Bearer $_token' ?? '',
|
||||
};
|
||||
final response = await _makeGetRequest(url, headers);
|
||||
});
|
||||
return response;
|
||||
}
|
||||
|
||||
// Future<Map<String, dynamic>> getBotDetails(String requestFor, is_option,
|
||||
// option, returnMessage, mobileNo, policyID) async {
|
||||
// print('requestFor: $requestFor');
|
||||
// print('is_option: $is_option');
|
||||
// print('option: $option');
|
||||
// print('returnMessage: $returnMessage');
|
||||
// print('mobileNo: $mobileNo');
|
||||
// print('policyID: $policyID');
|
||||
// if (_token == null) {
|
||||
// await _initializeToken();
|
||||
// }
|
||||
// final url;
|
||||
// if (is_option != '0') {
|
||||
// url = Uri.parse(
|
||||
// '${Environment.apiUrl}getChatResponse?request_for=$requestFor&is_option=$is_option&option=$option&mobile_no=$mobileNo&policy_id=$policyID');
|
||||
// } else {
|
||||
// url = Uri.parse(
|
||||
// '${Environment.apiUrl}getChatResponse?request_for=$requestFor&is_option=$is_option&text=$returnMessage&value=$option&mobile_no=$mobileNo&policy_id=$policyID');
|
||||
// }
|
||||
// print(url);
|
||||
//
|
||||
// final headers = {
|
||||
// 'Authorization': 'Bearer $_token' ?? '',
|
||||
// };
|
||||
// final response = await _makeGetRequest(url, headers);
|
||||
// return response;
|
||||
// }
|
||||
|
||||
Future<Map<String, dynamic>> _makeGetRequest(
|
||||
Uri url, Map<String, String> headers) async {
|
||||
final response = await http.get(url, headers: headers);
|
||||
|
||||
Loading…
Reference in New Issue
Block a user