Server-to-server chat API?

u7pp
u7pp
edited March 8 in Photon Chat

Is there a way to send messages (e.g. "system messages") into chat rooms outside of the client SDK? I'd like to do this through my own server to prevent abuse etc.

Best Answer

  • JohnTube
    JohnTube ✭✭✭✭✭
    Answer ✓

    Hi @u7pp,

    Thank you for choosing Photon!

    No, there is no built-in way to do this.

    Here are the two ways you could use this:

    1. Run a chat client from the web (from within browser app or from backend web server with interface from web app). It could be JS SDK or any other SDK. The special chat client can subscribe to any channel and publish message there as 'admin/system', these 'control/meta/system' messages should be handled in a special way by the other regular clients.
    2. Make use of chat webhooks to inject messages (workaround during channel creation/load) or override chat messages (make use of returned Data property).

Answers

  • JohnTube
    JohnTube ✭✭✭✭✭
    Answer ✓

    Hi @u7pp,

    Thank you for choosing Photon!

    No, there is no built-in way to do this.

    Here are the two ways you could use this:

    1. Run a chat client from the web (from within browser app or from backend web server with interface from web app). It could be JS SDK or any other SDK. The special chat client can subscribe to any channel and publish message there as 'admin/system', these 'control/meta/system' messages should be handled in a special way by the other regular clients.
    2. Make use of chat webhooks to inject messages (workaround during channel creation/load) or override chat messages (make use of returned Data property).
  • Hi @JohnTube,

    Thanks for your response. I hope you'll consider adding this feature, as in our case, your 2 suggestions don't apply unfortunately.

    Our use case is that we have groups of players in our game that each have their own channel and when certain game events take place within the group (independently of chat messages), we want to be able to inject system messages like "Player X achieved Y!".

  • JohnTube
    JohnTube ✭✭✭✭✭

    Hi @u7pp,

    What I suggested before can help you achieve your goal.

    either clients could poll (to check for new events) from web backend via PublishMessage webhook (response make use of Data to override message and return event system message)

    or special web client(s) send(s) event system message to each group channel (either subscribe to all beforehand or subscribe and publish on demand).

    it's feasible.

    but of course you could also choose to do it from your own backend in a custom way independently from Photon Chat.

  • Thanks for the suggestions @JohnTube, but as I mentioned before, this doesn't really help us because we don't want to have clients poll (defeats the purpose of having a realtime/chat service) or rely on the PublishMessage webhook (which is strangely reliant on the client allowing this with the forwardAsWebhook parameter 🤯).

    We also cannot run a special web client because there's no SDK for our backend environment (python). Today we've run into an additional limitation, which is that there is no way to remove/kick a user from a channel through Photon.

    Once again, I hope you'll consider adding a server-to-server API for your service. Relying on the client apps to do the right thing just isn't feasible or secure enough for serious apps/games.