Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Send message to a group of users in SignalR Service in Azure Functions

Looking at the docs for the SignalR bindings to send a message to a specified user you include the UserId property on the message as such -

[FunctionName("SendMessage")]
public static Task SendMessage(
    [HttpTrigger(AuthorizationLevel.Anonymous, "post")]object message, 
    [SignalR(HubName = "chat")]IAsyncCollector<SignalRMessage> signalRMessages)
{
    return signalRMessages.AddAsync(
        new SignalRMessage 
        {
            // the message will only be sent to these user IDs
            UserId = "userId1",
            Target = "newMessage", 
            Arguments = new [] { message } 
        });
}

This example is taken straight from the documentation, but the comment implies you message multiple userids, even though the property is a string and not an array.

How would you specify multiple users? (If for example, they are in a private chat channel together) Or is this mistake in the wording of the comment and you would need to send a message per user?

With other versions of SignalR I would put them in a group, but bindings for this do not exist for functions.

like image 571
Kirschstein Avatar asked Nov 05 '18 14:11

Kirschstein


1 Answers

Group operations were introduced in the latest release.

Now you can:

  • Send a message to a group using GroupName in SignalRMessage
  • Add/remove user in a group using IAsyncCollector<SignalRGroupAction> output
like image 133
myarotskaya Avatar answered Oct 24 '22 19:10

myarotskaya