question

Takuya Nakajo avatar image
Takuya Nakajo asked

How to use FunctionPlayerPlayStreamContext

Hello.

I'm trying to make a call to an Azure Function using the 'actions-rules' functionality.

[FunctionName("SendPushNotification")]
public static async Task<dynamic> SendPushNotification(
              [HttpTrigger(AuthorizationLevel.Anonymous, "get", "post", Route = null)] HttpRequestMessage req, ILogger log)
{
    var context = await FunctionPlayerPlayStreamContext<dynamic>.Create(req);
    return new { result = "Success!!" };
} 

However, I am getting the following error in FunctionPlayerPlayStreamContext.

Invalid cast from 'System.String' to 'System.Nullable`1[[PlayFab.ServerModels.LoginIdentityProvider, PlayFabAllSDK, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null]]'.

How can I resolve this error?

Thanks.

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

·
Hernando avatar image
Hernando answered

What is FunctionPlayerPlayStreamContext? Did you means PlayerPlayStreamFunctionExecutionContext class? This context in which your script is run determines the available data model and provides context specific data that is used in your script. Following code shows how to obtain the information from PlayerPlayStreamFunctionExecutionContext:

[FunctionName("SendPushNotification")]  public static async Task<object>
SendPushNotification( 
	[HttpTrigger(AuthorizationLevel.Function, "post", Route =
null)] HttpRequest httpRequest,  

	ILogger log)  

{  

	string body = await
	httpRequest.ReadAsStringAsync(); 
	PlayerPlayStreamFunctionExecutionContext<object[]> req =
	JsonConvert.DeserializeObject<PlayerPlayStreamFunctionExecutionContext<object[]>>(body);  

return await Task.FromResult(req.FunctionArgument);  

}
3 comments
10 |1200

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

Takuya Nakajo avatar image Takuya Nakajo commented ·

Thank you for answering.

I have two additional questions.

1. About FunctionPlayerPlayStreamContext

I referred to Handlers.cs, can I no longer use FunctionPlayerPlayStreamContext?

2. About PlayFabServerInstanceAPI

Is it possible to generate PlayFabServerInstanceAPI from PlayerPlayStreamFunctionExecutionContext?

Normally it is generated as follows, but in this case, I do not know what to do.


var context = await FunctionContext<dynamic>.Create(req);
var serverApi = new PlayFabServerInstanceAPI(context.ApiSettings, context.AuthenticationContext);

Thanks.

0 Likes 0 ·
Hernando avatar image Hernando Takuya Nakajo commented ·
  1. No, this script does not declare the FunctionPlayerPlayStreamContext class.
  2. To generate PlayFabServerInstanceAPI from PlayerPlayStreamFunctionExecutionContext, you can try the following code in C# SDK:
  var apiSettings = new PlayFabApiSettings 
{
TitleId = context.TitleAuthenticationContext.Id,
DeveloperSecretKey = Environment.GetEnvironmentVariable("PLAYFAB_DEV_SECRET_KEY",EnvironmentVariableTarget.Process),
};
var serverApi = new PlayFabServerInstanceAPI(apiSettings);

As you've set title Id and dev key in Azure portal, you should be able to get dev key with "GetEnvironmentVariable" method, but you may need to change the key to match your setting.

0 Likes 0 ·
Takuya Nakajo avatar image Takuya Nakajo Hernando commented ·

It was very helpful! Thank you!

0 Likes 0 ·

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.