Just follow the instrction here (https://docs.microsoft.com/en-us/gaming/playfab/features/automation/cloudscript-af/quickstart#playfab-cloudscript-context-variables-and-server-sdks-), try the HelloWorld sample it works fine in Players / Cloud Script / Run Cloud Script. But it fails with player_statistic_changed rule.
Azure Functions triggered by a Rule uses the PlayerPlayStreamFunctionExecutionContext context model, which is different from the one (FunctionExecutionContext) used in the link you mentioned in question. For instance, here is sample script showing how to handle calls triggered by a Rule:
[FunctionName("ReturnPlayerProfile")] public static async Task<PlayerProfileModel> Run( [HttpTrigger(AuthorizationLevel.Function, "post", Route = null)] PlayerPlayStreamFunctionExecutionContext req, HttpRequest httpRequest, ILogger log) { string body = await httpRequest.ReadAsStringAsync(); log.LogInformation($"HTTP POST Body: {body}"); if (req.PlayStreamEventEnvelope != null) { log.LogInformation($"eventEnvelope: {JsonConvert.SerializeObject(req.PlayStreamEventEnvelope)}"); } else { log.LogInformation("PlayStreamEventEnvelope was null"); } if (req.PlayerProfile != null) { log.LogInformation($"playerProfile: {JsonConvert.SerializeObject(req.PlayerProfile)}"); } else { log.LogInformation("PlayerProfile was null"); } return await Task.FromResult(req.PlayerProfile); } }
This is not clear at all in the context documentation. I spent 30 minutes trying to find out how to get the playerId from a rule, until I stumbled upon this forum post.
4 People are following this question.