question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Socket channel does not return json messages

See original GitHub issue

Rasa version: 1.1.3

Python version: 3.7.3

Operating system (windows, osx, …): WSL Ubuntu 16.04

Issue: Attempting to send custom json response over socket channel returns null instead.

Steps to recreate:

  1. Initialize a new rasa project.
  2. Update the templates in domain with custom json.
  3. Update the credentials file allowing socket channel.
  4. Send message ‘hi’ over socket connection. (I’m using Rasa-Webchat as the interface

Content of credentials file (credentials.yml):

# 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


#facebook:
#  verify: "<verify>"
#  secret: "<your secret>"
#  page-access-token: "<your page access token>"

#slack:
#  slack_token: "<your slack token>"
#  slack_channel: "<the slack channel>"

socketio:
 user_message_evt: user_uttered
 bot_message_evt: bot_uttered
 session_persistence: false

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

Content of domain file (domain.yml):

intents:
  - greet
  - goodbye
  - affirm
  - deny
  - mood_great
  - mood_unhappy

actions:
- utter_greet
- utter_cheer_up
- utter_did_that_help
- utter_happy
- utter_goodbye

templates:
  utter_greet:
  - custom:
      text: "Hey! How are you?"
      something: "wrong"

  utter_cheer_up:
  - text: "Here is something to cheer you up:"
    image: "https://i.imgur.com/nGF1K8f.jpg"

  utter_did_that_help:
  - text: "Did that help you?"

  utter_happy:
  - text: "Great carry on!"

  utter_goodbye:
  - text: "Bye"

The above configuration runs successfully under rasa shell alt text

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Comments:7 (3 by maintainers)

github_iconTop GitHub Comments

2reactions
saket-shuklacommented, Jun 20, 2019

I did a bit of debugging on my own and following are my findings:

  1. The json output as shown in the shell response is available under json_message for rasa’s socketio channel method for sending custom json. Reference: socketio.py line-92
  2. This however does not get transferred to asyncio server’s emit method. Reference: asyncio_server.py line-78
  3. Inferring from the above 2 methods - asyncio expects a keyword data for emitting response, which does not exist. Hence, I updated the domain template to:
templates:
  utter_greet:
  - custom:
      data:
        text: "Hey! How are you?"
        something: "wrong"

This now correctly populates in response.

Conclusion: The custom template should be enclosed under the key data for custom json response.

Having an example for the same would have been helpful. Personally I feel the data key is redundant for a custom json output in socket channel and could have been abstracted from the user.

Please feel free to close this issue.

0reactions
saket-shuklacommented, Jun 20, 2019

Makes sense. Thanks for the clarification and help.

Read more comments on GitHub >

github_iconTop Results From Across the Web

PHP socket shoud return json but returns warning
So it seems socket_recv returns false. why? Is that because of json object in response from server? And how to fix that? Any...
Read more >
SocketChannel.read methods returns '0' for a blocking ...
I am using a blocking socket channel in a client code. Here is the code section which shows the way I am getting...
Read more >
Writing WebSocket client applications - Web APIs | MDN
The constructor will throw a SecurityError if the destination doesn't allow access. This may happen if you attempt to use an insecure connection ......
Read more >
Phoenix.Socket — Phoenix v1.6.15 - HexDocs
A socket implementation that multiplexes messages over channels. Phoenix.Socket is used as ... For sockets requiring no authentication, nil can be returned ......
Read more >
Web API implementation - Best practices for cloud applications
The body of a response message may contain data in a variety of formats. For example, an HTTP GET request could return data...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found