How to trigger events from custom actions

Hello,

I am using rasa version 2.8

I have a 2 part question

  1. Can we still trigger UserUttered event from custom actions/forms in rasa 2 ?
  2. If yes, then how can we do it?
1 Like

Welcome to the forum :slight_smile:

As per the docs, you can use that event in 2.x and 3.x.

You use it like any other event, by returning it in a list from a custom action.


UserUttered(
    text: Text,                 # Text of the message
    parse_data: Dict[Text, Any] # Parsed data of user message ordinarily filled by NLU
    timestamp: float,           # Optional timestamp of the event
    input_channel: Text         # The channel on which the message was received
)

@ChrisRahme Thankyou for your reply!

I saw this in docs, can you give me an example on how to implement this using all four fields

Thanks

@NIkhilBhaskar

Demo example:

UserUttered(text, parse_data["intent"], parse_data["entities"],
                           parse_data, timestamp, input_channel)
UserUttered(
    text = 'Hello',
    parse_data = {
        'id': 123456789,
        'name': 'greet',
        'confidence': 1
    },
    timestamp = int(time.time()),
    input_channel = tracker.get_latest_input_channel()
)

@ChrisRahme Thankyou so much this is reallly helpful!!! in parse_data can I get id from tracker? or can I give any value to it? and name is intent name which I want? right?

Thanks

thanks @nik202

It should just be a unique value. You can use int(time.time() * 1000) for example.

Yup!

Thanks @ChrisRahme

1 Like

No problem :slight_smile: Please mark the answer that helped you as solution