Spaces:
Runtime error
Runtime error
""" | |
Customer Service Expertise Enhancements for Omdurman National Bank Chatbot | |
This module contains additional customer service expertise elements that can be | |
integrated into the main chatbot implementation to provide a more personalized | |
and professional banking experience. | |
""" | |
# Enhanced customer service phrases with more banking-specific language | |
ENHANCED_CUSTOMER_SERVICE_PHRASES_AR = { | |
"greeting": [ | |
"مرحبًا بك في بنك أم درمان الوطني! كيف يمكنني مساعدتك اليوم؟", | |
"أهلاً بك في خدمة العملاء الافتراضية لبنك أم درمان الوطني. كيف يمكنني خدمتك؟", | |
"مرحبًا! أنا مساعدك المصرفي الشخصي من بنك أم درمان الوطني. كيف يمكنني مساعدتك؟", | |
"شكرًا لاختيارك بنك أم درمان الوطني. كيف يمكنني تلبية احتياجاتك المصرفية اليوم؟" | |
], | |
"thanks": [ | |
"شكرًا لتواصلك مع بنك أم درمان الوطني!", | |
"نشكرك على ثقتك في خدماتنا المصرفية.", | |
"سعداء بخدمتك دائمًا في بنك أم درمان الوطني!", | |
"نقدر اختيارك لبنك أم درمان الوطني لتلبية احتياجاتك المالية." | |
], | |
"follow_up": [ | |
"هل هناك خدمة مصرفية أخرى يمكنني مساعدتك بها اليوم؟", | |
"هل لديك أي استفسارات أخرى حول منتجاتنا أو خدماتنا المصرفية؟", | |
"هل تحتاج إلى مساعدة في أي معاملات مصرفية أخرى؟", | |
"هل يمكنني مساعدتك في أي شيء آخر لتحسين تجربتك المصرفية معنا؟" | |
], | |
"apology": [ | |
"أعتذر عن أي إزعاج قد سببناه لك.", | |
"نأسف على هذه التجربة، ونحن ملتزمون بتحسين خدماتنا.", | |
"أعتذر عن عدم تلبية توقعاتك. دعنا نعمل معًا لإيجاد حل.", | |
"نعتذر عن هذا الخطأ ونقدر صبرك." | |
], | |
"reassurance": [ | |
"يمكنك الاطمئنان بأن أموالك في أيدٍ أمينة مع بنك أم درمان الوطني.", | |
"أمن معلوماتك المالية هو أولويتنا القصوى.", | |
"نحن نلتزم بتقديم أفضل الحلول المالية لعملائنا الكرام.", | |
"ثقتك مهمة لنا، ونحن نعمل جاهدين للحفاظ عليها." | |
] | |
} | |
ENHANCED_CUSTOMER_SERVICE_PHRASES_EN = { | |
"greeting": [ | |
"Welcome to Omdurman National Bank! How may I assist you today?", | |
"Hello and welcome to ONB virtual customer service. How can I help you?", | |
"Greetings! I'm your personal banking assistant from Omdurman National Bank. How can I assist you?", | |
"Thank you for choosing Omdurman National Bank. How may I address your banking needs today?" | |
], | |
"thanks": [ | |
"Thank you for contacting Omdurman National Bank!", | |
"We appreciate your trust in our banking services.", | |
"Always a pleasure serving you at Omdurman National Bank!", | |
"We value your choice of Omdurman National Bank for your financial needs." | |
], | |
"follow_up": [ | |
"Is there any other banking service I can assist you with today?", | |
"Do you have any other questions about our products or banking services?", | |
"Do you need assistance with any other banking transactions?", | |
"Can I help you with anything else to enhance your banking experience with us?" | |
], | |
"apology": [ | |
"I apologize for any inconvenience this may have caused you.", | |
"We're sorry about this experience, and we're committed to improving our services.", | |
"I apologize that we didn't meet your expectations. Let's work together to find a solution.", | |
"We apologize for this error and appreciate your patience." | |
], | |
"reassurance": [ | |
"You can rest assured that your money is in safe hands with Omdurman National Bank.", | |
"The security of your financial information is our top priority.", | |
"We are committed to providing the best financial solutions for our valued customers.", | |
"Your trust is important to us, and we work hard to maintain it." | |
] | |
} | |
# Banking-specific FAQs | |
BANKING_FAQS_AR = [ | |
{ | |
"question": "ما هي متطلبات فتح حساب توفير؟", | |
"answer": "لفتح حساب توفير، تحتاج إلى هوية وطنية سارية المفعول أو جواز سفر، وإثبات عنوان (مثل فاتورة مرافق)، والحد الأدنى للإيداع هو 1000 جنيه سوداني." | |
}, | |
{ | |
"question": "كيف يمكنني تغيير رقم هاتفي المسجل لدى البنك؟", | |
"answer": "لتغيير رقم هاتفك المسجل، يرجى زيارة أقرب فرع مع إثبات هويتك، أو يمكنك تقديم طلب عبر الخدمات المصرفية عبر الإنترنت في قسم 'تحديث المعلومات الشخصية'." | |
}, | |
{ | |
"question": "ما هي رسوم التحويلات الدولية؟", | |
"answer": "تبدأ رسوم التحويلات الدولية من 25 جنيه سوداني وتختلف حسب البلد المستلم ومبلغ التحويل. للحصول على تفاصيل محددة، يرجى الاطلاع على جدول الرسوم على موقعنا الإلكتروني." | |
}, | |
{ | |
"question": "هل يمكنني الحصول على قرض إذا كنت متقاعدًا؟", | |
"answer": "نعم، يمكن للمتقاعدين التقدم بطلب للحصول على قروض خاصة مع شروط ميسرة. يجب أن يكون عمرك أقل من 70 عامًا وأن تتلقى معاشك التقاعدي من خلال حساب في بنكنا." | |
}, | |
{ | |
"question": "كم من الوقت يستغرق إصدار بطاقة ائتمان جديدة؟", | |
"answer": "عادة ما يستغرق إصدار بطاقة ائتمان جديدة من 7 إلى 10 أيام عمل من تاريخ الموافقة على الطلب. يمكنك متابعة حالة طلبك من خلال الخدمات المصرفية عبر الإنترنت." | |
} | |
] | |
BANKING_FAQS_EN = [ | |
{ | |
"question": "What are the requirements for opening a savings account?", | |
"answer": "To open a savings account, you need a valid national ID or passport, proof of address (such as a utility bill), and the minimum deposit is 1000 SDG." | |
}, | |
{ | |
"question": "How can I change my registered phone number with the bank?", | |
"answer": "To change your registered phone number, please visit your nearest branch with your ID proof, or you can submit a request through online banking in the 'Update Personal Information' section." | |
}, | |
{ | |
"question": "What are the fees for international transfers?", | |
"answer": "International transfer fees start from 25 SDG and vary depending on the receiving country and transfer amount. For specific details, please check the fee schedule on our website." | |
}, | |
{ | |
"question": "Can I get a loan if I am retired?", | |
"answer": "Yes, retirees can apply for special loans with favorable terms. You must be under 70 years of age and receive your pension through an account with our bank." | |
}, | |
{ | |
"question": "How long does it take to issue a new credit card?", | |
"answer": "Issuing a new credit card typically takes 7-10 business days from the date of application approval. You can track your application status through online banking." | |
} | |
] | |
# Customer satisfaction survey | |
SATISFACTION_SURVEY_AR = { | |
"title": "استطلاع رضا العملاء", | |
"intro": "نقدر ملاحظاتك! يرجى تقييم تجربتك مع مساعدنا المصرفي الافتراضي.", | |
"questions": [ | |
"كيف تقيم سهولة استخدام المساعد المصرفي الافتراضي؟", | |
"هل كانت المعلومات المقدمة مفيدة ودقيقة؟", | |
"هل تمت معالجة استفسارك بشكل فعال؟", | |
"ما مدى احتمالية استخدامك للمساعد المصرفي الافتراضي مرة أخرى؟", | |
"هل لديك أي اقتراحات لتحسين خدمتنا؟" | |
], | |
"ratings": ["ممتاز", "جيد جدًا", "جيد", "مقبول", "ضعيف"], | |
"submit": "إرسال التقييم", | |
"thanks": "شكرًا على ملاحظاتك القيمة!" | |
} | |
SATISFACTION_SURVEY_EN = { | |
"title": "Customer Satisfaction Survey", | |
"intro": "We value your feedback! Please rate your experience with our virtual banking assistant.", | |
"questions": [ | |
"How would you rate the ease of use of the virtual banking assistant?", | |
"Was the information provided helpful and accurate?", | |
"Was your inquiry handled effectively?", | |
"How likely are you to use the virtual banking assistant again?", | |
"Do you have any suggestions for improving our service?" | |
], | |
"ratings": ["Excellent", "Very Good", "Good", "Fair", "Poor"], | |
"submit": "Submit Rating", | |
"thanks": "Thank you for your valuable feedback!" | |
} | |
# Banking terminology glossary | |
BANKING_GLOSSARY_AR = { | |
"حساب جاري": "حساب مصرفي يسمح بالسحب والإيداع المتكرر، عادة بدون فائدة.", | |
"حساب توفير": "حساب مصرفي يدفع فائدة على الأموال المودعة ويشجع على الادخار.", | |
"بطاقة الخصم": "بطاقة تسمح بالدفع الإلكتروني مباشرة من الحساب الجاري.", | |
"بطاقة ائتمان": "بطاقة تسمح بالاقتراض ضمن حد ائتماني محدد مسبقًا.", | |
"معدل الفائدة": "النسبة المئوية للمبلغ الأصلي الذي يدفعه المقترض كرسوم للمقرض.", | |
"الرصيد المتاح": "المبلغ المتاح للسحب من الحساب.", | |
"كشف الحساب": "سجل للمعاملات المالية خلال فترة زمنية محددة.", | |
"الحوالة المصرفية": "تحويل الأموال إلكترونيًا من حساب إلى آخر.", | |
"الرهن العقاري": "قرض لشراء عقار، حيث يكون العقار نفسه ضمانًا للقرض.", | |
"الوديعة لأجل": "إيداع مالي في البنك لفترة زمنية محددة بسعر فائدة ثابت." | |
} | |
BANKING_GLOSSARY_EN = { | |
"Current Account": "A bank account that allows frequent withdrawals and deposits, usually without interest.", | |
"Savings Account": "A bank account that pays interest on deposits and encourages saving.", | |
"Debit Card": "A card that allows electronic payment directly from a current account.", | |
"Credit Card": "A card that allows borrowing within a pre-approved credit limit.", | |
"Interest Rate": "The percentage of the principal amount that a borrower pays as a fee to the lender.", | |
"Available Balance": "The amount available for withdrawal from an account.", | |
"Bank Statement": "A record of financial transactions over a specified period.", | |
"Wire Transfer": "Electronic transfer of funds from one account to another.", | |
"Mortgage": "A loan to purchase real estate, where the property itself serves as collateral.", | |
"Fixed Deposit": "A financial deposit in a bank for a specified time period at a fixed interest rate." | |
} | |
# Function to get enhanced customer service response | |
def get_enhanced_response(intent, language, user_name=None): | |
""" | |
Generate an enhanced customer service response based on intent and language. | |
Args: | |
intent (str): The identified user intent | |
language (str): The language code ('ar' or 'en') | |
user_name (str, optional): The user's name for personalization | |
Returns: | |
str: An enhanced response with appropriate customer service elements | |
""" | |
import random | |
# Select the appropriate phrases based on language | |
phrases = ENHANCED_CUSTOMER_SERVICE_PHRASES_AR if language == "ar" else ENHANCED_CUSTOMER_SERVICE_PHRASES_EN | |
# Get the base response content | |
if language == "ar": | |
base_content = ONB_GUIDELINES_AR.get(intent, "") | |
else: | |
base_content = ONB_GUIDELINES_EN.get(intent, "") | |
# Add personalization if user name is provided | |
greeting = random.choice(phrases["greeting"]) | |
if user_name: | |
if language == "ar": | |
greeting = greeting.replace("مرحبًا", f"مرحبًا {user_name}") | |
else: | |
greeting = greeting.replace("Welcome", f"Welcome {user_name}") | |
# Add reassurance for financial security related intents | |
reassurance = "" | |
if intent in ["balance", "transfer", "loan", "new_account"]: | |
reassurance = f"<br><br>{random.choice(phrases['reassurance'])}" | |
# Add follow-up | |
follow_up = random.choice(phrases["follow_up"]) | |
# Combine all elements | |
enhanced_response = f"{greeting}<br><br>{base_content}{reassurance}<br><br>{follow_up}" | |
return enhanced_response | |
# Function to handle common banking FAQs | |
def handle_banking_faq(question, language): | |
""" | |
Check if the user's question matches any common banking FAQs and return the answer. | |
Args: | |
question (str): The user's question | |
language (str): The language code ('ar' or 'en') | |
Returns: | |
str or None: The FAQ answer if found, None otherwise | |
""" | |
# Select the appropriate FAQs based on language | |
faqs = BANKING_FAQS_AR if language == "ar" else BANKING_FAQS_EN | |
# Convert question to lowercase for case-insensitive matching | |
question_lower = question.lower() | |
# Check each FAQ for a match | |
for faq in faqs: | |
faq_question_lower = faq["question"].lower() | |
# Check if the user's question contains the FAQ question keywords | |
keywords = faq_question_lower.split() | |
match_count = sum(1 for keyword in keywords if keyword in question_lower) | |
# If more than 50% of keywords match, consider it a match | |
if match_count >= len(keywords) * 0.5: | |
return faq["answer"] | |
return None | |
# Function to offer satisfaction survey | |
def offer_satisfaction_survey(language): | |
""" | |
Generate HTML for a customer satisfaction survey. | |
Args: | |
language (str): The language code ('ar' or 'en') | |
Returns: | |
str: HTML for the satisfaction survey | |
""" | |
# Select the appropriate survey based on language | |
survey = SATISFACTION_SURVEY_AR if language == "ar" else SATISFACTION_SURVEY_EN | |
# Generate HTML for the survey | |
html = f""" | |
<div class="satisfaction-survey" dir="{('rtl' if language == 'ar' else 'ltr')}"> | |
<h3>{survey['title']}</h3> | |
<p>{survey['intro']}</p> | |
<form id="satisfaction-form"> | |
""" | |
# Add questions | |
for i, question in enumerate(survey['questions']): | |
html += f""" | |
<div class="survey-question"> | |
<p>{question}</p> | |
<div class="rating-options"> | |
""" | |
# Add rating options | |
for rating in survey['ratings']: | |
html += f""" | |
<label> | |
<input type="radio" name="q{i+1}" value="{rating}"> | |
{rating} | |
</label> | |
""" | |
html += """ | |
</div> | |
</div> | |
""" | |
# Add text area for suggestions | |
html += f""" | |
<div class="survey-question"> | |
<p>{survey['questions'][-1]}</p> | |
<textarea name="suggestions" rows="3" cols="40"></textarea> | |
</div> | |
""" | |
# Add submit button | |
html += f""" | |
<button type="button" onclick="submitSurvey()" class="survey-submit">{survey['submit']}</button> | |
</form> | |
</div> | |
<script> | |
function submitSurvey() {{ | |
alert('{survey['thanks']}'); | |
document.getElementById('satisfaction-form').style.display = 'none'; | |
}} | |
</script> | |
""" | |
return html | |
# Function to provide banking term definition | |
def get_banking_term_definition(term, language): | |
""" | |
Get the definition of a banking term from the glossary. | |
Args: | |
term (str): The banking term to look up | |
language (str): The language code ('ar' or 'en') | |
Returns: | |
str or None: The definition if found, None otherwise | |
""" | |
# Select the appropriate glossary based on language | |
glossary = BANKING_GLOSSARY_AR if language == "ar" else BANKING_GLOSSARY_EN | |
# Convert term to lowercase for case-insensitive matching | |
term_lower = term.lower() | |
# Check each term in the glossary | |
for glossary_term, definition in glossary.items(): | |
if glossary_term.lower() in term_lower or term_lower in glossary_term.lower(): | |
return definition | |
return None | |