# How to get value from user input and pass it into custom actions?

**URL:** <https://forum.rasa.com/t/how-to-get-value-from-user-input-and-pass-it-into-custom-actions/53004>\
**Category:** Rasa Open Source\
**Created:** [May 5, 2022, 2:53am UTC](https://forum.rasa.com/t/how-to-get-value-from-user-input-and-pass-it-into-custom-actions/53004 "2022-05-05T02:53:51Z")\
**Posts on this page:** 14\
**Page:** 1

<div class="post-metadata">

**Author:** ![baodv1001](https://dub1.discourse-cdn.com/flex013/user_avatar/forum.rasa.com/baodv1001/32/20038_2.png) [@baodv1001](https://forum.rasa.com/u/baodv1001)\
**Post date:** [May 5, 2022, 2:53am UTC](https://forum.rasa.com/t/how-to-get-value-from-user-input-and-pass-it-into-custom-actions/53004/1 "2022-05-05T02:53:51Z")

</div>

Hi, I tried to get some values from user input and passed it to my custom action with below code:

_This is my custom action_

```auto
class ActionTrendingByHashTag(Action):

    def name(self) -> Text:
        return "action_trending_by_hashtag"

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

        hashtag = next(tracker.get_latest_entity_values("hashtag"),None)
        result = get_tiktok_trending_by_hashtag(hashtag)
        for video in result:
            dispatcher.utter_message(text=video['title'], image=video['cover'])

        return []

```

_And here is intent_:

```auto
- intent: confirm_hashtag
    examples: |
      - [cosplay](hashtag) nha
      - Hashtag là [cosplay abc](hashtag)
      - Từ khóa là [cosplay](hashtag)
      - hashtag anh muốn tìm là [cosplay](hashtag)
      - Từ khóa cần tìm kiếm là [cosplay](hashtag)
      - Anh muốn tìm về từ khóa [cosplay](hashtag)

```

_In domain.yml, I declared slots and entities_:

```auto
entities:
  - hashtag

slots:
  hashtag:
    type: text
    influence_conversation: true
    mappings:
      - type: from_entity
        entity: hashtag

```

_And I defined a story_:

```auto
- story: ask trending by hashtag
    steps:
      - intent: greet
      - action: utter_greet
      - intent: ask_for_tiktok_trending_by_hashtag
      - action: utter_confirm
      - intent: confirm_hashtag
        entities:
          - hashtag: singsong
      - slot_was_set:
          - hashtag: hashtag
      - action: action_trending_by_hashtag

```

But when I try to push value, action get None. Is there any wrong in my code? Thanks for your time!

---

<div class="post-metadata">

**Author:** ![nik202](https://dub1.discourse-cdn.com/flex013/user_avatar/forum.rasa.com/nik202/32/16098_2.png) [@nik202](https://forum.rasa.com/u/nik202)\
**Post date:** [May 5, 2022, 3:37pm UTC](https://forum.rasa.com/t/how-to-get-value-from-user-input-and-pass-it-into-custom-actions/53004/2 "2022-05-05T15:37:55Z")

</div>

@baodv1001

```auto
first check that are you able to get the user input whilst using the print statement
print(hashtag)
then next like 
get_tiktok_trending_by_hashtag({hashtag})
check
print(result)

```

Ref: [f-strings in Python - GeeksforGeeks](https://www.geeksforgeeks.org/formatted-string-literals-f-strings-python/)

You will get the clear idea. Good luck!

---

<div class="post-metadata">

**Author:** ![baodv1001](https://dub1.discourse-cdn.com/flex013/user_avatar/forum.rasa.com/baodv1001/32/20038_2.png) [@baodv1001](https://forum.rasa.com/u/baodv1001)\
**Post date:** [May 6, 2022, 12:45am UTC](https://forum.rasa.com/t/how-to-get-value-from-user-input-and-pass-it-into-custom-actions/53004/3 "2022-05-06T00:45:13Z")

</div>

Thanks for your reply, when I print(hashtag), it give me None. When I type ‘cosplay’ same with examples, entity can get this value but the other word hashtag is None. Any idea about it?

---

<div class="post-metadata">

**Author:** ![nik202](https://dub1.discourse-cdn.com/flex013/user_avatar/forum.rasa.com/nik202/32/16098_2.png) [@nik202](https://forum.rasa.com/u/nik202)\
**Post date:** [May 6, 2022, 11:42am UTC](https://forum.rasa.com/t/how-to-get-value-from-user-input-and-pass-it-into-custom-actions/53004/4 "2022-05-06T11:42:55Z")

</div>

Are you able to see user input whilst using print statements?

---

<div class="post-metadata">

**Author:** ![baodv1001](https://dub1.discourse-cdn.com/flex013/user_avatar/forum.rasa.com/baodv1001/32/20038_2.png) [@baodv1001](https://forum.rasa.com/u/baodv1001)\
**Post date:** [May 6, 2022, 1:07pm UTC](https://forum.rasa.com/t/how-to-get-value-from-user-input-and-pass-it-into-custom-actions/53004/5 "2022-05-06T13:07:20Z")

</div>

When I ran rasa shell --debug, and I got this result:

 ![image](https://europe1.discourse-cdn.com/flex013/uploads/rasa/original/3X/3/7/37ad17030d8a2eb0c35820b0a495c86f2d252812.png) ![image](https://europe1.discourse-cdn.com/flex013/uploads/rasa/original/3X/c/c/cca32d255b18f28639dc5e59c71c6235af1bc7cb.png)I except the value for entity hashtag is “sontung” but when I print(hashtag), the value is always null. When user input is here: ![image](https://europe1.discourse-cdn.com/flex013/uploads/rasa/original/3X/0/2/02b37dd78aa6c139c16eb5e84f733cea2254916c.png)The entities is not empty. I can’t understand why this happen.

---

<div class="post-metadata">

**Author:** ![baodv1001](https://dub1.discourse-cdn.com/flex013/user_avatar/forum.rasa.com/baodv1001/32/20038_2.png) [@baodv1001](https://forum.rasa.com/u/baodv1001)\
**Post date:** [May 16, 2022, 3:28am UTC](https://forum.rasa.com/t/how-to-get-value-from-user-input-and-pass-it-into-custom-actions/53004/6 "2022-05-16T03:28:42Z")

</div>

Bump

---

<div class="post-metadata">

**Author:** ![nik202](https://dub1.discourse-cdn.com/flex013/user_avatar/forum.rasa.com/nik202/32/16098_2.png) [@nik202](https://forum.rasa.com/u/nik202)\
**Post date:** [May 16, 2022, 1:36pm UTC](https://forum.rasa.com/t/how-to-get-value-from-user-input-and-pass-it-into-custom-actions/53004/7 "2022-05-16T13:36:49Z")

</div>

@baodv1001 you not tag me and I did not saw your message sorry. What is the current status of your error?

---

<div class="post-metadata">

**Author:** ![baodv1001](https://dub1.discourse-cdn.com/flex013/user_avatar/forum.rasa.com/baodv1001/32/20038_2.png) [@baodv1001](https://forum.rasa.com/u/baodv1001)\
**Post date:** [May 16, 2022, 2:11pm UTC](https://forum.rasa.com/t/how-to-get-value-from-user-input-and-pass-it-into-custom-actions/53004/8 "2022-05-16T14:11:01Z")

</div>

@nik202 My bad! I try to put some example values in nlu.yml like this:

 ![image](https://europe1.discourse-cdn.com/flex013/uploads/rasa/original/3X/b/d/bd0ac435794e5a36e97bc3ed0fbf4d307e414d4d.png)

And in custom actions, when user typed which value the same with example, I got it. But with other, the value of entity is still None

---

<div class="post-metadata">

**Author:** ![baodv1001](https://dub1.discourse-cdn.com/flex013/user_avatar/forum.rasa.com/baodv1001/32/20038_2.png) [@baodv1001](https://forum.rasa.com/u/baodv1001)\
**Post date:** [May 16, 2022, 2:16pm UTC](https://forum.rasa.com/t/how-to-get-value-from-user-input-and-pass-it-into-custom-actions/53004/9 "2022-05-16T14:16:57Z")

</div>

@nik202 My partner tried with new intent: ![image](https://europe1.discourse-cdn.com/flex013/uploads/rasa/original/3X/4/2/42d9e2e5a78f94d44fa3918bc9ca7ec82df18c46.png)And he made all files like me, the result he got is: ![image](https://europe1.discourse-cdn.com/flex013/uploads/rasa/original/3X/2/9/29de83f05527a5b394d399d185c3deaba6d5e288.png)

I don’t know why he success but not me.

Should I create an lookup example for the entity? But the entity I want to get value is unpredictable such as hashtag, … because it has very many different values.

---

<div class="post-metadata">

**Author:** ![nik202](https://dub1.discourse-cdn.com/flex013/user_avatar/forum.rasa.com/nik202/32/16098_2.png) [@nik202](https://forum.rasa.com/u/nik202)\
**Post date:** [May 16, 2022, 10:35pm UTC](https://forum.rasa.com/t/how-to-get-value-from-user-input-and-pass-it-into-custom-actions/53004/10 "2022-05-16T22:35:31Z")

</div>

@baodv1001 should also work in your case too.

It hard for me to comment without seeing the code, if you need to talk to me please schedule the appointment if you are ok with it.

---

<div class="post-metadata">

**Author:** ![baodv1001](https://dub1.discourse-cdn.com/flex013/user_avatar/forum.rasa.com/baodv1001/32/20038_2.png) [@baodv1001](https://forum.rasa.com/u/baodv1001)\
**Post date:** [May 17, 2022, 1:35am UTC](https://forum.rasa.com/t/how-to-get-value-from-user-input-and-pass-it-into-custom-actions/53004/11 "2022-05-17T01:35:08Z")

</div>

@nik202 I don’t change my code, now it the same with above. I don’t know where is my mistake to fix that ☹ Do you need more code, tell me, I will show it. Thanks so much!

---

<div class="post-metadata">

**Author:** ![baodv1001](https://dub1.discourse-cdn.com/flex013/user_avatar/forum.rasa.com/baodv1001/32/20038_2.png) [@baodv1001](https://forum.rasa.com/u/baodv1001)\
**Post date:** [May 24, 2022, 1:40pm UTC](https://forum.rasa.com/t/how-to-get-value-from-user-input-and-pass-it-into-custom-actions/53004/12 "2022-05-24T13:40:57Z")

</div>

Bump

---

<div class="post-metadata">

**Author:** ![nik202](https://dub1.discourse-cdn.com/flex013/user_avatar/forum.rasa.com/nik202/32/16098_2.png) [@nik202](https://forum.rasa.com/u/nik202)\
**Post date:** [May 24, 2022, 4:34pm UTC](https://forum.rasa.com/t/how-to-get-value-from-user-input-and-pass-it-into-custom-actions/53004/13 "2022-05-24T16:34:33Z")

</div>

@baodv1001 I already shared the solution’s, suggestion and even proposed to schedule a meeting but you have not shown any interest so sorry I can not help much on this. Good Luck!

---

<div class="post-metadata">

**Author:** ![baodv1001](https://dub1.discourse-cdn.com/flex013/user_avatar/forum.rasa.com/baodv1001/32/20038_2.png) [@baodv1001](https://forum.rasa.com/u/baodv1001)\
**Post date:** [May 25, 2022, 1:01am UTC](https://forum.rasa.com/t/how-to-get-value-from-user-input-and-pass-it-into-custom-actions/53004/14 "2022-05-25T01:01:39Z")

</div>

@nik202 Thanks for you support. I realize that if I want to get some value like email, phone number … I should use entity and regex to extract that entity. But with dynamic value like name, hashtag, … should use form to extract value. I will try this idea soon. Thanks again!
