I'm writing an application which uses Azure SignalR in serverless mode, since I need to transmit messages from Azure Functions.
To that end, I'm using the Microsoft.Azure.SignalR.Management
library to access a hub context so I can send messages. That part is working so far, both when the call is made from Azure Functions, or from a RESTful api call.
I would like to be able to add a specific user
to a group
. The user I can identify using a userId
public async Task<ActionResult> AddToGroup([FromBody]GroupAddRequest request)
{
//This crashes - since it expects a connection id instead of a user Id
await this.messageHubContext.Groups.AddToGroupAsync(request.UserId, request.GroupId);
await this.messageHubContext.Clients.User(request.UserId).SendAsync("group", request.GroupId);
//I can send a message to a specific user ^
return new JsonResult("Done");
}
I can send messages a user identified from the userId - but I can't add that user to a group since it's expecting a connectionId
instead. So how can I get the connection of that specific user, or alternatively - how can I add a User
to a Group
. I can't use "Context" since this isn't within a hub.