deep-chat icon indicating copy to clipboard operation
deep-chat copied to clipboard

Advice needed for submitUserMessage

Open ki-zeitalter opened this issue 1 year ago • 0 comments

Hi DeepChatTeam!

I'm struggling to get submitUserMessage to work. Basically it doesn't seem to do anything at all and I'm not sure why.

So I made a very simple example to show what I'm doing:

import {DeepChat as DeepChatCore} from 'deep-chat';
import {DeepChat} from 'deep-chat-react';
import {useEffect, useRef, useState} from "react";
import './style.css';

export const App = () => {
  const [buttonmsg, setButtonmsg] = useState("")

  const deepChatRef: React.RefObject<DeepChatCore> = useRef(null);

  useEffect(() => {
    if (deepChatRef && buttonmsg != "") {
      deepChatRef.current.submitUserMessage({text: buttonmsg})
    }
  }, [buttonmsg])

  return (
    <div className="App">
      <h1>Deep Chat</h1>
      <DeepChat
        ref={deepChatRef}
        demo={true}
        style={{ borderRadius: '10px' }}
        textInput={{ placeholder: { text: 'Welcome to the demo!' } }} 
      />

      <button onClick={() => setButtonmsg("Hi this is a message submitted by a button!")}>Click me!</button>
    </div>
  );
};

In my real world code the message even seems to be sent to the back-end but the response is not shown at all. In my simple example it is not visible as well.

Maybe I'm doing something horribly wrong so I would be glad if you could give me an advice!

Thanks!

ki-zeitalter avatar Aug 08 '24 14:08 ki-zeitalter