I have succesfully create a chat page using SignalR
now i would like to create a more professional chat
Like a help desk system
so when a user send a message in the chat it should give a notification to a (manager) page
and were only 1 person can enter the room
I have used the IHubContext service this is my simple code so far:
[Route("api")]
[ApiController]
public class ChatController : ControllerBase
{
private readonly IHubContext<ChatHub, IChatClient> _chathub;
public ChatController(IHubContext<ChatHub, IChatClient> chathub)
{
_chathub = chathub;
}
[HttpPost("messages")]
public async Task Post([FromBody]ChatMessage message)
{
string name = "jack";
await _chathub.Clients.All.ReceiveMessage(name, message.Message);
}
}
and from the front end:
receiving messages:
const Connection = new HubConnectionBuilder()
.withUrl('https://localhost:44370/hubs/chat')
.build();
try{
Connection.start().then(result => { console.log("connected")});
Connection.on("ReceiveMessage",(user, message) => {
const li = document.createElement("li");
li.textContent = `${user}: ${message}`;
document.getElementById("messagelist").appendChild(li);})
}
catch(err){
console.log("something went wrong while connection: ", err)
}
sending messages:
try {
await fetch('https://localhost:44370/api/messages',{
method: 'POST',
body: JSON.stringify({
message: newmessage
}),
headers: {'Content-Type': 'application/json'}
}).catch((error) => {
console.error('Error:', error);
});
I have tried to look into the microsoft documents on how to achive what i want but
its not very clear on how to achive this through the IHubContext service
hopefully someone can help me out to better understand to achive what i want

