Sign In Register

How can we help you today?

Start a new topic

Best way how to add custom data to TeamChatMessage

Hi, I am just thinking of the best approach to add custom data to TeamChatMessage. The reason is that I need more data to be exposed about the sender of message. For example I want to add an portraitID of a player sending the message.  The simplest way I could think of would be to add the portraitID in the "message" (or Title/Subtitle) field itself and the client will then parse this portraitId from the message. 

Is there any more "intelligent" way how to do this?  For example to add some sort of "ScriptData" to system "teamChatHistory" collection ( as the "player" collection has its own "ScriptData" where we can store custom data about player) ?

1 person has this question

Bump. Anyone? 

Another example would be a situation when in team chat you would like to have special messages like "Player X left your Team".  This would be a team message sent by a player before leaving the team but how would one differentiate between this special "leave" message and common team chat messages so it will show in different colour and appearance in Client UI for example.

Hi Jan,

You can set scriptData in the Global TeamChatMessage to whatever value required and then access it via the Message Template in the message configuration on the portal. For example I have my Global TeamChatMessage Cloud code set up as follows.

var testMessage = "Hello"

Spark.setScriptData("myData", {"message":testMessage})


My TeamChatMessage message is configured like below. Note the template and how it is accessing the data.


Now if you send the SendTeamChatMessageRequest you'll see the summary is as follows.

 "summary": "Custom Message is Hello"

Try that and let us know if it works for you.



1 person likes this


how can i get script data from 'SendTeamChatMessageRequest' and then put it into the 'TeamChatMessage'?

Something like this in  Global TeamChatMessage :

var testMessage = Spark.getScriptData("customData");

Spark.setScriptData("myData", {"message":testMessage})

2 people like this

Bumping this topic!

In our case, we need to communicate between the SendTeamChatMessageRequest and the TeamChatMessage CloudCode scripts. We still want to use them as TeamChatMessages, so we can retrieve them by the TeamChatHistory, which is quite easy and reliable to use.

We would want to specify some custom data in the TeamChatMessage, but the Request is the one that is giving its custom data.

Neither the "Spark.getData().scriptData" or "Spark.getScriptData("customData")" are working to handle this problem. They both show null values.

Hope it can be resolved!

2 people like this
Login to post a comment