To handle messages that are sent by the user, we will create a new function, as follows:
- Create a function with an HttpTrigger and with anonymous access rights.
- Name the function Messages.
- Add a collection of SignalRMessages.
- Use the SignalR attribute to specify the hub name. Refer to the following code snippet:
[FunctionName("Messages")]
public async static Task SendMessages(
[HttpTrigger(AuthorizationLevel.Anonymous, "post")] object
message,
[SignalR(HubName = "chat")] IAsyncCollector<SignalRMessage>
signalRMessages)
{
The message parameter will be the message that the user sent. It will be of the JObject type (from Newtonsoft.Json). We need to convert it to the Message type that we created earlier. To do that, we need to add a reference to the Chat.Messages project. However, because the parameter is of an object type, we first need to cast it to JObject...