Need help on Playfab webhook

Options
I'm currently trying to make shared group on playfab whenever client is creating room.

First I check if the webhook is working by typing this code on playfab cloud script and it's working fine.
// Triggered automatically when a Photon room is first created
handlers.RoomCreated = function (args) {
    server.WriteTitleEvent({
        EventName : "room_created"+args.Type
    });
};

Then I add the script from memory demo to the cloud script and the result is that the room is never created. I checked on playstream monitor that after room is created, it will left the room immediately.
handlers.RoomCreated = function (args) {
    server.WriteTitleEvent({
        EventName : "room_created"+args.Type
    });
    
    
    'use strict';
    try {
        var timestamp = getISOTimestamp(),
            data = {};
        checkWebhookArgs(args, timestamp);
        if (args.Type === 'Create') {
            onGameCreated(args, timestamp);
            return {ResultCode: 0, Message: 'OK'};
        } else if (args.Type === 'Load') {
            data = getSharedGroupEntry(getGamesListId(currentPlayerId), args.GameId);
            if (data.Creation.UserId !== currentPlayerId) {
                data = getSharedGroupEntry(getGamesListId(data.Creation.UserId), args.GameId);
            }
            if (undefinedOrNull(data.State)) {
                if (args.CreateIfNotExists === false) {
                    throw new PhotonException(5, 'Room=' + args.GameId + ' not found', timestamp, args);
                } else {
                    onGameCreated(args, timestamp);
                    return {ResultCode: 0, Message: 'OK', State: ''}; // TBD: test if State property is required or what can be returned
                }
            }
            if (undefinedOrNull(data.LoadEvents)) {
                data.LoadEvents = {};
            }
            data.LoadEvents[timestamp] = {ActorNr: args.ActorNr, UserId: args.UserId};
            createSharedGroup(args.GameId);
            updateSharedGroupData(args.GameId, data);
            return {ResultCode: 0, Message: 'OK', State: data.State};
        } else {
            throw new PhotonException(2, 'Wrong PathCreate Type=' + args.Type, timestamp, {Webhook: args});
        }
    } catch (e) {
        if (e instanceof PhotonException) {
            return {ResultCode: e.ResultCode, Message: e.Message};
        }
        return {ResultCode: 255, Message: e.name + ': ' + e.message};
    }
};

function onGameCreated(args, timestamp) {
    'use strict';
    var data = {};
    createSharedGroup(args.GameId);
    data.Env = {Region: args.Region, AppVersion: args.AppVersion, AppId: args.AppId, TitleId: script.titleId,
                CloudScriptVersion: script.version, CloudScriptRevision: script.revision, PlayFabServerVersion: server.version,
               WebhooksVersion: undefinedOrNull(args.Nickname) ? '1.0' : '1.2'};
    data.RoomOptions = args.CreateOptions;
    data.Creation = {Timestamp: timestamp, UserId: args.UserId, Type: args.Type};
    data.Actors = {1: {UserId: args.UserId, Inactive: false}};
    data.NextActorNr = 2;
    updateSharedGroupData(args.GameId, data);
    updateSharedGroupEntry(getGamesListId(currentPlayerId), args.GameId, data);
}

Comments

  • JohnTube
    JohnTube ✭✭✭✭✭
    edited December 2020
    Options
    Hi @gr4ntz,

    As stated in the readme of the repo (I made), it's not officially supported by Photon nor PlayFab.
    Also, it was not meant to be used as is.
    Forget about that repository and start making CloudScript code on your own bit by bit.
  • gr4ntz
    Options
    Thanks for the clarifications John. Are there any good example that I can learn from?