0

I have the same question as in: Get Intent Value in RASA Core/NLU but I want the value that the user gives for a given intent.

For example:

User: I want to take it (this sentence is an intent called: 'use_it')
Bot: ....
User: .... (Later in the chat I decide to answer with the same phrase of intent 'use it') 
Bot: you said previously "I want to take it"

How can I do something like: tracker.get_slot but for intent?

I don't want the name of the last intent I want the text of a user-given intent.

Community
  • 1
  • 1
chemssou
  • 7
  • 1
  • 7

2 Answers2

0

Execute a custom action after the intent in which you store the intent text in a slot:

from rasa_core_sdk import Action
from rasa_core_sdk.events import SlotSet

class ActionStoreIntentMessage(Action):
    """Stores the bot use case in a slot"""

    def name(self):
        return "action_store_intent_message"

    def run(self, dispatcher, tracker, domain):

        # we grab the whole user utterance here as there are no real entities
        # in the use case
        message = tracker.latest_message.get('text')

        return [SlotSet('intent_message', message)]

You can then use the value of the set slot within an utter template:

slots:
  intent_message:
    type: text

templates:
  utter_last_intent:
    - "you said previously: {intent_message}"
Tobias
  • 1,880
  • 11
  • 17
  • I get this error by doing this : AttributeError: 'UserUttered' object has no attribute 'get' will give more details in a message – chemssou Nov 22 '18 at 11:15
  • I have changed tracker.latest_message.get('text') with tracker.latest_message.text and now I'am getting: NameError: name 'SlotSet' is not defined – chemssou Nov 22 '18 at 11:35
  • Solved the last one () I just forgot to import SoltSet. My final issue is that the bot recognise the 'intent_message' slot but when I use it in a template it does not show. It shows: you said previously: {intent_message} Any help please? – chemssou Nov 22 '18 at 11:47
  • My work arround is to add another costum action after saving the new slot. In the second costum action, I do something like:' message = tracker.get_slot('intent_message') response = """you said previously: {} """.format(loc) dispatcher.utter_message(response)' – chemssou Nov 22 '18 at 12:27
  • I added the imports and the slot definition to my example. Should work now this way. – Tobias Nov 22 '18 at 12:42
0

You can use tracker for the task.

text=tracker.latest_message['text']
Sagar Dhungel
  • 391
  • 2
  • 6