OvidijusParsiunas / deep-chat

Fully customizable AI chatbot component for your website
https://deepchat.dev
MIT License
1.26k stars 170 forks source link

Send the request without showing it #163

Closed littlepenguin89106 closed 2 months ago

littlepenguin89106 commented 2 months ago

When I use submitUserMessage, the request is shown on the chat. How do I only show the response?

OvidijusParsiunas commented 2 months ago

Hi @littlepenguin89106. Please see the following issue where this question was already answered: https://github.com/OvidijusParsiunas/deep-chat/issues/143

Thanks!

littlepenguin89106 commented 2 months ago

I think its behaviour is different, because it doesn't trigger the onNewMessage event.

OvidijusParsiunas commented 2 months ago

The onNewMessage has no relevance to how the messages are displayed. You need to use the messageStyles property to set the styling as described in this comment.

If your question is different, please elaborate. Thankyou.

littlepenguin89106 commented 2 months ago

Thanks for replies, I try to implement two requirements:

  1. click the button1, send the request, user request and ai reply are all displayed
  2. click the button2, send the request, only the ai reply is displayed
OvidijusParsiunas commented 2 months ago

Deep Chat does not provide the ability to have dynamic properties, so messageStyles can't be changed depending on the button that you clicked.

The only advice I can offer here is instead of using submitUserMessage for button2 - you should try to use the _addMessage method. This is a method that is not part of our official documentation and will be added to the main API on our next release, however it is still available in the current release. The way it works is it accepts a Response object as an argument and adds a message to the chat. E.g. deepChatRef._addMessage({text: 'hello'});.

The way you can use this in your use-case is you can process the request yourself on button2 click and then add the result to the chat via _addMessage. Hopefully this helps you.

littlepenguin89106 commented 2 months ago

Got it! Thank you for the timely support.