Setting a slot that captures the value provided by initPayload

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

Could you give us some samples of your code?

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

<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>

How about the login_token slot? is auto_fill: false ?

yes

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

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 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:

    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:

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:

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:

tracker.get_slot("sessionid")

A more complete example:

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

Introduction to Slots | Rasa Tutorial