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

        # the session should begin with a `session_started` event
        events = [SessionStarted()]

        events.extend(self._slot_set_events_from_tracker(tracker))

        # create mock profile
        user_profile = create_mock_profile()

        # initialize slots from mock profile
        for key, value in user_profile.items():
            if value is not None:
                events.append(SlotSet(key=key, value=value))

        # an `action_listen` should be added at the end
        events.append(ActionExecuted("action_listen"))

        # evt = {'event': 'followup', 'name': 'action_greet_user'}
        # events.append(evt)
        # events.append(ActionExecuted("action_greet_user"))
        # logger.debug(f"These are the events: {events[-1]}")
        # return [events, FollowupAction("action_listen")]
        return events
Пример #2
0
 async def run(self,dispatcher, tracker, domain):
     events = [SessionStarted()]
     events.extend(self._slot_set_events_from_tracker(tracker))
     username = tracker.get_slot('name') if tracker.get_slot("name") else tracker.current_state()["sender_id"]    
     dispatcher.utter_message(text=f"Hello {username}")
     events.append(ActionExecuted("action_listen"))
     return events
Пример #3
0
    async def run(self, dispatcher, tracker: Tracker,
                  domain: Dict[Text, Any]) -> List[Dict[Text, Any]]:

        # the session should begin with a `session_started` event
        events = [SessionStarted()]
        try:
            r = requests.get(
                'https://1ntj0abfh0.execute-api.us-east-1.amazonaws.com/PROD/customer?contactId='
                + tracker.sender_id)
            print(r.status_code)
            if r.status_code > 300:

                raise Exception("No Data supplied")
            data = r.json()
            for key in data:
                events.append(SlotSet(key, data[key]))
        except:
            data = {
                "name": "DemoMan",
                "payment_amount": "500 pesos",
                "payment_date": "22 de Enero"
            }

            for key in data:
                events.append(SlotSet(key, data[key]))

        # an `action_listen` should be added at the end as a user message follows
        events.append(ActionExecuted("action_listen"))
        return events
Пример #4
0
    async def run(
            self,
            dispatcher: CollectingDispatcher,
            tracker: Tracker,
            domain: Dict[Text, Any],
    ) -> List[EventType]:
        # the session should begin with a `session_started` event
        message_metadata = []
        events = tracker.current_state()['events']
        for e in events:
            if e['event'] == 'user' or e['event'] == 'session_started':
                message_metadata.append(e)
        meta = message_metadata[-1]["metadata"]["metadata"]
        meta_dict = ast.literal_eval(meta)
        per_id = meta_dict["id"]
        fname = meta_dict["first_name"]
        lname = meta_dict["last_name"]
        events = [SessionStarted()]
        dispatcher.utter_message(template="utter_iamabot")
        dispatcher.utter_message("Pleased to meet you, {}!".format(fname))
        dispatcher.utter_message("How're you doing today?")
        # any slots that should be carried over should come after the
        # `session_started` event
        events.extend(self.fetch_slots(dispatcher, tracker))

        # an `action_listen` should be added at the end as a user message follows
        events.append(ActionExecuted("action_listen"))

        return events
Пример #5
0
 def get_carry_over_slots(self, tracker: Tracker) -> List[Dict[Text, Any]]:
     actions = [SessionStarted()]
     carry_over_slots = (HealthCheckTermsForm.SLOTS +
                         HealthCheckProfileForm.PERSISTED_SLOTS +
                         HealthCheckProfileForm.CONDITIONS +
                         ["location_coords", "city_location_coords"])
     for slot in carry_over_slots:
         actions.append(SlotSet(slot, tracker.get_slot(slot)))
     return actions
Пример #6
0
   def run(self, dispatcher: CollectingDispatcher,
            tracker: Tracker,
            domain: Dict[Text, Any]) -> List[EventType]:

       dispatcher.utter_message("Hi, I am Woody. How may I help you")
       events=[SessionStarted()]
       events.append(ActionExecuted("action_listen"))

       return events
Пример #7
0
 def run(self, dispatcher, tracker, domain) -> List[EventType]:
     if not tracker.get_slot("is_authenticated"):
         dispatcher.utter_message(text="You are not logged in")
         return []
     dispatcher.utter_message(text="Hope you will come back!!")
     return [
         AllSlotsReset(),
         SessionStarted(),
         FollowupAction(name="action_restart")
     ]
Пример #8
0
async def test_run_action_session_start(dispatcher, domain):
    tracker = EMPTY_TRACKER
    action = actions.ActionSessionStart()
    events = await action.run(dispatcher, tracker, domain)
    expected_events = [
        SessionStarted(),
        SlotSet("currency", "INR"),
        ActionExecuted("action_listen"),
    ]
    assert events == expected_events
Пример #9
0
 def test_carry_over_slots(self):
     """
     Should set all the carry over slots, and then add a listen at the end
     """
     dispatcher = CollectingDispatcher()
     tracker = Tracker("", {}, None, [], False, None, None, None)
     actions = ActionSessionStart().run(dispatcher, tracker, {})
     assert actions[0] == SessionStarted()
     assert actions[-1] == ActionExecuted("action_listen")
     assert len(actions) > 2
Пример #10
0
 def test_carry_over_slots(self):
     """
     Should send the exit message, and then return all the carry over slots
     """
     dispatcher = CollectingDispatcher()
     tracker = Tracker("", {}, None, [], False, None, None, None)
     actions = ActionExit().run(dispatcher, tracker, {})
     assert actions[0] == SessionStarted()
     assert len(actions) > 1
     [msg] = dispatcher.messages
     assert msg["template"] == "utter_exit"
Пример #11
0
    def run(self, dispatcher, tracker: Tracker, domain: Dict[Text, Any]) -> List[Dict[Text, Any]]:
        # the session should begin with a `session_started` event
        events = [SessionStarted()]
        events.extend(tracker.slots)

        requests.post("https://terapiabot.herokuapp.com/users",
                      {"conversationId": tracker.sender_id, "name": tracker.sender_id})

        dispatcher.utter_message(
            text="Para sincronizar à sua conta do Todoist digite /action_sync_todoist a qualquer momento durante nossa conversa!")

        return events
Пример #12
0
    async def run(self, dispatcher: CollectingDispatcher, tracker: Tracker, domain: Dict[Text, Any], **kwargs) -> List[
        EventType]:

        # the session should begin with a `session_started` event
        events = [SessionStarted()]

        # any slots that should be carried over should come after the
        # `session_started` event
        events.extend(self.fetch_slots(tracker))

        # an `action_listen` should be added at the end as a user message follows
        events.append(ActionExecuted("action_listen"))

        return events
Пример #13
0
    async def run(
        self,
        output_channel: "OutputChannel",
        nlg: "NaturalLanguageGenerator",
        tracker: "DialogueStateTracker",
        domain: "Domain",
    ):
        # the session should begin with a `session_started` event
        events = [SessionStarted(metadata=self.metadata)]

        # any slots that should be carried over should come after the
        # `session_started` event
        events.extend(FollowupAction(name='load_profile'))

        # an `action_listen` should be added at the end as a user message follows
        events.append(ActionExecuted("action_listen"))

        return events
Пример #14
0
    async def run(
        self,
        dispatcher: CollectingDispatcher,
        tracker: Tracker,
        domain: Dict[Text, Any],
    ) -> List[EventType]:
        """Executes the custom action"""
        # the session should begin with a `session_started` event
        events = [SessionStarted()]

        events.extend(self._slot_set_events_from_tracker(tracker))

        # create a mock profile by populating database with values specific to tracker.sender_id
        profile_db.populate_profile_db(tracker.sender_id)
        currency = profile_db.get_currency(tracker.sender_id)

        # initialize slots from mock profile
        events.append(SlotSet("currency", currency))

        # add `action_listen` at the end
        events.append(ActionExecuted("action_listen"))

        return events
Пример #15
0
    async def run(
        self,
        dispatcher: CollectingDispatcher,
        tracker: Tracker,
        domain: Dict[Text, Any],
    ) -> List[EventType]:

        # the session should begin with a `session_started` event
        events = [SessionStarted()]

        events.extend(self._slot_set_events_from_tracker(tracker))

        # create mock profile
        # user_profile = create_mock_profile()

        # initialize slots from mock profile
        #for key, value in user_profile.items():
        #    if value is not None:
        #        events.append(SlotSet(key=key, value=value))

        # an `action_listen` should be added at the end
        events.append(ActionExecuted("action_listen"))

        return events
Пример #16
0
    async def run(
        self,
        dispatcher: CollectingDispatcher,
        tracker: Tracker,
        domain: Dict[Text, Any],
    ) -> List[EventType]:
        # the session should begin with a `session_started` event
        if str(tracker.get_slot("Person_Name")) == "None":
            dispatcher.utter_message(template="utter_iamabot")
            dispatcher.utter_message(template="utter_ask_Person_Name")
        else:
            dispatcher.utter_message("Pleased to meet you, {}!".format(
                str(tracker.get_slot("Person_Name"))))
            dispatcher.utter_message("How're you doing today?")
        events = [SessionStarted()]

        # any slots that should be carried over should come after the
        # `session_started` event
        events.extend(self.fetch_slots(dispatcher, tracker))

        # an `action_listen` should be added at the end as a user message follows
        events.append(ActionExecuted("action_listen"))

        return events
Пример #17
0
 async def run(self, dispatcher, tracker: Tracker,
               domain: Dict[Text, Any]) -> List[Dict[Text, Any]]:
     # the session should begin with a `session_started` event and an `action_listen`
     # as a user message follows
     return [SessionStarted(), ActionExecuted("action_listen")]