Hi, I’m trying to build a price negotiator bot using rasa.
I want to ask the user whether he is ok with the deal every time the bot presents him with a new offer. For this, I’m building a custom action that gets triggered on form submit.
def run(self,dispatcher,tracker: Tracker,domain: "DomainDict",) -> List[Dict[Text, Any]]:
dispatcher.utter_message(text = "Ok! Let me see what I can do!")
i = 0
product_price = 500
platform_bargain_percentage = 10
vendor_bargain_percentage = 10
min_bargain = 2
max_bargain = platform_bargain_percentage + vendor_bargain_percentage
offer_price = int(tracker.get_slot("price"))
quantity = int(tracker.get_slot("quantity"))
user_asked_percentage = (offer_price / product_price) * 100
current_bargain = [*range(min_bargain,max_bargain)][0]
deal = False
while user_asked_percentage > current_bargain and deal != True and i<= len([*range(min_bargain,max_bargain)]):
buttons = [
{"payload":'/inform_intent{"deal":True}',"title":"Yup!"},
{"payload":'/inform_intent{"deal":False}',"title":"Nope!"}
]
dispatcher.utter_message(text = "Okay so I just checked and sorry but we can't give away for that price!")
dispatcher.utter_message(text = f"How about {str(((current_bargain)/100) * product_price)}?")
dispatcher.utter_message(text = "Are you ok with this deal?",buttons = buttons)
deal = tracker.get_slot("deal")
i = i + 1
current_bargain = [*range(min_bargain,max_bargain)][i]
Here I intend to set the slot “deal” to True or False when the user clicks the button. So basically I want to modify this part to set directly into a slot instead of setting into an entity:
buttons = [ {“payload”:‘/inform_intent{“deal”:True}’,“title”:“Yup!”}, {“payload”:‘/inform_intent{“deal”:False}’,“title”:“Nope!”} ]
If there is no way to set a slot directly, how can I set the entity value into a slot in rules.yml?
Here is my current rules.yml:
- rule: start bargaining
steps:
- intent: user_negotiation_initiate
- action: utter_start_negotiation
- action: user_offer_form
- active_loop: user_offer_form
- rule: submit form
condition:
- active_loop: user_offer_form
steps:
- action: user_offer_form
- active_loop: null
- slot_was_set:
- requested_slot: null
- action: action_get_offer
And this is my current form definition in domain.yml:
forms:
user_offer_form:
quantity:
- type: from_text
price:
- type: from_text
Any help would be appreciated!! Thanks!