0

I'm using the Botfront/rasa-webchat component on a webpage. I want to send the message returned by the bot to a bot libre avatar. TBH I'm not a javascript programmer, most of my work is in python, but I cannot figure out how I can get the result returned by rasa so I can pass it to the avatar SDK. I believe the onSocketEvent may hold the key, but I haven't been able to make that work. Please help. Here's my current (dysfunctional) code.

<html>
<body>
    <p>welcome to the class chatbot</p>
  <script type='text/javascript' src="https://www.botlibre.com/scripts/sdk.js"></script>
  <script type='text/javascript'>
    !(function () {
    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",
            onSocketEvent: onSocketEvent,
            // add other props here
          },
          null
        );
      }),
      t.insertBefore(e, t.firstChild);
  })();

  SDK.applicationId = "1591399486198011154";
  var sdk = new SDKConnection();
  var web = new WebAvatar();
  web.version = 8.5;
  web.connection = sdk;
  web.avatar = "37788053";
  web.voice = "cmu-slt";
  web.voiceMod = "default";
  web.width = "300";
  web.height = "300";
  web.createBox();
  web.addMessage("Hello, I am Tuesday. The class chatbot", "", "", "");
  web.processMessages();
  onSocketEvent={
    'bot_uttered': function(e) {console.log(e.bot_uttered)
    },
    'connect': () => console.log('connection established'),
    'disconnect': () => doSomeCleanup(),
  };
  </script>
</body>
</html>
rwreed
  • 348
  • 2
  • 10

2 Answers2

1

Just replace e.bot_uttered with e.text. The event object already contains the text key with value as the recently uttered message. Also, directly assign the onSocketEvent like this:

  onSocketEvent:{
    'bot_uttered': function(e) {console.log(e.text)},
    'connect': function() {console.log('connection established')},
    'disconnect': function() {doSomeCleanup()},
  };
0

Helo!

To "capture" bot messages and all events you will need to enable generation of events in the rasa (called event-brokers). One of the events that are generated are the responses from the bot.

In this scenario you have some alternatives such as:

  • send events to rabbitMQ (pika events)
  • send events to kafka broker
  • send events directly in SQL

This way you can consume this information and send it wherever you want.

I hope I've helped.

Wlad Neto
  • 351
  • 3
  • 10