Cannot get Azure function WebPubSubTrigger to fire with custom events

Longtooth 6 Reputation points
2022-11-10T15:23:23.603+00:00

I have been trying to get a simple function for fire for 3 days now. I am using WebPubSub for messaging in my game (Unity). I can connect using the json.webpubsub.azure.v1 protocol and WebSocketSharp. I can join/leave group and send messages to groups no problems directly from the client using the protocol. I can also use timer triggers and they are fine, But when I try to send a custom event, I get back {"type":"ack","ackId":1,"success":false,"error":{"name":"InternalServerError","message":"Internal server error"}}. I don't see any feedback in the logstream, so I'm kinda lost. Any help would be much appreciated.

Here is how I'm setting up the handlers (per the many examples), I've also tried setting the handler to just one specific event:

https://functionsapp.azurewebsites.net/runtime/webhooks/webpubsub?code=*****************************

Here is the send normal message code that works fine:

        public void SendMessageToGroup(string groupToMessage, string messageToSend)  
        {  
            if (groupToMessage == null) return;  
  
            string message = JsonConvert.SerializeObject(new  
            {  
                type = AzurePubSubKeys.SendToGroup,  
                group = groupToMessage,  
                ackId = ++this.ackId,  
                dataType = AzurePubSubKeys.DataText,  
                data = messageToSend + System.Environment.NewLine  
            });  
  
            webSocket.SendAsync(message, isSuccess => { Debug.Log($"[{GetType().Name}] Message Send Success: {isSuccess}"); });  
        }  

Here is the code that gets the error:

            string message = JsonConvert.SerializeObject(new  
            {  
                type = "event",  
                @event = "testtrigger",  
                ackId = ++this.ackId,  
                dataType = AzurePubSubKeys.DataText,  
                data = "this is data for the testtrigger event handler"  
            });  
  
            webSocket.SendAsync(message, isSuccess => { Debug.Log($"[{GetType().Name}] testtrigger Send Success: {isSuccess}"); });  

Here are the functions I've been trying to get working:

        [FunctionName("WebPubSubTriggerFunction")]  
        public static void Run(  
            ILogger logger,  
            [WebPubSubTrigger("hub", WebPubSubEventType.User, "testtrigger")] UserEventRequest request,  
            string data,  
            WebPubSubDataType dataType)  
        {  
            logger.LogInformation($"Request from: {request.ConnectionContext.UserId}, data: {data}, dataType: {dataType}");  
        }  
  
  
        [FunctionName("TestEventHandler")]  
        public static void TestEventHandler(  
            [WebPubSubTrigger(AzurePubSubNames.DefaultHub, WebPubSubEventType.User, "testevent")] WebPubSubConnectionContext context,  
            string data,  
            ILogger log)  
        {  
            log.LogDebug($"[TestEventHandler] *********************** start ***********************\n{context.UserId}\n{data}");  
        }  
Azure Web PubSub
Azure Web PubSub
An Azure service that provides real-time messaging for web applications using WebSockets and the publish-subscribe pattern.
98 questions
Azure Functions
Azure Functions
An Azure service that provides an event-driven serverless compute platform.
5,925 questions
0 comments No comments
{count} votes

1 answer

Sort by: Most helpful
  1. Longtooth 6 Reputation points
    2022-11-11T15:12:56.28+00:00

    Solved: for some reason, one of my accounts wasn't logged in properly to visual studio. So publishing still occurred, but something wasn't updating properly. Relogging the account fixed everything.

    1 person found this answer helpful.

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.