question

heath avatar image
heath asked

From where does a CouldScript handler's context.playStreamEvent data originate?

This should probably be two questions, but:

My code sends a custom event via Client.WritePlayerEvent().

This event has a Rule attached to trigger a CloudScript hander.

I am unsure of what the data is in the handler's context.playStreamEvent is, exactly, and where it comes from.

So question 1:

Is context.playStreamEvent the exact object that is returned from the Client.WritePlayerEvent()?

That is, the exact JSON Dict I see in PlayStream Event History?

That object appears to be mirrored in the "TriggeringEventData" key of the resulting CloudScript execution, also as seen in the PlayStream Event History, but missing the "CustomTags" and "Reserved" keys.

Question 2:

To what Playstreameventmodel does a custom event conform to?

There are many models defined, but I could not find documentation for a "custom" or "generic" case.

Example usage (Unity API):

 PlayFab.PlayFabClientAPI.WritePlayerEvent(WriteClientPlayerEventRequest)

The PlayStreamData look like:

{
    "EventName": "My_Event_That_Triggers_A_Rule",
    "EventNamespace": "title.0000",
    "Source": "0000",
    "EntityType": "player",
    "TitleId": "0000",
    "EventId": "goghohgds8hrgsf5",
    "EntityId": "dsljhds89gsdhogsd",
    "SourceType": "GameClient",
    "Timestamp": "2017-09-14T18:55:17.5004227Z",
    "History": [],
    "CustomTags": null,
    "Reserved": null,
    "body_key_0": "body_value_0",
    "body_key_1": "body_value_1",
    "body_key_2": "body_value_2",
    "body_key_3": "body_value_3",
    "body_key_4": "body_value_4",

}

In the CloudScript handler's context.playStreamEvent, where do I find this data?

For instance, would

context.playStreamEvent.EventName = "My_Event_That_Triggers_A_Rule"?

and

context.playStreamEvent.body_key_4 = "body_value_4"?

many thanks,

-heathcarlisle

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

·
brendan avatar image
brendan answered

Correct - it's the event that triggered the Action. I'd recommend reviewing this tutorial, which goes into more detail on this topic: https://api.playfab.com/docs/tutorials/landing-automation/using-cloud-script-actions-with-playstream. The examples you have above, both for the PlayStream data and the playStreamEvent data, are correct.

2 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.

heath avatar image heath commented ·

So then, a "custom" Playstreameventmodel would contain only the "Common" properties, plus those of the WriteClientPlayerEventRequest body?

0 Likes 0 ·
brendan avatar image brendan heath commented ·

Correct - common, plus whatever keys you send in the event.

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.