I want to show the response coming from WebSocket server to emulator that is Microsoft Bot Builder but I am having a issue that inside ws.addEventListener. Here is the code
ws.addEventListener('message',async function (event) {
const msg = JSON.parse(event.data);
if(msg.topic === 'aws/chat' && msg.contentType === 'application/json'){
const content = JSON.parse(msg.content);
switch(content.Type){
case 'MESSAGE':
try{
if(content.ParticipantRole !== 'CUSTOMER'){
responseMessage = `${content.DisplayName} : ${content.Content}`;
console.log(`responseMessage :- ${responseMessage}`);
await turnContext.sendActivity(responseMessage);
}
}catch(error){
console.log("Insise Error");
console.log(error);
}
break;
case 'Event':
if(content.ContentType.includes('ended')){
responseMessage = `Chat ended`;
}
}
}
});
When I debugged await turnContext.sendActivity(responseMessage) is loosing scope inside the listener function and not able to return the response to the emulator.
From WS server receiving response and getting printed in console with error.
responseMessage :- BOT : To speak to an agent, press or say # Insise Error TypeError: Cannot perform 'get' on a proxy that has been revoked at WebSocket. (D:\azure-bot\echo-bot\bots\stateManagementBot.js:155:59)