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.

how to display images in chat bot using custom Component .Any example?

See original GitHub issue

Hi I am new to react. I want to display an Image in chat bot using custom component. Please providing any example. For example i am trying below code using an api(json Data). If response is text type display that message using addResponse method. Similarly buttons also. But if response is Image type then how to display using customcomponent.Please help me

`export default class App extends Component { state = { todoss: [] }

componentDidMount() { addResponseMessage(‘Welcome to this awesome chat!’); }

handleNewUserMessage = (newMessage) => {
  fetch('http://localhost:5005/webhooks/rest/webhook', {
        method: 'POST',
         headers : new Headers(),
         body:JSON.stringify({"sender": "Rasa", "message": newMessage}),
         }).then((res) => res.json())
         .then((data) => {
          var first = data[0];
          var mm= first.text;
          var i;
          console.log(mm)
          toggleMsgLoader();
          setTimeout(() => {
          toggleMsgLoader();
        if (data.length < 1) {
		   addResponseMessage("I could not get....");
	    } else {
		//if we get response from Rasa
		for ( i = 0; i < data.length; i++) {
			//check if there is text message
			if (data[i].hasOwnProperty("text")) {
			     addResponseMessage(data[i].text );
			}
			if (data[i].hasOwnProperty("buttons")) {
				 setQuickButtons([ { label: data[i].buttons[0].title, value: 'Yes' }, { label: 
                                        data[i].buttons[1].title, value: 'No' } ]);
                           }
			if (data[i].hasOwnProperty("image")) {
			    this.setState({todos: data[i].image})

			 }
		   }
	     }
	  }, 2000);
   })
   }

   handleQuickButtonClicked = (e) => {
       addResponseMessage('Selected ' + e);
       setQuickButtons([]);
   }
 render() {
   return (
     <div>
        <Widget
             title="Rasa Sample Bot"
             subtitle="Asistente virtual"
             senderPlaceHolder="Type here ..."
             handleNewUserMessage={this.handleNewUserMessage}
             handleQuickButtonClicked={this.handleQuickButtonClicked}
             badge={1}
             customComponent={(customData) => (<div><img src={todoss.image} /></div>) }
  />
  <h2> hi</h2>
  </div>
  </div>
  );
}

} `

Issue Analytics

  • State:open
  • Created 4 years ago
  • Reactions:3
  • Comments:6

github_iconTop GitHub Comments

3reactions
cosmeoescommented, Oct 8, 2019

Here’s how you would add an image at the beginning of the chat.

import React, { Component } from 'react';
import { Widget, renderCustomComponent } from 'react-chat-widget';
import './App.css';
import 'react-chat-widget/lib/styles.css';

//This is the image component, copy it to your project
class Image extends Component {
  render() {
    return <img alt="placeholder" src={this.props.src}></img>
  }
}
class App extends Component {
    componentDidMount() {
        let imageSrc = "https://wolper.com.au/wp-content/uploads/2017/10/image-placeholder.jpg"; //Place here your image location

        //Here I'm adding the component
        renderCustomComponent(Image, {src: imageSrc}) 
    }

    render() {
        return (
          <div className="App">
            <Widget />
          </div>
        );
      }
}

export default App;

In your code you probably want add it after the check for an image.

if (data[i].hasOwnProperty("image")) {
      let imageSrc = //get image location
      renderCustomComponent(Image, {src: imageSrc}) 
}

0reactions
arslanqadir69commented, Dec 20, 2022

how we can send images voice messages and videos through react-chat-widget

Read more comments on GitHub >

github_iconTop Results From Across the Web

Specify Chat Images | Embedded Service for Web Developer ...
Specify a URL to set the avatar image that appears when the customer is chatting with a bot. We recommend an image size...
Read more >
Web Chat customization in the Bot Framework SDK - Bot Service
The Web Chat control provides rich customization options: you can change colors, sizes, placement of elements, add custom elements, and interact ...
Read more >
Developing custom messages for react-chatbot-kit - YouTube
... we implement custom messages in the react- chatbot -kit package, allowing users to define a message type and map custom components to...
Read more >
Chat Lightning Web Component Pack – User Guide
Therefore, it is best to use the carousel component in a Question block if using a chatbot, to save the selected tile response...
Read more >
Web Chat samples - Microsoft Open Source
These samples are connected to MockBot, a bot for testing various features of Web Chat. The source code of MockBot can be found...
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