Chat

Centralized chat service for personal, group and in-game chats.

Introduction

Welcome to the official chat system documentation. This guide delineates the structured procedures to interact with the chat service through GraphQL. Clear examples for each function are provided for precise understanding.

Retrieving Chats

To systematically query all associated chat sessions, use the following:

query GetChats {
  chats {
    __typename
    ... on ChatsOk {
      result {
        id
        users {
          id
        }
        lastMessage {
          message
        }
      }
    }
    ... on Error {
      message
    }
  }
}

GraphQL enables you to query the exact data that you need. For example, if you need a user nickname to be returned additionally to user id, you can add it there.

Accessing Messages Within a Chat

For accessing the messages within a specified chat, use:

query GetMessages($chatId: ID!) {
  messages(chatId: $chatId) {
    __typename
    ... on MessagesOk {
      result {
        message
        author {
          id
        }
      }
    }
    ... on Error {
      message
    }
  }
}

Variables:

{
  "chatId": "YourChatID"
}

Initiating a New Chat Session

To systematically initiate a new chat session:

mutation CreateChat($user1: String!, $user2: String!) {
  createChat(users: [$user1, $user2]) {
    __typename
    ... on CreateChatOk {
      result
    }
    ... on Error {
      message
    }
  }
}

Variables:

{
  "user1": "User1ID",
  "user2": "User2ID"
}

Transmitting a Message

For transmitting a message within a chat:

mutation SendMessage($chatId: ID!, $content: String!) {
  sendMessage(chatId: $chatId, message: $content) {
    __typename
    ... on SendMessageOk {
      result
    }
    ... on Error {
      message
    }
  }
}

Variables:

{
  "chatId": "YourChatID",
  "content": "YourMessageContent"
}

Deletion of a Message

To systematically retract a message:

mutation DeleteMessage($chatId: ID!, $messageId: ID!) {
  deleteMessage(chatId: $chatId, id: $messageId) {
    __typename
    ... on DeleteMessageOk {
      result
    }
    ... on Error {
      message
    }
  }
}

Variables:

{
  "chatId": "YourChatID",
  "messageId": "YourMessageID"
}

Real-time Message Update Subscription

For users necessitating real-time updates:

subscription OnMessageChange($chatId: ID!) {
  messages(chatId: $chatId) {
    mutationType
    id
    chatId
    message {
      message
      author {
        id
      }
    }
  }
}

Variables:

{
  "chatId": "YourChatID"
}

Any anomalies or issues encountered will be reported in the message field of the GraphQL response. For instance, the Error flag represents generic discrepancies.

Your adherence to this structured approach is highly esteemed. For further clarifications, kindly refer to the overarching documentation.

Last updated