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

Custom properties inside the response?

Open cpperey opened this issue 8 months ago • 7 comments

As the title says, is it possible to add an attribute to the message object that deepchat.dev tracks? For example, I wanted to track how long it took for the response to get back.

message would then be:

{ text: "hello", duration: 0.20s }

When I try to add this within the onResponseInterceptor, when I pull the messages again, it doesn't show in the object.

cpperey avatar Mar 12 '25 16:03 cpperey

Hi @cpperey.

You should be able to see your own custom properties inside the responseInterceptor. May I see the code that you are using to configure Deep Chat?

Thankyou!

OvidijusParsiunas avatar Mar 13 '25 14:03 OvidijusParsiunas

Also, the latest version for deep-chat-dev and deep-chat-react-dev of 9.0.241 contains a new Response property called custom which accepts any value. However it must be returned with one of the other content properties such as text.

E.g. {text: 'My response', custom: 'any value'}

This is not necessary to see values using the responseInterceptor and its main purpose is to be able to see custom values after calling getMessages method.

OvidijusParsiunas avatar Mar 13 '25 14:03 OvidijusParsiunas

Hi @cpperey.

You should be able to see your own custom properties inside the responseInterceptor. May I see the code that you are using to configure Deep Chat?

Thankyou!

Yes, I do see them at responseInterceptor. At the moment, what I've done is I created a chatMapping array where I match the items returned in getMessages(). For some context, what I was trying to do is have a feedback button. So when someone clicks on thumbs up or thumbs down, I could get the object with custom attributes (i.e. duration, transactionId, etc.) so I can store the information with the feedback.

Also, the latest version for deep-chat-dev and deep-chat-react-dev of 9.0.241 contains a new Response property called custom which accepts any value. However it must be returned with one of the other content properties such as text.

E.g. {text: 'My response, custom: 'any value'}`

This is not necessary to see values using the responseInterceptor and its main purpose is to be able to see custom values after calling getMessages method.

I think this is what I need. When do you think this goes out to release version and would that be supported on VueJS framework too?

cpperey avatar Mar 13 '25 16:03 cpperey

Hey. You can use this functionality in the dev packages mentioned above. They work exactly the same as the normal ones except their names are just different.

We hope to make the next core version release at the end of this month, however due to a number of spotted bugs, it may be at the start of the next month. Nevertheless, I will keep this issue open and close it when the code is released.

Thankyou!

OvidijusParsiunas avatar Mar 13 '25 16:03 OvidijusParsiunas

@OvidijusParsiunas Thank You!

cpperey avatar Mar 13 '25 20:03 cpperey

Is this feature live yet? I couldn't get it to work on the latest release and on the dev release. Are there any plans on adding a custom property on stream events? I couldn't find any indication here for the custom property, however I might be looking in the wrong place.

asafn-jfrog avatar Apr 27 '25 13:04 asafn-jfrog

Hi @asafn-jfrog. The dev version 9.0.256 supported the custom property for the regular messages that were not streamed. I have made a small update that now allows the custom property to be used in streamed messages. A point to note is that the last streamed event's custom property will be retained when observing the existing messages via the getMessages method. This is now available in deep-chat-dev and deep-chat-react-dev version 9.0.257.

I am currently working on the documentation for the next release of the official packages which will include this feature. This should happen quite soon, please stay tuned!

OvidijusParsiunas avatar Apr 27 '25 16:04 OvidijusParsiunas

This is now available in deep-chat and deep-chat-react version 2.2.0. See Message Content for more information.

OvidijusParsiunas avatar May 08 '25 13:05 OvidijusParsiunas

Hi @OvidijusParsiunas 👋

Could you please share a sample code snippet showing how we can access the custom properties (like topic, context, and cat_id) when clicking on an HTML button?

Our backend response looks like this:

{
  "html": "<div class='deep-chat-temporary-message'> \
<button class='deep-chat-button deep-chat-suggestion-button' \
data-topic='What do shrimps eat topic' \
data-context='What do shrimps eat context.' \
data-cat_id='shrims-2'> \
What do shrimps eat ? \
</button></div>",

  "custom": {
    "text": "What do shrimps eat ?",
    "topic": "What do shrimps eat topic ?",
    "context": "What do shrimps eat context ?",
    "cat_id": "shrims-2"
  }
}

We use this method to handle the chat connection:

setupChatConnection(chat) {
  chat.connect = {
    stream: true,
    handler: async (body, signals) => {
      console.debug("DeepChatHandler ~ handler: ~ body:", body);
    }
  };
}

However, the body we see to console only contains the role and text of the clicked button:

[
  {
    "role": "user",
    "text": "What do shrimps eat 2?"
  }
]

djsakisd avatar May 12 '25 15:05 djsakisd

@djsakisd your comment is displaying a response, but you are logging what is passed by the handler. It doesn't seem to make sense. I think you are missing something in your comment. Also, I would appreciate if you could format your code correctly as it is difficult to read. Thanks.

OvidijusParsiunas avatar May 12 '25 15:05 OvidijusParsiunas

Hi @OvidijusParsiunas and thanks for your quick reply !

I’ve updated my previous reply for clarity.

The core issue is that while the custom parameters are correctly passed from the backend, I’m unable to send those custom values back to the backend when a button is clicked.

Here’s what I’m trying to achieve:

Dynamically render multiple buttons (e.g., labeled "Assist me with X", "Assist me with Y", etc.) as part of a streaming response.

When a user clicks on one of these buttons, send the associated custom properties (originally provided as a JSON array from the backend) back to the backend.

Any guidance on how to capture and return these custom attributes on click would be greatly appreciated!

djsakisd avatar May 12 '25 15:05 djsakisd

Hi @djsakisd. I suspect you are using the submitUserMessage method which does not support the custom property as per the documentation. If that is the case, I have updated the deep-chat-dev and deep-chat-react-dev packages version 9.0.264 to include this property. Let me know if it helps. Thanks!

OvidijusParsiunas avatar May 13 '25 13:05 OvidijusParsiunas

@OvidijusParsiunas sorry for the late reply, i can verify that it works now , thanks !

djsakisd avatar Jun 13 '25 12:06 djsakisd