Declined
Last Updated: 18 Apr 2024 10:35 by ADMIN
Christian
Created on: 11 Apr 2024 10:35
Category: Chat
Type: Bug Report
0
jquery Chat: post message does not allow async calls

I have a chat widget configured like this:


let chat = $(target).kendoChat({
			messages: {
        placeholder: ResourceManager.GetInstance().getResource("SR_TYPE_A_MESSAGE")
      },
      user: user, 
      post: async (m: kendo.ui.ChatPostEvent) => await this.post(m),
    }).data("kendoChat");

 

If the post handler tries to await a call to a web  service (to do some translation/tag substitution) then the message is posted to the chat and the results of the web call are ignored.

2 comments
ADMIN
Nikolay
Posted on: 18 Apr 2024 10:35

Hi Christian,

Just a follow-up to my last reply. 

What yo are trying to achieve, however, can be achieved by overriding the internal Chat logic:

  function resolveAfter2Seconds() {
    console.log("starting slow promise");
    return new Promise((resolve) => {
      setTimeout(() => {
        resolve("slow");
      }, 2000);
    });
  }
  
  async function someAsyncJob(message) {
  	await resolveAfter2Seconds();
    return message;
  }	
  	
  const originalPostMessage = kendo.ui.Chat.fn.postMessage;
  kendo.ui.Chat.fn.postMessage = async function(message) {
		const m = await someAsyncJob(message);
		originalPostMessage.call(this, m);
  }
  
$("#chat").kendoChat();

Dojo demo: https://dojo.telerik.com/ALAJeyEr/2

Regards,
Nikolay
Progress Telerik

Stay tuned by visiting our public roadmap and feedback portal pages! Or perhaps, if you are new to our Kendo family, check out our getting started resources
ADMIN
Nikolay
Posted on: 18 Apr 2024 10:28

Hi Christian,

The Chat post event is an event that triggers when a certain event happens within the component. In the current case it fires when a message is posted to the Chat and can be either through the message box or through an action button click.

https://docs.telerik.com/kendo-ui/api/javascript/ui/chat/events/post

The Kendo UI component events are used to execute custom logic or perform action when an event fires. The post Chat event is not a method that will process events and return a result.

That said, the post event cannot be async. It just captures certain actions and allow you to execute certain logic at that point.

I hope this clarifies the situation.

Regards,
Nikolay
Progress Telerik

Stay tuned by visiting our public roadmap and feedback portal pages! Or perhaps, if you are new to our Kendo family, check out our getting started resources