question

Gorazd avatar image
Gorazd asked

NodeJS Azure Function not receiving Playfab

I'm using NodeJS/typescript to create a CloudScript Azure Function called onPlayerRegister to set up some initial player inventory when a player creates a new account. I've set up the automation Rule, so the played_added_title event triggers my Azure Function. The function triggers correctly, but I can't figure out how to identify this player on whose behalf the CloudScript function was run.

This is my function, gets triggered by player_added_title:

 import {
   app,
   HttpRequest,
   HttpResponseInit,
   InvocationContext,
 } from "@azure/functions";
    
 export async function onPlayerRegister(
   request: HttpRequest,
   context: InvocationContext
 ): Promise<HttpResponseInit> {
   context.log(context);
   context.log(request);
    
   return { body: `Hello!` };
 }
    
 app.http("onPlayerRegister", {
   methods: ["GET", "POST"],
   authLevel: "anonymous",
   handler: onPlayerRegister,
 });

These are the request and context parameter values I'm logging in Azure. I can't see any Playfab-related data here. What am I missing?

 InvocationContext { 
   invocationId: 'f8375571-8345-4b51-824f-f740ef9efa7f',
   functionName: 'onPlayerRegister', 
   extraInputs: InvocationContextExtraInputs {}, 
   extraOutputs: InvocationContextExtraOutputs {}, 
   retryContext: undefined, 
   traceContext: { 
     traceParent: '00-3cc8c5fcb8b32b8e05ee60c2f96b0408-cc460fb1c10baf52-00', 
     traceState: '', 
     attributes: {} 
   }, 
   triggerMetadata: undefined, 
   options: { 
     trigger: { 
       methods: [Array], 
       authLevel: 'anonymous', 
       type: 'httpTrigger', 
       name: 'httpTrigger2', 
       direction: 'in' 
     }, 
     return: { 
       type: 'http', 
       name: '$return', 
       direction: 'out' 
     },
     extraInputs: [], 
     extraOutputs: [] 
   } 
 }

 HttpRequest {
   query: URLSearchParams {},
   params: {}
 }

How do I identify a player in my NodeJS Azure Function triggered by a 'player_added_title' PlayStream event?

CloudScriptPlayStream
10 |1200

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

1 Answer

·
Neils Shi avatar image
Neils Shi answered

PlayFab executes cloud scripts through several mechanisms, and different mechanisms require different contexts. In your case, you use the played_added_title event to trigger the Azure Function in Rules, so, you can identify the player (obtain player’s MasterPlayerAccountId) via PlayerPlayStreamFunctionExecutionContext. Please note that all context info is contained in the req, like c# example : “var context=JsonConvert.DeserializeObject(await req.ReadAsStringAsync());” And currently we only provide the C# CloudScript context models. So, if you need TypeScript ones, you need to build them by yourself as per CloudScript using Azure Functions helper class.

10 |1200

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

Write an Answer

Hint: Notify or tag a user in this post by typing @username.

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.