Last active
February 18, 2025 11:20
-
-
Save ehzawad/405b597147039bbf19062179125aeb96 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
nlu.yml: | |
- intent: new_card_activation | |
examples: | | |
- কার্ড অ্যাক্টিভেট করতে চাই | |
- নতুন কার্ড অ্যাক্টিভেট করব | |
- আমার কার্ডটি সক্রিয় করতে চাই | |
- কার্ড এক্টিভেশন করতে চাই | |
- নতুন কার্ড সক্রিয় করতে হবে | |
- কার্ড অ্যাক্টিভেশন প্রসেস শুরু করুন | |
- কিভাবে কার্ড অ্যাক্টিভেট করব | |
- আমার নতুন কার্ড এখনো অ্যাক্টিভ নয় | |
- কার্ড অ্যাক্টিভেশন প্রয়োজন | |
- নতুন কার্ডের জন্য অ্যাক্টিভেশন | |
rules.yml: | |
# new card activation steps | |
- rule: Activate form for new card activation | |
steps: | |
- intent: new_card_activation | |
- action: action_ask_new_card_activation | |
- action: new_card_activation_form | |
- active_loop: new_card_activation_form | |
- rule: Submit form for new card activation | |
condition: | |
- active_loop: new_card_activation_form | |
steps: | |
- action: new_card_activation_form | |
- active_loop: null | |
- action: action_new_card_activation_response | |
- action: reset_new_card_activation_slots | |
domain.yml: | |
intents: | |
# New Card Activation Steps | |
- new_card_activation | |
forms: | |
# new card activation steps | |
new_card_activation_form: | |
required_slots: | |
- card_last_four | |
- new_card_expiry_date | |
- new_card_pin | |
- new_card_pin_confirm | |
- otp | |
slots: | |
# new card activation steps | |
card_last_four: | |
type: text | |
influence_conversation: false | |
mappings: | |
- type: from_text | |
conditions: | |
- active_loop: new_card_activation_form | |
requested_slot: card_last_four | |
new_card_expiry_date: | |
type: text | |
influence_conversation: false | |
mappings: | |
- type: from_text | |
conditions: | |
- active_loop: new_card_activation_form | |
requested_slot: new_card_expiry_date | |
new_card_pin: | |
type: text | |
influence_conversation: false | |
mappings: | |
- type: from_text | |
conditions: | |
- active_loop: new_card_activation_form | |
requested_slot: new_card_pin | |
new_card_pin_confirm: | |
type: text | |
influence_conversation: false | |
mappings: | |
- type: from_text | |
conditions: | |
- active_loop: new_card_activation_form | |
requested_slot: new_card_pin_confirm | |
otp: | |
type: text | |
influence_conversation: false | |
mappings: | |
- type: from_text | |
conditions: | |
- active_loop: new_card_activation_form | |
requested_slot: otp | |
actions: | |
# new card activation steps | |
- action_ask_new_card_activation | |
- reset_new_card_activation_slots | |
- validate_new_card_activation_form | |
- action_new_card_activation_response | |
action.py: | |
# new card activation steps | |
# Action to prompt for new card activation – Step 1: Request card's last four digits. | |
class ActionAskNewCardActivation(Action): | |
def name(self) -> Text: | |
return "action_ask_new_card_activation" | |
def run(self, dispatcher: CollectingDispatcher, tracker: Tracker, domain: Dict[Text, Any]) -> List[Dict[Text, Any]]: | |
last_text = tracker.latest_message.get("text", "") | |
dispatcher.utter_message(text="আপনার নতুন কার্ড সক্রিয় করতে, আপনার কার্ডের লাস্ট ফোর ডিজিট বলুন") | |
return [] | |
# Reset action to clear all new card activation slots. | |
class ResetNewCardActivationSlots(Action): | |
def name(self) -> Text: | |
return "reset_new_card_activation_slots" | |
def run(self, dispatcher: CollectingDispatcher, tracker: Tracker, domain: Dict[Text, Any]) -> List[Dict[Text, Any]]: | |
return [ | |
SlotSet("card_last_four", None), | |
SlotSet("new_card_expiry_date", None), | |
SlotSet("new_card_pin", None), | |
SlotSet("new_card_pin_confirm", None), | |
SlotSet("otp", None), | |
SlotSet("process_continue_status", None), | |
SlotSet("process_state", None), | |
SlotSet("process_interruption", 0), | |
] | |
# Form validation for the new card activation form. | |
class ValidateNewCardActivationForm(FormValidationAction): | |
def name(self) -> Text: | |
return "validate_new_card_activation_form" | |
def validate_card_last_four(self, slot_value: Any, dispatcher: CollectingDispatcher, | |
tracker: Tracker, domain: Dict[Text, Any]) -> Dict[Text, Any]: | |
last_intent = tracker.latest_message.get("intent", {}).get("name") | |
last_text = tracker.latest_message.get("text", "") | |
process_interruption = tracker.get_slot("process_interruption") or 0 | |
process_interruption += 1 | |
if last_intent == "negate": | |
dispatcher.utter_message(response="utter_asking_for_next_service") | |
return {"card_last_four": None, "requested_slot": None, "process_interruption": 0} | |
filtered = hp_obj.get_numerical_value(last_text, limit=4) | |
if filtered and len(filtered[0]) == 4 and filtered[0].isnumeric(): | |
bn_card = numberTranslate(filtered[0]).strip(",") | |
dispatcher.utter_message(text=f"আপনি বলেছেন, {bn_card}. যদি ঠিক থাকে বলুন 'হ্যা ঠিক আছে'.") | |
return {"card_last_four": filtered[0], "requested_slot": "new_card_expiry_date", "process_interruption": 0} | |
else: | |
if process_interruption > cfg.PREPETED_TIME: | |
dispatcher.utter_message(text=response_db["agent_transfer"]["text"]) | |
return {"card_last_four": None, "requested_slot": None, "process_interruption": process_interruption} | |
else: | |
dispatcher.utter_message(text="দয়া করে আপনার কার্ডের লাস্ট ফোর ডিজিট দিন।") | |
return {"card_last_four": None, "requested_slot": "card_last_four", "process_interruption": process_interruption} | |
def validate_new_card_expiry_date(self, slot_value: Any, dispatcher: CollectingDispatcher, | |
tracker: Tracker, domain: Dict[Text, Any]) -> Dict[Text, Any]: | |
last_intent = tracker.latest_message.get("intent", {}).get("name") | |
last_text = tracker.latest_message.get("text", "") | |
process_interruption = tracker.get_slot("process_interruption") or 0 | |
process_interruption += 1 | |
if last_intent == "negate": | |
dispatcher.utter_message(response="utter_asking_for_next_service") | |
return {"new_card_expiry_date": None, "requested_slot": None, "process_interruption": 0} | |
filtered = hp_obj.get_numerical_value(last_text, limit=4) | |
if filtered and len(filtered[0]) == 4 and filtered[0].isnumeric(): | |
month = int(filtered[0][:2]) | |
if 1 <= month <= 12: | |
dispatcher.utter_message(text="আপনার এক্সপায়ারি ডেট সঠিক হয়েছে।") | |
return {"new_card_expiry_date": filtered[0], "requested_slot": "new_card_pin", "process_interruption": 0} | |
else: | |
dispatcher.utter_message(text="দয়া করে সঠিক MMYY ফরম্যাটে এক্সপায়ারি ডেট দিন।") | |
return {"new_card_expiry_date": None, "requested_slot": "new_card_expiry_date", "process_interruption": process_interruption} | |
else: | |
if process_interruption > cfg.PREPETED_TIME: | |
dispatcher.utter_message(text=response_db["agent_transfer"]["text"]) | |
return {"new_card_expiry_date": None, "requested_slot": None, "process_interruption": process_interruption} | |
else: | |
dispatcher.utter_message(text="দয়া করে সঠিক 4 ডিজিটের এক্সপায়ারি ডেট (MMYY) দিন।") | |
return {"new_card_expiry_date": None, "requested_slot": "new_card_expiry_date", "process_interruption": process_interruption} | |
def validate_new_card_pin(self, slot_value: Any, dispatcher: CollectingDispatcher, | |
tracker: Tracker, domain: Dict[Text, Any]) -> Dict[Text, Any]: | |
last_intent = tracker.latest_message.get("intent", {}).get("name") | |
last_text = tracker.latest_message.get("text", "") | |
process_interruption = tracker.get_slot("process_interruption") or 0 | |
process_interruption += 1 | |
if last_intent == "negate": | |
dispatcher.utter_message(response="utter_asking_for_next_service") | |
return {"new_card_pin": None, "requested_slot": None, "process_interruption": 0} | |
filtered = hp_obj.get_numerical_value(last_text, limit=4) | |
if filtered and len(filtered[0]) == 4 and filtered[0].isnumeric(): | |
dispatcher.utter_message(text="আপনার নতুন পিন নম্বরটি পুনরায় দিন, যদি ঠিক থাকে বলুন 'হ্যা ঠিক আছে'।") | |
return {"new_card_pin": filtered[0], "requested_slot": "new_card_pin_confirm", "process_interruption": 0} | |
else: | |
if process_interruption > cfg.PREPETED_TIME: | |
dispatcher.utter_message(text=response_db["agent_transfer"]["text"]) | |
return {"new_card_pin": None, "requested_slot": None, "process_interruption": process_interruption} | |
else: | |
dispatcher.utter_message(text="দয়া করে 4 ডিজিটের নতুন পিন নম্বর দিন।") | |
return {"new_card_pin": None, "requested_slot": "new_card_pin", "process_interruption": process_interruption} | |
def validate_new_card_pin_confirm(self, slot_value: Any, dispatcher: CollectingDispatcher, | |
tracker: Tracker, domain: Dict[Text, Any]) -> Dict[Text, Any]: | |
last_intent = tracker.latest_message.get("intent", {}).get("name") | |
last_text = tracker.latest_message.get("text", "") | |
process_interruption = tracker.get_slot("process_interruption") or 0 | |
process_interruption += 1 | |
new_card_pin = tracker.get_slot("new_card_pin") | |
if last_intent == "negate": | |
dispatcher.utter_message(response="utter_asking_for_next_service") | |
return {"new_card_pin_confirm": None, "requested_slot": None, "process_interruption": 0} | |
filtered = hp_obj.get_numerical_value(last_text, limit=4) | |
if filtered and len(filtered[0]) == 4 and filtered[0].isnumeric(): | |
if new_card_pin and new_card_pin == filtered[0]: | |
dispatcher.utter_message(text="নতুন পিন নম্বর মিলছে। এখন ওটিপি দিন।") | |
return {"new_card_pin_confirm": filtered[0], "requested_slot": "otp", "process_interruption": 0} | |
else: | |
dispatcher.utter_message(text="পিন নম্বর মিলছে না, অনুগ্রহ করে আবার নতুন পিন নম্বর দিন।") | |
return {"new_card_pin_confirm": None, "requested_slot": "new_card_pin_confirm", "process_interruption": process_interruption} | |
else: | |
if process_interruption > cfg.PREPETED_TIME: | |
dispatcher.utter_message(text=response_db["agent_transfer"]["text"]) | |
return {"new_card_pin_confirm": None, "requested_slot": None, "process_interruption": process_interruption} | |
else: | |
dispatcher.utter_message(text="দয়া করে 4 ডিজিটের পিন নম্বর দিন।") | |
return {"new_card_pin_confirm": None, "requested_slot": "new_card_pin_confirm", "process_interruption": process_interruption} | |
def validate_otp(self, slot_value: Any, dispatcher: CollectingDispatcher, | |
tracker: Tracker, domain: Dict[Text, Any]) -> Dict[Text, Any]: | |
last_intent = tracker.latest_message.get("intent", {}).get("name") | |
last_text = tracker.latest_message.get("text", "") | |
process_interruption = tracker.get_slot("process_interruption") or 0 | |
process_interruption += 1 | |
if last_intent == "negate": | |
dispatcher.utter_message(response="utter_asking_for_next_service") | |
return {"otp": None, "requested_slot": None, "process_interruption": 0} | |
filtered = hp_obj.get_numerical_value(last_text, limit=6) | |
if filtered and len(filtered[0]) == 6 and filtered[0].isnumeric(): | |
dispatcher.utter_message(text="ওটিপি সঠিক হয়েছে। আপনার কার্ডটি সফলভাবে সক্রিয় হয়েছে।") | |
return {"otp": filtered[0], "process_continue_status": True, "process_state": "complete", "process_interruption": 0} | |
else: | |
if process_interruption > cfg.PREPETED_TIME: | |
dispatcher.utter_message(text=response_db["agent_transfer"]["text"]) | |
return {"otp": None, "requested_slot": None, "process_interruption": process_interruption} | |
else: | |
dispatcher.utter_message(text="দয়া করে 6 ডিজিটের ওটিপি দিন।") | |
return {"otp": None, "requested_slot": "otp", "process_interruption": process_interruption} | |
# Final response action to complete the activation process. | |
class ActionNewCardActivationResponse(Action): | |
def name(self) -> Text: | |
return "action_new_card_activation_response" | |
async def run(self, dispatcher: CollectingDispatcher, tracker: Tracker, | |
domain: Dict[Text, Any]) -> List[Dict]: | |
card_last_four = tracker.get_slot("card_last_four") | |
new_card_expiry_date = tracker.get_slot("new_card_expiry_date") | |
new_card_pin = tracker.get_slot("new_card_pin") | |
otp_number = tracker.get_slot("otp") | |
sender_id = tracker.current_state()['sender_id'] | |
save_log_information("info", f"New Card Activation: card_last_four = {card_last_four}") | |
global NEW_CARD_EXPIRY_DATE | |
if NEW_CARD_EXPIRY_DATE is None: | |
NEW_CARD_EXPIRY_DATE = new_card_expiry_date | |
print("==========================================") | |
print(f"Expiry Date: {NEW_CARD_EXPIRY_DATE}") | |
callid, cli = hp_obj.get_cli_and_callid(sender_id) | |
if cfg.DEBUG_API_INTEGRATION: | |
print("Calling new_card_activation_api") | |
response = bapi.new_card_activation_api( | |
cli=cli, | |
callid=callid, | |
card_last_four=str(card_last_four), | |
new_pin_number=str(new_card_pin), | |
new_card_expiry_date=str(NEW_CARD_EXPIRY_DATE), | |
otp=str(otp_number) | |
) | |
if response["status_code"] == 200: | |
dispatcher.utter_message(text="আপনার কার্ডটি সফলভাবে সক্রিয় হয়েছে। অনুগ্রহ করে আপনার নতুন পিনটি নিরাপদে রাখুন।") | |
elif response["status_code"] == 408: | |
dispatcher.utter_message(text=response_db["api_error_message"]["text"]) | |
else: | |
dispatcher.utter_message(text="দুঃখিত, আপনার কার্ড সক্রিয় করার অনুরোধটি সফল হয়নি। অনুগ্রহ করে পুনরায় চেষ্টা করুন।") | |
else: | |
dispatcher.utter_message(text="আপনার কার্ডটি সফলভাবে সক্রিয় হয়েছে।") | |
NEW_CARD_EXPIRY_DATE = None | |
otp.remove_cli(cli) | |
return [ | |
SlotSet("card_last_four", None), | |
SlotSet("new_card_expiry_date", None), | |
SlotSet("new_card_pin", None), | |
SlotSet("new_card_pin_confirm", None), | |
SlotSet("otp", None), | |
SlotSet("process_continue_status", None), | |
SlotSet("process_state", None), | |
SlotSet("process_interruption", 0), | |
] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment