# Setting a slot that captures the value provided by initPayload

**URL:** <https://forum.rasa.com/t/setting-a-slot-that-captures-the-value-provided-by-initpayload/41288>\
**Category:** Rasa Open Source\
**Created:** [March 15, 2021, 8:57am UTC](https://forum.rasa.com/t/setting-a-slot-that-captures-the-value-provided-by-initpayload/41288 "2021-03-15T08:57:16Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![Horizon733](https://dub1.discourse-cdn.com/flex013/user_avatar/forum.rasa.com/horizon733/32/20855_2.png) [@Horizon733](https://forum.rasa.com/u/Horizon733)\
**Post date:** [March 15, 2021, 8:57am UTC](https://forum.rasa.com/t/setting-a-slot-that-captures-the-value-provided-by-initpayload/41288/1 "2021-03-15T08:57:16Z")

</div>

I tried everything but still, I am not able to set a slot via this method can you guys help me out. I also tried manually in shell still nothings works. What I want to achieve is when user login my website bot should capture the value provided by initPayload and set slot with it. Versions used: 2.1.2, 2.2.4 and 2.3.4

---

<div class="post-metadata">

**Author:** ![digitalWestie](https://dub1.discourse-cdn.com/flex013/user_avatar/forum.rasa.com/digitalwestie/32/11329_2.png) [@digitalWestie](https://forum.rasa.com/u/digitalWestie)\
**Post date:** [March 15, 2021, 11:22am UTC](https://forum.rasa.com/t/setting-a-slot-that-captures-the-value-provided-by-initpayload/41288/2 "2021-03-15T11:22:57Z")

</div>

Could you give us some samples of your code?

---

<div class="post-metadata">

**Author:** ![Horizon733](https://dub1.discourse-cdn.com/flex013/user_avatar/forum.rasa.com/horizon733/32/20855_2.png) [@Horizon733](https://forum.rasa.com/u/Horizon733)\
**Post date:** [March 15, 2021, 12:55pm UTC](https://forum.rasa.com/t/setting-a-slot-that-captures-the-value-provided-by-initpayload/41288/3 "2021-03-15T12:55:07Z")

</div>

Here in greet\_payload you can have a look what I am trying to do.  
Explaination: I am capturing username from website and sending to bot but bot gets it as None, it’s not receiving it

```auto
<script>!(function () {
    let propUser = window.localStorage.getItem('user')
    let propName = propUser ? propUser.split('@')[0] : '';
    let greet_payload = propUser ? `/greet{"login_token":"${propUser}"}` : '/greet';
    console.log(propUser, propName, greet_payload)
    let e = document.createElement("script"),
      t = document.head || document.getElementsByTagName("head")[0];
    (e.src =
      "https://cdn.jsdelivr.net/npm/rasa-webchat/lib/index.js"),
      (e.async = !0),
      (e.onload = () => {
        window.WebChat.default(
          {
            customData: { language: "en" },
            socketUrl: "http://localhost:5005",
            initPayload: greet_payload
          },
          null
        );
      }),
      t.insertBefore(e, t.firstChild);
  })();
  </script>

```

---

<div class="post-metadata">

**Author:** ![digitalWestie](https://dub1.discourse-cdn.com/flex013/user_avatar/forum.rasa.com/digitalwestie/32/11329_2.png) [@digitalWestie](https://forum.rasa.com/u/digitalWestie)\
**Post date:** [March 15, 2021, 1:22pm UTC](https://forum.rasa.com/t/setting-a-slot-that-captures-the-value-provided-by-initpayload/41288/4 "2021-03-15T13:22:21Z")

</div>

How about the `login_token` slot? is `auto_fill: false` ?

---

<div class="post-metadata">

**Author:** ![Horizon733](https://dub1.discourse-cdn.com/flex013/user_avatar/forum.rasa.com/horizon733/32/20855_2.png) [@Horizon733](https://forum.rasa.com/u/Horizon733)\
**Post date:** [March 15, 2021, 1:30pm UTC](https://forum.rasa.com/t/setting-a-slot-that-captures-the-value-provided-by-initpayload/41288/5 "2021-03-15T13:30:23Z")

</div>

yes

---

<div class="post-metadata">

**Author:** ![deeksha1](https://avatars.discourse-cdn.com/v4/letter/d/b4bc9f/32.png) [@deeksha1](https://forum.rasa.com/u/deeksha1)\
**Post date:** [July 12, 2022, 10:37am UTC](https://forum.rasa.com/t/setting-a-slot-that-captures-the-value-provided-by-initpayload/41288/6 "2022-07-12T10:37:01Z")

</div>

Hey! Any idea how to solve that issue? even i am getting None. i want the username from website to bot.

---

<div class="post-metadata">

**Author:** ![edu\_vives](https://avatars.discourse-cdn.com/v4/letter/e/7993a0/32.png) [@edu\_vives](https://forum.rasa.com/u/edu_vives)\
**Post date:** [September 29, 2022, 8:33am UTC](https://forum.rasa.com/t/setting-a-slot-that-captures-the-value-provided-by-initpayload/41288/7 "2022-09-29T08:33:16Z")

</div>

> [@Horizon733](#):
>
> ll, I am not able to set a slot via this metho

I have had the same problem and after a lot of research I have managed to get it working. The version of Rasa that I use is 2.1.2, since the higher versions had compatibility problems with the chat widget [Rasa Webchat](https://github.com/botfront/rasa-webchat) and/or the connection with sockets did not work.

First of all you must pass correctly next to the `initPayload` the _entity_ or _entities_ that you want to receive in the Rasa Server. To do this, the structure is as follows:

With one entity: `/greet{"sessionid" : "text_1"}`

Multiple entities: `/greet{"sessionid" : "text_1", "csrftoken" : "text_2", "csrfmiddlewaretoken" : "text_3"}`

If you want to incorporate the value of the entities dynamically, you can use this example method I have created:

```auto
    function generateInitPayload() {
        let action = '/greet';
        let sessionid = "{{ request.session.session_key }}";
        let csrfmiddlewaretoken = document.getElementsByName("csrfmiddlewaretoken")[0].value;
        let csrftoken = getCookie("csrftoken");
        return action + '{\"csrfmiddlewaretoken\":\"' + csrfmiddlewaretoken + '\",\"csrftoken\":\"' + csrftoken + '\",\"sessionid\":\"' + sessionid + '\"}';
    }
    ...
    initPayload: generateInitPayload(),
    ...

```

Once Rasa can get the _entities_ correctly, to save them in _Slots_ and be able to access them at any time of the session, you must declare the `entities` that you pass next to the `initPyaload` in the `domain.yml` file, you must also declare the `slots` that will store those values.

In Rasa 2.x the slots must have the same name as the entity they store. In Python 3.x I am not sure if it is mandatory that they have the same name, since they can be mapped, but by standard it is recommended that they share a name.

You must indicate in the domain.yml that those Slots should be automatically filled with the value of that entity when the entity is received with any intent.

For this, in Rasa 2.x:

```auto
entities:
  - sessionid
  - csrftoken
  - csrfmiddlewaretoken

slots:
  sessionid:
    type: text
    auto_fill: true
  csrftoken:
    type: text
    influence_conversation: false
    auto_fill: true
  csrfmiddlewaretoken:
    type: text
    influence_conversation: false
    auto_fill: true

# It is not necessary to indicate if they influence the conversation, this is only for my entities.

```

In Rasa 3.x:

```auto
entities:
  - sessionid
  - csrftoken
  - csrfmiddlewaretoken

slots:
  sessionid:
    type: text
      mappings:
      - type: from_entity
        entity: sessionid
  csrftoken:
    type: text
    influence_conversation: false
      mappings:
      - type: from_entity
        entity: csrftoken
  csrfmiddlewaretoken:
    type: text
    influence_conversation: false
      mappings:
      - type: from_entity
        entity: csrfmiddlewaretoken

```

Finally, if you want to access the value of those _Slots_ in a Custom Action, you can with the tracker:

```auto
tracker.get_slot("sessionid")

```

A more complete example:

```auto
requests.get(domainUrl + "selected_data/", params={"csrfmiddlewaretoken":tracker.get_slot("csrfmiddlewaretoken")}, cookies={"sessionid":tracker.get_slot("sessionid"),"csrftoken":tracker.get_slot("csrftoken")})

```

In case you have any doubts, these videos show very clearly how to declare and use Slots:

[Memory and Slots in Rasa | Rasa Tutorial](https://www.youtube.com/watch?v=Ss1xRQv9jWg&ab_channel=Rasa)

[Introduction to Slots | Rasa Tutorial](https://www.youtube.com/watch?v=4d730wRyEQE&ab_channel=Rasa)
