Rasa Webchat Integration

hey @Wy0024, the buttons which you send from rasa are treated as quick replies in the webchat, attaching some of the reference that might help you:

buttons registered in domain.yml file:

responses:
  utter_greet:
  - text: "Hey! How are you?"
    buttons:
    - title: "great"
      payload: "great"
    - title: "super sad"
      payload: "super sad"
  utter_cheer_up:
  - text: "Here is something to cheer you up:"
    image: "https://i.imgur.com/nGF1K8f.jpg"

button rendered as quick replies and treated as MESSAGES_TYPES in the webchat:

buttons

https://github.com/botfront/rasa-webchat/blob/9d6e692ea780e3b5b0ef394a3889e0240979689a/src/constants.js#L22

GitHub - botfront/rasa-webchat: A feature-rich chat widget for Rasa and Botfront

Let me know if this helps :slight_smile:

2 Likes

Thanks @JiteshGaikwad ! This is helpful. Also, I notice there is some additional usage on the webchat Github page here. How do i incorporate these additional usage (sending image file, video etc) into my custom action file?

For the buttons/ quick replies, i specify a certain pattern in domain.yml. But how do i use something as below?

message = {
  "attachment":{
    "type":"template",
    "payload":{
      "template_type":"generic",
      "elements":[
        {
          "title":"Title",
          "buttons":[ {
            "title":"Link name",
            "url": "http://link.url"
          }
        ]
      }
    ]
  }
}
}
emit('bot_uttered', message, room=socket_id)

Thanks

You have to convert the json code they provide into yaml (unless there is another way of doing it I don’t know about). So in your response in domain.yml

utter_some_message:
  - text: hello world
    attachment:
      type: template
      payload:
        template_type: generic
        elements:
        - title: Title here
          buttons:
          - title: Link name here
            url: "http://link.url"

I’ve been using a converter tool to see and check to make sure I have exactly what they require on their docs. Something like this worked for me, can even type in YAML and check to see the JSON matches too. https://www.json2yaml.com/

To further this discussion. I am wondering if anyone has any experience adding custom things like cards or carousels similar to how facebook’s looks? My impression is that you’d have to add a custom react component. I’m just curious as to what extent. Does it require forking of their base code to make it work or can we just add some react components in the init section of the script?

I did have a quick browse through the code but I am only a little familiar with the react process.

1 Like

Hi @JiteshGaikwad, It worked fine for me but if I put the script part in other template its not working how to make it work in any template ? thank you.

Hey @skjainmiah, can you explain a bit, I didn’t quiet get what you are trying to say.

I’m really sorry I wasn’t feeling well so I didn’t see your message. The script part taken from GitHub is working fine.

// Or you can replace latest with a specific version

But if I put the same code in different chat templates it is not working. I changed java script in the new chat html template but still it’s not working.

I have included script but it wasn’t showing here so I’m attaching link of the code: GitHub - botfront/rasa-webchat: A chat widget for Rasa and Botfront from here I have taken script and created a html page and put in it. Its working fine till here. what my question is if I place same webchat script in other html chatting templates It wasn’t working what is the reason.

Hello,

I’m trying to plug RASA on my page, but the widget doesn’t appear and the console keeps showing CORS error.

Below I put how I tried to put all to work.

HTML page:

<html>
<body>
	<div id="webchat"></div>
	<script src="https://storage.googleapis.com/mrbot-cdn/webchat-latest.js"></script>
	<script>
		WebChat.default.init({
			selector: "#webchat",
			initPayload: "/get_started",
			customData: { "language": "pt" }, // arbitrary custom data. Stay minimal as this will be added to the socket
			socketUrl: "http://localhost:5005",
			socketPath: "/socket.io/",
			title: "Global Antares",
			subtitle: "Antares",
			connectOn: "open",
			hideWhenNotConnected : "false"
		})
	</script>
</body>
</html>

RASA start command line:

rasa run -m models --enable-api --cors '*' --debug

Every time that widget tries to connect apears:

2020-03-18 11:11:18 DEBUG rasa.core.channels.socketio - User 196e28d40f8f4bf28903b66c7c693420 connected to socketIO endpoint. 2020-03-18 11:1 1:36 DEBUG rasa.core.channels.socketio - User ab11abcf07364e34866edede15987bed disconnected from socketIO endpoint.

And the console on browser shows:

teste.html:1 Access to XMLHttpRequest at ‘http://localhost:5005/socket.io/?EIO=3&transport=polling&t=N3j-F6b’ from origin ‘null’ has been blocked by CORS policy: No ‘Access-Control-Allow-Origin’ header is present on the requested resource.

Log from RASA initialization:

2020-03-18 09:41:41 DEBUG rasa.core.utils - Available web server routes: /conversations/<conversation_id>/messages POST add_message /conversations/<conversation_id>/tracker/events POST append_events /webhooks/rasa GET custom_webhook_RasaChatInput.health /webhooks/rasa/webhook POST custom_webhook_RasaChatInput.receive /webhooks/rest GET custom_webhook_RestInput.health /webhooks/rest/webhook POST custom_webhook_RestInput.receive /model/test/intents POST evaluate_intents /model/test/stories POST evaluate_stories /conversations/<conversation_id>/execute POST execute_action /domain GET get_domain /socket.io GET handle_request / GET hello /model PUT load_model /model/parse POST parse /conversations/<conversation_id>/predict POST predict /conversations/<conversation_id>/tracker/events PUT replace_events /conversations/<conversation_id>/story GET retrieve_story /conversations/<conversation_id>/tracker GET retrieve_tracker /webhooks/socketio GET socketio_webhook.health /status GET status /model/predict POST tracker_predict /model/train POST train /conversations/<conversation_id>/trigger_intent POST trigger_intent /model DELETE unload_model /version GET version

2020-03-18 09:41:41 INFO root - Starting Rasa server on http://localhost:5005 2020-03-18 09:41:41 DEBUG rasa.core.utils - Using the default number of Sanic workers (1). 2020-03-18 09:41:41 INFO root - Enabling coroutine debugging. Loop id 1621305365384. 2020-03-18 09:41:41 DEBUG rasa.model - Extracted model to ‘C:\Users\lluchini\AppData\Local\Temp\tmpar5dl75o’. 2020-03-18 09:41:42 INFO rasa.nlu.components - Added ‘SpacyNLP’ to component cache. Key ‘SpacyNLP-pt’. 2020-03-18 09:41:42 DEBUG rasa.utils.tensorflow.models - Loading the model … 2020-03-18 09:41:42.770020: W tensorflow/stream_executor/platform/default/dso_loader.cc:55] Could not load dynamic library ‘nvcuda.dll’; dlerror: nvcuda.dll not found 2020-03-18 09:41:42.775639: E tensorflow/stream_executor/cuda/cuda_driver.cc:351] failed call to cuInit: UNKNOWN ERROR (303) 2020-03-18 09:41:42.781225: I tensorflow/stream_executor/cuda/cuda_diagnostics.cc:169] retrieving CUDA diagnostic information for host: apdata676 2020-03-18 09:41:42.787204: I tensorflow/stream_executor/cuda/cuda_diagnostics.cc:176] hostname: apdata676 2020-03-18 09:41:42.790519: I tensorflow/core/platform/cpu_feature_guard.cc:142] Your CPU supports instructions that this TensorFlow binary was not compiled to use: AVX2 2020-03-18 09:41:43 DEBUG rasa.utils.tensorflow.models - Finished loading the model. 2020-03-18 09:41:43 DEBUG rasa.utils.tensorflow.models - Building tensorflow prediction graph… 2020-03-18 09:41:43.669010: W tensorflow/core/kernels/data/generator_dataset_op.cc:103] Error occurred when finalizing GeneratorDataset iterator: Cancelled: Operation was cancelled 2020-03-18 09:41:47 DEBUG rasa.utils.tensorflow.models - Finished building tensorflow prediction graph. 2020-03-18 09:41:47 DEBUG rasa.nlu.classifiers.diet_classifier - Failed to load model. Maybe the path ‘C:\Users\lluchini\AppData\Local\Temp\tmpar5dl75o\nlu’ doesn’t exist? 2020-03-18 09:41:47 DEBUG rasa.core.tracker_store - Connected to InMemoryTrackerStore. 2020-03-18 09:41:47 DEBUG rasa.core.lock_store - Connected to lock store ‘InMemoryLockStore’. 2020-03-18 09:41:47 DEBUG rasa.model - Extracted model to ‘C:\Users\lluchini\AppData\Local\Temp\tmp0up4ifrc’. 2020-03-18 09:41:47 DEBUG pykwalify.compat - Using yaml library: c:\venv\lib\site-packages\ruamel\yaml_init_.py 2020-03-18 09:41:47 DEBUG rasa.utils.tensorflow.models - Loading the model … 2020-03-18 09:41:48 DEBUG rasa.utils.tensorflow.models - Finished loading the model. 2020-03-18 09:41:48 DEBUG rasa.utils.tensorflow.models - Building tensorflow prediction graph… 2020-03-18 09:41:48.085525: W tensorflow/core/kernels/data/generator_dataset_op.cc:103] Error occurred when finalizing GeneratorDataset iterator: Cancelled: Operation was cancelled 2020-03-18 09:41:48 DEBUG rasa.utils.tensorflow.models - Finished building tensorflow prediction graph. 2020-03-18 09:41:48 DEBUG rasa.core.nlg.generator - Instantiated NLG to ‘TemplatedNaturalLanguageGenerator’.

Hey @lluchini, I see you haven’t registered your bot with socket.io channel due to which you are facing the above issue, check this out it may help you:

Your Own Website

Hello @JiteshGaikwad, if you’re talking about the credentials.yml it was already set like below.

# This file contains the credentials for the voice & chat platforms
# which your bot is using.
# https://rasa.com/docs/rasa/user-guide/messaging-and-voice-channels/

rest:
#  # you don't need to provide anything here - this channel doesn't
#  # require any credentials

rasa:
  url: "http://localhost:5002/api"

socketio:
  user_message_evt: user_uttered
  bot_message_evt: bot_uttered
  session_persistence: true

And at the log from previously post the socket.io is listed as below.

/socket.io GET handle_request

/webhooks/socketio GET socketio_webhook.health

Hey @lluchini, sorry my bad I missed out that :sweat_smile:

@JiteshGaikwad no problem at all! Any help is welcome!!!

Hey @lluchini, why don’t you try running the above command as below:

rasa run -m models --enable-api --cors “*” --debug

Just making it cors as double quote.

1 Like

Maaaaan, I LOVE YOU!!! It was the quotes!!!:kissing_heart:

Thank you so much!!! I owe you a big one!!!

Hey @lluchini, thanks Man, I am glad that it worked out well and your problem is solved :+1::wink:. Thanks for trying it out​:blush:

@JiteshGaikwad can you give example about

`initPayload: "/get_started"`
can i use existing template on this or action?

you can use that

Is the double quotes necessary in all circumstances? Were running this line in docker.

"exec rasa x --no-prompt --production (Other stuff here...) --enable-api --debug --cors '*'"

I have tried your tutorial and it works. However, when I enter any message it reads the message but there is no reply that is sent from the bot…any suggestions on how to fix it?

2020-03-22 15:47:31 DEBUG rasa.core.processor - Received user message ‘hey’ with intent ‘{‘name’: ‘greet’, ‘confidence’: 0.9997854828834534}’ and entities ‘[]’ 2020-03-22 15:47:31 DEBUG rasa.core.processor - Logged UserUtterance - tracker now has 7 events. 2020-03-22 15:47:31 DEBUG rasa.core.lock_store - Deleted lock for conversation ‘b267a27e10bf41a2bf222a0b3cca1806’.

1 Like

the issue still perils. whether I use single quote or double quote. please see below (rasa-venv) m.srinivasan@ATTACHCREDITTONE Rasa-Init-Yes-Train-InitialModel % rasa run -m ./models/20200323-132806.tar.gz --enable-api --cors “*” --debug

any idea?