How to target specific player when calling cloud code module with API to send Push Message

I want to add player economy and send message with pushclient to the player when a player interact with my website. But in the API doc for calling cloud code module there isn’t a way to inject IExecutionContext to the cloud code .
Another way I can think of is calling economy and push message directly via API but I cannot find Web API for the push message (not push notification). Is there any way to achieve this behaviour?

Thanks in advance!

    [CloudCodeFunction("AddRewardFromExt")]
    public async Task AddRewardFromExt(IExecutionContext ctx, long amount)
    {
        try
        {
            CurrencyModifyBalanceRequest balreq = new CurrencyModifyBalanceRequest("GOLD", amount);
            await _gameApiClient.EconomyCurrencies.IncrementPlayerCurrencyBalanceAsync(ctx, ctx.ServiceToken, ctx.ProjectId, ctx.PlayerId, "GOLD", balreq);
            var res = await _pushClient.SendPlayerMessageAsync(ctx, $"Reward#{amount}", "Reward", ctx.PlayerId);
        }
        catch (Exception ex)
        {
            _logger.LogError($"Failed to AddRewardFromExt. Error: {ex}", ex.Message);
        }
    }

Hi @saranw71

Would you be able to elaborate on this part a bit more? The context is automatically populated by the Cloud Code service based on the request values so you shouldn’t need to inject anything?

I’ll link the documentation just in case you haven’t already seen it Send push messages - but you’ve specifically mentioned using a website. Are you running a Unity WebGL build? Or do you wish to send a request to the Cloud Code API from your website?

@samg-unity

I’m looking to externally (like when player interact with my website) do economy change and push message. Either:

  1. Something like this but for push message, that way I can do both with API call

https://services.docs.unity.com/economy/v2/#tag/Currencies/operation/setPlayerCurrencyBalance

or

  1. A way to call Cloud Code Module given in OP and provide IExecutionContext for the pushclient.SendPlayerMessageAsync
    I don’t see where I can target a specific player Unity Services Web API docs

What I expect: a player press a button on my website, currency is increased and push message sent to the client.

Thanks in advance