Slot values not submitting to database

So i’m developing a bot with rasa 2.0 using slots and forms. When i run the bot everything runs well, all the form fields work but the data is not saved to a database on submit. The bot does tell me the data that ive put in the form but the function does not submit the data to database. What could be the problem?

class ActionFormInfo(FormAction):
    def name(self) -> Text:
        """Unique identifier of the form"""
        return "request_names"
    def required_slots(tracker: Tracker) -> List[Text]:
        """A list of required slots that the form has to fill"""
        return ["first_name", "your_email","recipient","message"]
    def submit(
            dispatcher: CollectingDispatcher,
            tracker: Tracker,
            domain: Dict[Text, Any],
    ) -> List[Dict]:
        """Define what the form has to do
            after all required slots are filled"""
        # utter submit template
        dispatcher.utter_message(template="utter_submit", first_name=tracker.get_slot('first_name'),
        mail ='http://localhost:8000/api',{'first_name':first_name,'your_email':your_email,'recipient_mail':recipient,'message':message}).json()
        print(""" You submited the information {} {} {} {}""")
        return []
    def slot_mappings(self) -> Dict[Text, Union[Dict, List[Dict]]]:
        """A dictionary to map required slots to
            - an extracted entity
            - intent: value pairs
            - a whole message
            or a list of them, where a first match will be picked"""
        return {
            "first_name": self.from_entity(entity="first_name", intent='my_name_is'),
            "your_email": self.from_entity(entity="your_email", intent="email"),
            "recipient": self.from_entity(entity="recipient", intent="recipient_mail"),
            "message": self.from_entity(entity="message", intent="message"),

you should use a custom action to deal with action submitting, rasa not know submit function. Just learn from the tutorial:

And I have not see you write anything to operate database.

1 Like

Im posting to a django api via http request

ok. So your submit function is not called, right? Just try to use a rule to trigger submit action. I see somebody see submit function is ok, but I never use it. My method is use the rule.

  - rule: submit form
        - active_loop: invite_form
      - action: invite_form
      - active_loop: null
      - slot_was_set:
          - requested_slot: null
      - action: action_submit_form

So when invite_form is finished, action_submit_form will triggered, I write my code in the method run:

class ActionSubmitForm(Action):

    def name(self) -> Text:
        return "action_submit_form"

    def run(self, dispatcher: CollectingDispatcher,
            tracker: Tracker,
            domain: Dict[Text, Any]) -> List[Dict[Text, Any]]:
        # save you slot to database here
        return []
1 Like