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

How to upload image into chatbot #37

Closed
arissaraZ opened this issue Mar 17, 2021 · 8 comments
Closed

How to upload image into chatbot #37

arissaraZ opened this issue Mar 17, 2021 · 8 comments

Comments

@arissaraZ
Copy link

Hi,

Is there any way to provide file custom component which select from the gallery?

Example of the custom component will be appreciated.

@FredrikOseberg
Copy link
Owner

FredrikOseberg commented Mar 17, 2021 via email

@arissaraZ
Copy link
Author

I mean How to add button for upload image into chat like Facebook Messenger.

@FredrikOseberg
Copy link
Owner

I mean How to add button for upload image into chat like Facebook Messenger.

If you want to render an image you can use widgets to that from the bot side. Do you have a use case where you want to upload an image as a user?

@arissaraZ
Copy link
Author

arissaraZ commented Mar 28, 2021

Use case: When user click on upload image button to select image, then selected image will show on text input (change from placeholder to selected image). And if user confirm image to submit to click on send button. So that image will show in user chat is it possible? and if possible. Can you show me an example? please.

Thanks

@FredrikOseberg
Copy link
Owner

Use case: When user click on upload image button to select image, then selected image will show on text input (change from placeholder to selected image). And if user confirm image to submit to click on send button. So that image will show in user chat is it possible? and if possible. Can you show me an example? please.

Thanks

Currently, this isn't possible. I'll look into building support for that. What you could do is to build an image widget that displays an image with a chatbot response, but you currently can't upload an image from the user side.

@FredrikOseberg
Copy link
Owner

Here's a way you can render an image before I improve support for this use case:

First create an image widget:

const ImageWidget = ({ src, alt }) => {
    return <img src={src} alt={`image of ${alt}`}  />
}

Then register it in the config:

const config = {
   state: {
     src: "", 
     alt: "",
   }
   widgets: [
      {
         widgetName: "imageWidget",
         widgetFunc: (props) => <ImageWidget {...props} />,
         mapStateToProps: ["src", "alt"]
      }
   ]
}

In your actionprovider:

const handleImage = (src, alt) => {
     const message = { type: "user", message: "Here's my image:", widget: "imageWidget", id: "some-unique-id" };

     this.setState(prev => ({ ...prev, messages: [...prev.messages, message], src, alt }))
}

That should help you render an image widget.

@arissaraZ
Copy link
Author

I really appreciate you, Thank you so much.

@arissaraZ
Copy link
Author

Sorry, I need help again. When use type: "user" followed your example, It's can't work but when use this.createChatBotMessag It's work. So Why doesn't work ? please help me for solution.

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

2 participants