Example #1
0
    def run(self, dispatcher: CollectingDispatcher, tracker: Tracker,
            domain: Dict[Text, Any]) -> List['Event']:

        intent_ranking = tracker.latest_message.get('intent_ranking', [])
        if len(intent_ranking) > 1:
            diff_intent_confidence = (intent_ranking[0].get("confidence") -
                                      intent_ranking[1].get("confidence"))
            if diff_intent_confidence < 0.2:
                intent_ranking = intent_ranking[:2]
            else:
                intent_ranking = intent_ranking[:1]
        first_intent_names = [
            intent.get('name', '') for intent in intent_ranking
            if intent.get('name', '') != 'out_of_scope'
        ]

        message_title = "Sorry, I'm not sure I've understood " \
                        "you correctly 🤔 Do you mean..."

        mapped_intents = [(name, self.intent_mappings.get(name, name))
                          for name in first_intent_names]

        buttons = []
        for intent in mapped_intents:
            buttons.append({
                'title': intent[1],
                'payload': '/{}'.format(intent[0])
            })

        buttons.append({'title': 'Something else', 'payload': '/out_of_scope'})

        dispatcher.utter_button_message(message_title, buttons=buttons)

        return []
Example #2
0
    def run(self, dispatcher: CollectingDispatcher, tracker: Tracker,
            domain: Dict[Text, Any]) -> List['Event']:

        intent_ranking = tracker.latest_message.get('intent_ranking', [])
        first_intent_names = [
            intent.get('name', '') for intent in intent_ranking[:2] if
            intent.get('name', '') not in ['deny', 'affirm', 'out_of_scope']
        ]

        message_title = "Sorry, I'm not sure I've understood " \
                        "you correctly 🤔 Do you mean..."

        mapped_intents = [(name, self.intent_mappings.get(name, name))
                          for name in first_intent_names]

        buttons = []
        for intent in mapped_intents:
            buttons.append({
                'title': intent[1],
                'payload': '/{}'.format(intent[0])
            })

        buttons.append({'title': 'Something else', 'payload': '/deny'})

        dispatcher.utter_button_message(message_title, buttons=buttons)

        return []
Example #3
0
    def submit(self, dispatcher: CollectingDispatcher, tracker: Tracker,
               domain: Dict[Text, Any]) -> List[Dict]:
        """Define what the form has to do after all required slots are filled"""

        location = tracker.get_slot('location')
        speciality = tracker.get_slot('speciality')
        results = _find_providers(location, speciality)
        buttons = []
        for r in results:
            provider_id = r.get("provider_id")
            provider_name = r.get("provider_name")
            payload = "/inform{\"provider_id\":\"" + provider_id + "\"}"
            buttons.append({
                "title": "{}".format(provider_name.title()),
                "payload": payload
            })

        # limit number of buttons to 3 here for clear presentation purpose
        dispatcher.utter_button_message(
            "Here is a list of {} {} near you".format(len(buttons[:3]),
                                                      "providers"),
            buttons[:3],
            button_type="vertical")
        # todo: note: button options are not working BUG in rasa_core

        # utter submit template
        dispatcher.utter_template('utter_submit', tracker)
        return []
Example #4
0
    def run(self, dispatcher: CollectingDispatcher, tracker: Tracker,
            domain: Dict[Text, Any]) -> List:

        location = tracker.get_slot('location')
        facility_type = tracker.get_slot('facility_type')

        results = _find_facilities(location, facility_type)
        button_name = _resolve_name(FACILITY_TYPES, facility_type)
        if len(results) == 0:
            dispatcher.utter_message(
                "Sorry, we could not find a {} in {}.".format(
                    button_name, location))
            return []

        buttons = []
        print("found {} facilities".format(len(results)))
        for r in results:
            if facility_type == FACILITY_TYPES["hospital"]["resource"]:
                facility_id = r.get("provider_id")
                name = r["hospital_name"]
            elif facility_type == FACILITY_TYPES["nursing_home"]["resource"]:
                facility_id = r["federal_provider_number"]
                name = r["provider_name"]
            elif facility_type == FACILITY_TYPES["doctor"]["resource"]:
                facility_id = r["ind_enrl_id"]
                name = "{} {}".format(r["frst_nm"], r["lst_nm"])
            else:
                facility_id = r["provider_number"]
                name = r["provider_name"]

            payload = "/inform{\"facility_id\":\"" + facility_id + "\"}"
            buttons.append({
                "title": "{}".format(name.title()),
                "payload": payload
            })

        # limit number of buttons to 3 here for clear presentation purpose
        if "near" in location:
            location = "you"

        dispatcher.utter_button_message(
            "Here is a list of {} {}s near {}".format(len(buttons[:3]),
                                                      button_name, location),
            buttons[:3],
            button_type="custom")
        # todo: note: button options are not working BUG in rasa_core

        return []
Example #5
0
    def run(
        self,
        dispatcher: CollectingDispatcher,
        tracker: Tracker,
        domain: Dict[Text, Any],
    ) -> List["Event"]:

        intent_ranking = tracker.latest_message.get("intent_ranking", [])
        if len(intent_ranking) > 1:
            diff_intent_confidence = intent_ranking[0].get(
                "confidence"
            ) - intent_ranking[1].get("confidence")
            if diff_intent_confidence < 0.2:
                intent_ranking = intent_ranking[:2]
            else:
                intent_ranking = intent_ranking[:1]
        first_intent_names = [
            intent.get("name", "")
            for intent in intent_ranking
            if intent.get("name", "") != "out_of_scope"
        ]

        message_title = (
            "Sorry, I'm not sure I've understood " "you correctly 🤔 Do you mean..."
        )

        entities = tracker.latest_message.get("entities", [])
        entities = {e["entity"]: e["value"] for e in entities}

        entities_json = json.dumps(entities)

        buttons = []
        for intent in first_intent_names:
            logger.debug(intent)
            logger.debug(entities)
            buttons.append(
                {
                    "title": self.get_button_title(intent, entities),
                    "payload": "/{}{}".format(intent, entities_json),
                }
            )

        buttons.append({"title": "Something else", "payload": "/out_of_scope"})

        dispatcher.utter_button_message(message_title, buttons=buttons)

        return []
Example #6
0
    def submit(self, dispatcher: CollectingDispatcher, tracker: Tracker,
               domain: Dict[Text, Any]) -> List[Dict]:
        """Once required slots are filled, print buttons for found facilities"""

        location = tracker.get_slot('location')
        facility_type = tracker.get_slot('facility_type')

        results = _find_facilities(location, facility_type)
        button_name = _resolve_name(FACILITY_TYPES, facility_type)
        if len(results) == 0:
            dispatcher.utter_message(
                "Sorry, we could not find a {} in {}.".format(
                    button_name, location.title()))
            return []

        buttons = []
        # limit number of results to 3 for clear presentation purposes
        for r in results[:3]:
            if facility_type == FACILITY_TYPES["hospital"]["resource"]:
                facility_id = r.get("provider_id")
                name = r["hospital_name"]
            elif facility_type == FACILITY_TYPES["nursing_home"]["resource"]:
                facility_id = r["federal_provider_number"]
                name = r["provider_name"]
            else:
                facility_id = r["provider_number"]
                name = r["provider_name"]

            payload = "/inform{\"facility_id\":\"" + facility_id + "\"}"
            buttons.append({
                "title": "{}".format(name.title()),
                "payload": payload
            })

        if len(buttons) == 1:
            message = "Here is a {} near you:".format(button_name)
        else:
            if button_name == "home health agency":
                button_name = "home health agencie"
            message = "Here are {} {}s near you:".format(
                len(buttons), button_name)

        # TODO: update rasa core version for configurable `button_type`
        dispatcher.utter_button_message(message, buttons)

        return []
    def run(self,
            dispatcher: CollectingDispatcher,
            tracker: Tracker,
            domain: Dict[Text, Any]) -> List:

        global count

        print("count:", count)

        full_path = _create_path(ENDPOINTS["base"])
        results = requests.get(full_path).json()

        if count == 13:

            dispatcher.utter_template('utter_continue', tracker)
            return []
        else:
            selected = results[count]
            count = count + 1

            print("count1:", count)
            print("result:", selected)
            print("que:", selected["question"])
            question = selected["question"]
            option1 = selected["option1"]
            option2 = selected["option2"]
            option3 = selected["option3"]

            buttons = []
            payload1 = "/inform{\"enquiry\": \"" + option1 + "\"}"
            payload2 = "/inform{\"enquiry\": \"" + option2 + "\"}"
            payload3 = "/inform{\"enquiry\": \"" + option3 + "\"}"

            buttons.append({"title": "{}".format(option1.title()), "payload": payload1})
            buttons.append({"title": "{}".format(option2.title()), "payload": payload2})
            buttons.append({"title": "{}".format(option3.title()), "payload": payload3})

        # TODO: update rasa core version for configurable `button_type`;;;;
        dispatcher.utter_button_message(question, buttons)
        # dispatcher.utter_button_template(question, buttons, tracker)
        return []