Skip to content

setGameScore

Set a user's score in a game. Works on a message carrier (chat_id + message_id) or an inline message carrier (inline_message_id).

Request

POST /:token/setGameScore

Parameters

ParameterTypeRequiredDescription
user_idIntegerYesUnique identifier of the target user
scoreIntegerYesNew score, must be a non-negative integer
forceBooleanNoWhether the score may decrease. Defaults to false, in which case the new score must be strictly greater than the current one; set to true for corrections or anti-cheating
disable_edit_messageBooleanNoWhether to skip auto-editing the game card to refresh the high score table. Defaults to false
chat_idIntegerNoRequired when inline_message_id is not specified: the chat that contains the game card
message_idIntegerNoRequired when inline_message_id is not specified: the message ID of the game card
inline_message_idStringNoRequired when chat_id and message_id are not specified: the inline message identifier

Provide either chat_id + message_id or inline_message_id.

Response

On success:

  • For a regular message carrier, returns the edited Message object;
  • For an inline message carrier, returns the Boolean value true.
json
{
  "ok": true,
  "result": {
    "message_id": 100,
    "chat": { "id": 987654321, "type": "private" },
    "date": 1700000000,
    "game": {
      "title": "Tower Blocks",
      "description": "Stack the blocks and chase the high score!",
      "photo": [{ "file_id": "AgACAgIAAx...", "width": 640, "height": 360 }],
      "text": "🏆 1. Alice — 980\n2. Bob — 760"
    }
  }
}

When force=false and the new score is not greater than the user's current score, the request is rejected.

Error Codes

CodeDescription
400Bad request parameters, e.g. the new score is not greater than the current one (with force=false), missing carrier parameters, or the game does not exist
401Invalid or expired token
403Bot does not have permission to set scores for this game
404User, chat, or message does not exist
500Internal server error

Examples

cURL (message carrier)

bash
curl -X POST "https://api.safew.bot/<token>/setGameScore" \
  -H "Content-Type: application/json" \
  -d '{
    "user_id": 111222333,
    "score": 980,
    "chat_id": 987654321,
    "message_id": 100
  }'

cURL (inline carrier)

bash
curl -X POST "https://api.safew.bot/<token>/setGameScore" \
  -H "Content-Type: application/json" \
  -d '{
    "user_id": 111222333,
    "score": 980,
    "inline_message_id": "AAQAAxkBAAI..."
  }'