Can´t deactivate rasa form if user want to stop

Hi,

I have following situation. I have a bot which supports the user creating a ticket for the IT-support. I am using forms for that. First of all, the bot asks the user if they should make the ticket together. If yes, the bot asks for a summary and a description. After that he performs a API POST call to create an issue in jira. If no, the bot only should send a link where the user can find a guide for creating a jira issue.

My form is working fine in some parts. If the users agrees to fill out the form everything is okay, but If the user says no and he just wants the link I run in problems deactivating the form.

Here are some parts of my config:

Rasa Form

class CreateJiraIssue(FormAction):
"""Example of a custom form action"""

def name(self):
    """Unique identifier of the form"""
    return "create_jira_issue_form"

@staticmethod
def required_slots(tracker: "Tracker") -> List[Text]:
    return ["start_form", "sd_summary", "sd_description"]


def slot_mappings(self) -> Dict[Text, Union[Dict, List[Dict[Text, Any]]]]:
    return {
        "start_form":[
            self.from_intent(intent="affirm", value=True),
            self.from_intent(intent="deny", value=False)
        ],
        "sd_summary":self.from_text(),
        "sd_description":self.from_text()

    }

def validate_start_form(
    self,
    value: Text,
    dispatcher: CollectingDispatcher,
    tracker: Tracker,
    domain: Dict[Text, Any],
) -> Dict[Text, Any]:
    last_intent = tracker.latest_message['intent'].get('name')

    if last_intent == 'deny':
        confluence_link = 'mylink'

        element = {
            "template-type": "generic",
            "elements": [
                {
                    "flag": "l",
                    "before": "",
                    "middle": "",
                    "after": " findest du eine Anleitung, wie man eine Jira Service-Anfrage erstellt. "
                    ,
                    "links": [
                        {
                            "url": confluence_link,
                            "title": "Hier"
                        }

                    ]
                }
            ]
        }

        dispatcher.utter_custom_json(element)
        return self.deactivate()
    else:
        return {"start_form": "True"}



def submit(
        self,
        dispatcher: CollectingDispatcher,
        tracker: Tracker,
        domain: Dict[Text, Any],
) -> List[Dict]:
    print("all done")
    return [AllSlotsReset()]

Please ignore the custom JSON utterance. This is just my way to send a link to the user with some text.

Domain

actions:
#Utterances
  - utter_goodbye
  - utter_greet
  - utter_you_are_welcome

intents:
  - goodbye:
      triggers: utter_goodbye
      use_entities: []
  - greet:
      triggers: utter_greet
      use_entities: []
  - say_thank_you:
      triggers: utter_you_are_welcome
      use_entities: []
  - jira_ask_for_service_request_guide:
      use_entities: []
	  
slots:
  start_form:
    type: unfeaturized
    auto_fill: false
  sd_summary:
    type: unfeaturized
    auto_fill: false
  sd_description:
    type: unfeaturized
    auto_fill: false
  requested_slot:
    type: unfeaturized
	
responses:
  utter_goodbye:
	- text: Auf Wiedersehen
	- text: Einen schönen Tag noch
	- text: Bye Bye
  utter_greet:
	- text: Hallo, was kann ich für dich tun?
	- text: Guten Tag, wie kann ich dir weiterhelfen?
  utter_you_are_welcome:
	- text: Gern geschehen :)
  utter_ask_start_form:
	- text: Sollen wir gemeinsam eine Jira Serviceanfrage erstellen?
  utter_ask_sd_summary:
    - text: Wie lautet der Betreff für deine Service Anfrage?
  utter_ask_sd_description:
    - text: Bitte schreib jetzt eine aussagekräftige Zusammenfassung.
  utter_jira_sd_values:
    - text: "Ich habe jetzt alle benötigten Informationen. Hier eine kurze Zusammenfassung:\n
            Betreff: {sd_summary}\n
            Zusammenfassung: {sd_description}\n\n
            Kann ich die Service Anfrage nun abschicken?"

and finally my Stories

## greet + create_jira_issue_form
*greet
    - utter_greet
* jira_ask_for_service_request_guide
    - create_jira_issue_form
    - form{"name":"create_jira_issue_form"}
    - form{"name":null}
    - utter_jira_sd_values
* say_thank_you
    - utter_you_are_welcome
    
## create_jira_issue_form
* jira_ask_for_service_request_guide
    - create_jira_issue_form
    - form{"name":"create_jira_issue_form"}
    - form{"name":null}
    - utter_jira_sd_values
    
## greet + create_jira_issue_form + deny
* greet
    - utter_greet
* jira_ask_for_service_request_guide
    - create_jira_issue_form
    - form{"name": "create_jira_issue_form"}
    - slot{"requested_slot": "start_form"}
* deny
    - action_deactivate_form
    - form{"name": null}
    - slot{"requested_slot": null}
* say_thank_you
    - utter_you_are_welcome

The problem happens after the bot aks

“Sollen wir gemeinsam eine Jira Serviceanfrage erstellen?”

if the user says “nein” (no) the bot answers as below (i used rasa shell --debug)

Custom json:
{
  "template-type": "generic",
  "elements": [
    {
      "flag": "l",
      "before": "",
      "middle": "",
      "after": " findest du eine Anleitung, wie man eine Jira Service-Anfrage erstellt. ",
      "links": [
        {
          "url": "<mylink>",
          "title": "Hier"
        }
      ]
    }
  ]
}
Wie lautet der Betreff für deine Service Anfrage?
Your input ->

The bot should only answer the custom json. However he tries to get the summary from the user with the question “Wie lautet der Betreff für deine Service Anfrage?”

This question should only be raised of the user choosed “ja” (yes). For testing purpose I just answerd to this with “vielen dank” (thank you very much), as I expected the bot filled the sd_summary-slot with this value.

It seems the bot did not deactivate the form correctly. In normal situation he should answer “Gern geschehen” (you are welcome).

Can somebody tell my why my bot won´t deactivate the form? He sends the custom json, so he is able to extract the last user intent deny and normally return self.deactivate() should work.

Hi @lindig!

A few points that might help:

  • Returning self.deactivate() from within the validation function will not work. self.deactivate() returns a list of events while the validation function is supposed to return a dictionary with slot name as key and its value as value.

  • Your form is not deactivating because not all required slots are set at that time (sd_summary & sd_description).

Now, if you want to deactivate the form when the requested_slot is start_form and the intent is deny, I suggest you declare requested_slot as a categorical slot with the three required slots as its value and train again. You can read more about it in this part of the doc.

Hope that helps.

@saurabh-m523 thank you for your answer. I thought it is possible to deactivate a form within the validation function as here.

I will try your suggestion. Do I need a new function to check if requested_slot is set to start_form and last intent is deny, or do you think I can now deactivate a form in the validation function because I set the requested_slot to categorical? Thank you!

Yea so, earlier it was possible to deactivate the Form from within the validation function but things have changed since then. There is an open issue on github about this.

Now, you can make the requested_slot as categorical (don’t forget to give values to the categorical slot) and retrain. This should work. Also, you should not be returning self.deactivate from within the validation function. The reason this should work is due to this part of the story:

## greet + create_jira_issue_form + deny
* greet
    - utter_greet
* jira_ask_for_service_request_guide
    - create_jira_issue_form
    - form{"name": "create_jira_issue_form"}
    - slot{"requested_slot": "start_form"}
* deny
    - action_deactivate_form
    - form{"name": null}
    - slot{"requested_slot": null}
* say_thank_you
    - utter_you_are_welcome

Unfortunately this didn´t solved my problem. I searched in the rasa forum and found this thread. This and your suggestions to make a categorical slot solved my problem! :slight_smile:

1 Like