Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Video/Image Not Showing #41

Closed
arni5na opened this issue Dec 16, 2018 · 9 comments
Closed

Video/Image Not Showing #41

arni5na opened this issue Dec 16, 2018 · 9 comments

Comments

@arni5na
Copy link

arni5na commented Dec 16, 2018

Hi there! I'm trying to send a video/image to the chat UI from Rasa but this is what i'm getting:

screen shot 2018-12-16 at 2 51 48 pm

This is a snippet of my actions.py code:
screen shot 2018-12-16 at 2 53 30 pm

I have an actions server and my socket server code is on another Python file. If I use the SocketIOOUtput Class, it will ask me for a recipient ID which I'm not sure where to get. I'm pretty new to Python and Rasa. Any help would be much appreciated!

@arni5na
Copy link
Author

arni5na commented Dec 16, 2018

Update: I used dispatcher.utter_attachment(message) with message = {
"type":"video",
"payload":{
"title":"Link name",
"src": "https://youtu.be/f3EbDbm8XqY"
}
}

But it still shows as text in the chat window:
screen shot 2018-12-16 at 4 28 58 pm

@znat
Copy link
Contributor

znat commented Dec 16, 2018

With Rasa Core it must follow the template schema.
So for an image:

{
  text: ...,
  image: ...
}

See: https://rasa.com/docs/core/domains/#images-and-buttons

@arni5na
Copy link
Author

arni5na commented Dec 17, 2018

I was able to send an image by adding it in the templates of the domain file, but I can't send through the custom actions. I changed the value of the message variable in my actions file into this:
message = {
"attachment":{
"type":"image",
"payload":{
"text":"Test",
"image": "img.jpg"
}
}
}

Then I used the dispatcher to send it, but it still doesn't show the image. I'm not sure if I'm in the right track here. Is it possible to send image/video through the custom actions or it can only be done through the domain file?

@bing-zhub
Copy link

I have encountered the same problem with you, attachment should be part of response. The reality is that it is part of text. I don't know if you have solved this problem.

@arni5na
Copy link
Author

arni5na commented Jan 7, 2019

Sorry, I got busy... Anyway, it seems that we need the Rasa core output channel of the webchat to send the video. I checked the rasa-addons link where we supposed can get it but I didn't find it there...

@hrqiang
Copy link

hrqiang commented Jan 17, 2019

the socketio.py doesn't seem like it supports video tag, so there is a mismatch.
The other way is send thru custom message.

@arni5na
Copy link
Author

arni5na commented Feb 20, 2019

It's still not working using custom message. This is the video JSON data I sent to the UI:

message = {
                "attachment":{
                    "type":"video",
                    "title":"Link name",
                     "src": "https://www.youtube.com/watch?v=f3EbDbm8XqY"
                }
            }

I did a debug on the UI and it's acknowledging that it received the data as video but it just doesn't show it. Is there a video JSON format that I should follow?

@arni5na
Copy link
Author

arni5na commented Mar 31, 2019

Got it finally resolved. These are the steps I did:

In CollectingDispatcher class, I added this function:

    def utter_response(self, message: Dict[Text, Any]) -> None:
        """Send a message to the client."""
        
        self.messages.append(message)

In SocketIOOutput class of the socketio module, I added the following:

    def send_response(self, recipient_id: Text, message: Dict[Text, Any]):
        self._send_message(self.sid, message)

In the Dispatcher class of the dispatcher module, I made the following changes:

    def utter_response(self, message: Dict[Text, Any]) -> None:
        """Send a message to the client."""

        bot_message = BotMessage(text=message.get("text"),
                                 data={"elements": message.get("elements"),
                                       "buttons": message.get("buttons"),
                                       "attachment": message.get("video")})

        self.latest_bot_messages.append(bot_message)
        self.output_channel.send_response(self.sender_id, message)

@arni5na arni5na closed this as completed Mar 31, 2019
@arni5na
Copy link
Author

arni5na commented Apr 10, 2019

Sorry, above fix caused some issue when dispatching messages other than video attachment. I made changes to the send_custom_message function in socketio instead:

def send_custom_message(self, recipient_id: Text, elements: List[Dict[Text, Any]]) -> None: """Sends elements to the output.""" #print(">>>elements:", elements) message = '' try: if not any('attachment' in d for d in elements): message = {"attachment": { "type": "template", "payload": { "template_type": "generic", "elements": elements[0] }}} else: message = elements[0] self._send_message(self.sid, message) except Exception as e: print("Error sending custom message:", e)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants