Sending messages from other services
So far, we have implemented a chat app that allows users to send messages to other users or groups. Sometimes, we need to send messages from other places. For example, when an event occurs, we may need to send a message to notify the users. In this section, we will explore how to send messages from other services. You can find the complete code of the sample in the chapter13/v4
folder of the GitHub repository.
We will add a REST API endpoint to allow other systems to send messages to the SignalR hub. Follow these steps to add a REST API endpoint in the ChatApp.Server
application:
- Create the following models in the
Models
folder:public class SendToAllMessageModel{ public string FromUser { get; set; } = string.Empty; public string Message { get; set; } = string.Empty;}public class SendToUserMessageModel{ public string FromUser { get; set; } = string.Empty; ...