botfront / rasa-webchat

A feature-rich chat widget for Rasa and Botfront
https://botfront.io/rasa
Apache License 2.0
948 stars 496 forks source link

How can i have access to rasa response inside HTML file and send it to my robot? #430

Closed MortezaAliyari closed 2 years ago

MortezaAliyari commented 2 years ago

Hi, I don't know where is the correct place to ask this question, so if it's the wrong place, sorry about that! I'm using rasa3.1 and everything is working with your HTML file. I want to have access to the rasa response in an HTML file and send it with URL method to my robot? so I need to define a string variable to store received messages as rasa responses and use this message in my own way. I searched a lot but I couldn't find something useful to work correctly. I would be grateful if you give me a hand. thanks.

rajalala commented 2 years ago

By "rasa responses" are you referring to messages from user or Rasa chatbot?

There is parameter onSocketEvent (see README) which allows one to listen and react to some of the socket events, including messages from the bot, but unfortunately that does not include messages from the user. (That event could also be exposed by would require changes to widget source code.)

MortezaAliyari commented 2 years ago

Dear @rajalala thanks for your response. Base on your expalnation onSocketEvent should work for me. I need to listen to messages from rasabot. for example: user: "hi" bot: "Hi there, How can i help you?" I need use bot response "Hi there, How can i help you?" and send it to my mobile robot. How could i use below code in my html file?

onSocketEvent={{
  'bot_uttered': () => console.log('the bot said something'),
  'connect': () => console.log('connection established'),
  'disconnect': () => doSomeCleanup(),
}}

thanks in advance.

MortezaAliyari commented 2 years ago

html code:

<html>
    <body>
        <script>!(function () {
        sessionStorage.clear();// remove chats history 

          let e = document.createElement("script"),
            t = document.head || document.getElementsByTagName("head")[0];
          (e.src =
            "https://cdn.jsdelivr.net/npm/rasa-webchat@1.0.1/lib/index.js"),

            (e.async = !0),
            (e.onload = () => {
              window.WebChat.default(
            {
              intitpayload: '/greet',
              customData: { language: "en" },
              socketUrl: "http://0.0.0.0:5005",
              params:{

                storage: "session" // chats history location is "session", default is "local"

              }

            },
            null
              );
            }),
            t.insertBefore(e, t.firstChild);
        })();

        </script>

    </body>
</html>
stale[bot] commented 2 years ago

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.