Setting slot value

Hi All,

Hope all of you are good. Currently i am stucked at a points where i am able to extract number from text i want to save this value in Transaction_ID . Could you please help how to set this value. I am using FreeTextFormField () to get this value.

class ActionAskPoints(FormAction): RANDOMIZE = False @staticmethod def required_fields(): return [ FreeTextFormField(“Transaction_ID”)

    ]
def name(self):
    return 'action_points'
def submit(self, dispatcher, tracker, domain):
    Transaction_ID = tracker.get_slot("Transaction_ID")
    Coustomer_ID = tracker.sender_id
    timestamp = tracker.latest_message.timestamp
    response = """Your points on transaction id  :{} is $ 10 . Enjoy !!""".format(Transaction_ID)
    dispatcher.utter_message(response)

For setting the Slot values in rasa, you can use the SlotSet event of rasa_core

class rasa_core.events.SlotSet(key, value=None, timestamp=None)

How are you stuck exactly? I think you probably want to be using the EntityFormField() to extract an entity

Yaa I used and while interacting, training it is asking for Transaction_ID and when i am giving as a number it is taking as a new entity it is not taking that number as Transaction_ID slot.

I have given two numbers in mine intents but it is taking only one in slots. How to handle numbers. I am attaching interactive training data below :-

I am not collected 16548245 the points. Transaction ID : 43116 intent: Add_Transaction 0.97

slot{“number”: 43116.0}

Current slots: Customer_ID: None, Date: None, Transaction_ID: None, number: 43116.0

Hi All,

Any one have solution on above please let me know i am stucked at this point

both are getting extracted as numbers because I assume you’re using duckling, and then by default only the last number gets stored. If you want to store one of them in the TransactionID slot, then you need to do this in a custom action with a SlotSet() event

Is there any way to store infinite values in slots rather than giving finite set of values?

what do you mean?

Hi @akelad thanks for suggestion i created custom action but getting below error. Please let me know any changes required

action.py :

class GetTransactionID(Action): def name(self): return “action_transaction_id” def run(self, dispatcher, tracker, domain): Transaction_ID = tracker.get_slot(“number”) if Transaction_ID: return [SlotSet(“Transaction_ID” , Transaction_ID)]

Interactive learning:

Chat History

Bot You

1 action_listen

2 Please check the transaction ID 71168 . Still points not received intent: Add_Transaction 0.97 ─

3 slot{“number”: 71168.0}

Current slots: # Bot You

1 action_listen

2 Please check the transaction ID 71168 . Still points not received intent: Add_Transaction 0.97

3 slot{“number”: 71168.0}

Current slots: Customer_ID: None, Date: None, Transaction_ID: None, number: 71168.0

Error: ERROR:rasa_core.actions.action:Failed to run custom action ‘action_transaction_id’. Action server responded with a non 200 status code of 500. Make sure your action server properly runs actions and returns a 200 once the action is executed. Error: 500 Server Error: INTERNAL SERVER ERROR for url: http://localhost:5055/webhook ERROR:rasa_core.processor:Encountered an exception while running action ‘action_transaction_id’. Bot will continue, but the actions events are lost. Make sure to fix the exception in your custom code. ERROR:rasa_core.processor:Failed to execute custom action.

If i have a slot called salary,

entities:

  • salary slots: salary: type: float

and this is the intent from where i have some examples that a user can reply

intent:changed_financials

and this is the story

  • changed_financials
    • action_change_financials
    • slot{“salary”: “15000”}
    • utter_financials

here if i give salary as 15000, its working fine. But its not working for other values. How to make it generic so that it can take any values.

It would be great if someone could share an example for storing any value in the slot. Thanks.

Hey Chandan C it will be better if you will use duckling. Duckling will extract the number and then save it in salary.

Hi Neeraj, can you give some reference or an example for the same.

Hii, can we have single value in multiple intents?

“Yes” is used in both the intents

intent:change_in_state

  • Yes
  • state has been changed
  • yes the state is changed

intent:change_in_country

  • Yes
  • country has been changed
  • yes the country is changed

I am not able to use “Yes” in both the intents, what should i do for this to work?

Hi Chandan you can use ducklin to extract the number . Create a custom action and save it. i used form field for number

EntityFormField(“number”, “salary”),

Thanks Neeraj, i have solved that issue, but im stuck in the intents issue. I have asked in the earlier message. Is there any solution for that?

I think you can do. there may be some other way One way to create a custom action and use button yes and no and in payload call the particular intent

buttons = [{ “title”: “Yes”, “payload”: “/greet” }, { “title”: “No”, “payload”: “/goodbye” }] dispatcher.utter_button_message(“Do you have any other query” ,buttons)

I have a constraint, i cannot use buttons. I should find some other way for the same.

You can create two intent affirm(yes) and deny(No) and then call utter according to that.