question

vbalakrishnatimuz avatar image
vbalakrishnatimuz asked

Playfab Photon Webhooks return value

Hello,

Is there any way to get function returned values from cloud methods like RoomCreated() or JoinedRoom() webhooks.

Example :

handlers.RoomCreated = function(args){

var roomID = args.GameId; //An identifier for the Photon Cloud Room which generated the event.

return{coins : 200}; //How to get this value in any Client Photon Callbacks like OnJoined or OnConnected.

}

CloudScriptphoton
10 |1200

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

brendan avatar image
brendan answered

The Cloud Script you run in our service gets the parameters from a webhook call from Photon as described in our docs, which also described the best practice for using the ResultCode to indicate success or failure, but for info on the Photon side of the logic (getting anything returned from the Cloud Script call back to the client), you'll need to speak with the Exit Games team directly, as they own and manage that service. @Hamza Lazaar may be able to provide more insight.

10 |1200

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

vbalakrishnatimuz avatar image
vbalakrishnatimuz answered

Hi Hamza,

In Cloud webhook On RoomCreated.,We are returning value like below

return { 'ResultCode' : 0, 'Message' : 'BalutM OK' };

How to get this Message in Client side.?


In Photon client we got below.

OperationResponse 227: ReturnCode: 0.
UnityEngine.Debug:Log(Object)
NetworkingPeer:OnOperationResponse(OperationResponse) (at Assets/Photon Unity Networking/Plugins/PhotonNetwork/NetworkingPeer.cs:1556)

On

OperationResponse operationResponse

operationResponse.Parameters type is a Dictionary<byte ,object>.

When I debug I got below data.

=248 value==(System.Byte)250=(System.String[])System.String[], (System.Byte)249=(System.Boolean)True, (System.Byte)248=(System.Int32)1, (System.Byte)255=(System.Byte)2, (System.Byte)254=(System.Boolean)True, (System.Byte)253=(System.Boolean)True

Thank you.

Brendan and @Hamza Lazaar.

10 |1200

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

Hamza Lazaar avatar image
Hamza Lazaar answered

Hi @vbalakrishnatimuz,

Short answer: The Message will be returned to client only in case of error.

Long answer:

Some users (including me) and maybe that's your use case as well, want to use it as a way of returning data to client. Which can be "ugly".

The Message is returned to client only when the ResultCode is different than 0 ("error").

Currently only one case of ResultCode != 0 may result in cancelling a Photon operation, which is loading a room state in this case ReturnCode will be an error code PluginReportedError and DebugMessage will contain a string that includes your returned Message and the URL and extra stuff. Otherwise all Photon operations will succeed no matter what. However, if "HasErrorInfo" is enabled (set to true, which is not the case for apps configured by PlayFab), an ErrorInfo event will be broadcast with the Message inside embedded in another string as well.

So in both cases you need to parse the returned message yourself and we can't promise it won't change.

We're trying to come up with a better design and improve this in the future. But it's not a priority and I have no ETA.

10 |1200

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

vbalakrishnatimuz avatar image
vbalakrishnatimuz answered

As document says,

A very good way to handle return values is by implementing helper routines in the backends logic for your webhooks. The following is just a non-exhaustive list of examples of webhooks return objects.

  • Default return object for success

    { 'ResultCode' : 0 }
    { 'ResultCode' : 0, 'Message' : 'OK' }

  • We cannot use Message key for value..?
  • Thank You.
1 comment
10 |1200

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

Hamza Lazaar avatar image Hamza Lazaar commented ·

I apologize about the delay, I missed this.

You can set Message key value or even add other ones.

They will not be useful when ResultCode = 0 and will not be sent back to client.

The use case you described in the original post is only possible using Photon Plugins. For the time being, Photon Webhooks does not give you the option to modify room state or to return data to client.

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.